|
1 | 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node |
2 | 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs |
3 | 3 |
|
4 | | -name: Node.js CI |
| 4 | +name: Node.js CI and Deploy |
5 | 5 |
|
6 | 6 | on: |
7 | 7 | push: |
@@ -29,26 +29,35 @@ jobs: |
29 | 29 | - run: yarn build |
30 | 30 | # - run: yarn test |
31 | 31 | - name: Upload distribution artifacts |
32 | | - uses: actions/upload-pages-artifact@v3 |
| 32 | + uses: actions/upload-artifact@v4 |
33 | 33 | with: |
34 | | - name: github-pages |
| 34 | + name: build-artifacts |
35 | 35 | path: dist |
36 | 36 |
|
37 | 37 | deploy: |
38 | 38 | runs-on: ubuntu-latest |
39 | 39 | needs: build |
40 | | - |
41 | | - # Grant GITHUB_TOKEN the permissions required to make a Pages deployment |
42 | | - permissions: |
43 | | - pages: write # to deploy to Pages |
44 | | - id-token: write # to verify the deployment originates from an appropriate source |
45 | | - |
46 | | - # Deploy to the github-pages environment |
47 | | - environment: |
48 | | - name: github-pages |
49 | | - url: ${{ steps.deployment.outputs.page_url }} |
| 40 | + if: github.ref == 'refs/heads/main' # Only deploy on main branch |
50 | 41 |
|
51 | 42 | steps: |
52 | | - - name: Deploy to GitHub Pages |
53 | | - id: deployment |
54 | | - uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + - name: Download build artifacts |
| 45 | + uses: actions/download-artifact@v4 |
| 46 | + with: |
| 47 | + name: build-artifacts |
| 48 | + path: dist |
| 49 | + |
| 50 | + - name: Configure AWS credentials |
| 51 | + uses: aws-actions/configure-aws-credentials@v4 |
| 52 | + with: |
| 53 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 54 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 55 | + aws-region: ${{ secrets.AWS_REGION }} |
| 56 | + |
| 57 | + - name: Deploy to S3 |
| 58 | + run: | |
| 59 | + aws s3 sync dist/ s3://${{ secrets.S3_BUCKET }} |
| 60 | + |
| 61 | + # - name: Invalidate CloudFront cache |
| 62 | + # run: | |
| 63 | + # aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" |
0 commit comments