Skip to main content

Github Action + AWS S3 deployment

Add secret under your repo setting

AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGION

Now under Actions, click on 'set up your workflow yourself'

Give a name to your workflow and paste below code.

# This is a basic workflow to help you get started with Actions
name: Production Build & Deploy To S3
# Controls when the workflow will runon:  # Triggers the workflow on push or pull request events but only for the master branch  push:    branches: [ master ]  pull_request:    branches: [ master ]
  # Allows you to run this workflow manually from the Actions tab  workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in paralleljobs:  # This workflow contains a single job called "build"  build:    # The type of runner that the job will run on    runs-on: ubuntu-latest
    strategy:      matrix:        node-version: [14.x]
    # Steps represent a sequence of tasks that will be executed as part of the job    steps:      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version  }}        uses: actions/setup-node@v1        with:         node-version: ${{ matrix.node-version }}      - name: Yarn Install        run: |          yarn install      - name: Production Build        run: |          yarn build      - name: Deploy to S3        uses: jakejarvis/s3-sync-action@master        with:          args: --acl public-read --delete        env:          AWS_S3_BUCKET: "your-bucket-name"          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}          AWS_REGION: ${{ secrets.AWS_REGION }}          SOURCE_DIR: "build"