Deploy to AWS S3 & CloudFront #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to AWS S3 & CloudFront | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "frontend/**" | |
| workflow_run: | |
| workflows: [Run CI] | |
| types: | |
| - completed | |
| jobs: | |
| deploy-frontend: | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.head_branch == 'main' && | |
| github.event.workflow_run.event == 'push' | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: frontend | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: "20" | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Create environment file | |
| run: | | |
| echo "VITE_API_URL=${{ secrets.FF_API_URL }}" > ./.env | |
| - name: Build frontend | |
| run: npm run build | |
| - name: Deploy to S3 | |
| uses: jakejarvis/s3-sync-action@v0.5.1 | |
| with: | |
| args: --delete | |
| env: | |
| AWS_S3_BUCKET: ${{ secrets.S3_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: frontend/dist | |
| - name: Invalidate CloudFront cache | |
| run: | | |
| aws cloudfront create-invalidation \ | |
| --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \ | |
| --paths "/*" | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: ${{ secrets.AWS_REGION }} |