From b809225b3931813b71033928d9c32deb6381861e Mon Sep 17 00:00:00 2001 From: McNaBry Date: Wed, 30 Oct 2024 10:55:00 +0800 Subject: [PATCH] Create github workflow to deploy frontend to S3 * Ensure that action triggers only on push to main and on any changes to frontend directory * Uploads contents in dist folder to s3 bucket --- .github/workflows/frontend.yml | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/frontend.yml diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000000..df1401dca8 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,40 @@ +name: Deploy Frontend + +on: + push: + branches: [ 'main' ] + + workflow_dispatch: + +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout + +env: + AWS_REGION: ap-southeast-1 + S3_BUCKET_NAME: app.peerprep.org + +jobs: + deploy: + name: Deploy Frontend + runs-on: ubuntu-latest + environment: production + + steps: + - uses: actions/checkout@v4 + + - name: Configure AWS credentials + id: aws-configure + uses: aws-actions/configure-aws-credentials@v4.0.2 + with: + role-to-assume: arn:aws:iam::491085383176:role/github_s3_copy + role-session-name: GitHub_to_AWS_via_FederatedOIDC + aws-region: ${{ env.AWS_REGION }} + + - name: Build frontend distribution + working-directory: frontend + run: npm ci && npm run build + + - name: Sync distribution to S3 + run: | + aws s3 sync ./frontend/dist/frontend/browser/ s3://$S3_BUCKET_NAME --delete