Skip to content

Instantly share code, notes, and snippets.

@kibolho
Created March 16, 2023 16:51
Show Gist options
  • Select an option

  • Save kibolho/684339de88088457d0f58065279e34ff to your computer and use it in GitHub Desktop.

Select an option

Save kibolho/684339de88088457d0f58065279e34ff to your computer and use it in GitHub Desktop.
Action to deploy to S3
name: Deploy to S3 (Prod)
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Create .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//npm.pkg.github.com/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.GH_REGISTRY_PACKAGES }}
- name: Run install
uses: borales/actions-yarn@v4
with:
cmd: install # will run `yarn install` command
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_REGISTRY_PACKAGES }}
- name: Production Build
run: |
CI='false' npm run build-production
- name: Unit Tests
run: |
npm test
- name: Deploy to S3
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_PRODUCTION_BUCKET_NAME }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: 'build'
- name: Invalidate Cache (admin.poolit.com)
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CF_DISTRIBUTION_ID }} --paths "/*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment