|
1 | | -name: Deploy to GitHub Pages |
| 1 | +name: Deploy to AWS S3 |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} |
| 5 | + cancel-in-progress: true |
2 | 6 |
|
3 | 7 | on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + WORKFLOW_PHASE: |
| 11 | + description: "Environment to deploy to" |
| 12 | + required: true |
| 13 | + default: dev |
| 14 | + type: choice |
| 15 | + options: |
| 16 | + - dev |
| 17 | + - prod |
4 | 18 | push: |
5 | | - branches: [main] |
| 19 | + branches: |
| 20 | + - "main" |
6 | 21 |
|
7 | 22 | jobs: |
8 | 23 | build: |
9 | 24 | runs-on: ubuntu-latest |
| 25 | + |
| 26 | + env: |
| 27 | + API_STAGE: ${{ github.event_name == 'workflow_dispatch' && inputs.WORKFLOW_PHASE || 'dev' }} |
| 28 | + BUMP_RULE: ${{ (github.event_name == 'workflow_dispatch' && inputs.WORKFLOW_PHASE || 'dev') == 'dev' && '--mode development' || '' }} |
| 29 | + AWS_S3_BUCKET: ${{ github.event_name == 'workflow_dispatch' && secrets.AWS_S3_BUCKET_PROD || secrets.AWS_S3_BUCKET_DEV }} |
| 30 | + AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ github.event_name == 'workflow_dispatch' && secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID_PROD || secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID_DEV }} |
| 31 | + |
10 | 32 | steps: |
11 | | - - uses: actions/checkout@v4 |
12 | | - - run: npm install -g pnpm && pnpm install |
| 33 | + - uses: actions/checkout@master |
| 34 | + |
| 35 | + - uses: aws-actions/configure-aws-credentials@master |
| 36 | + with: |
| 37 | + role-session-name: GitHubActions |
| 38 | + role-to-assume: ${{ secrets.AWS_FRONTEND_DEPLOYMENT_ROLE_ARN }} |
| 39 | + aws-region: ${{ vars.AWS_REGION }} |
| 40 | + |
| 41 | + - uses: pnpm/action-setup@v4 |
| 42 | + |
| 43 | + - uses: actions/setup-node@v4 |
| 44 | + with: |
| 45 | + node-version: '20' |
| 46 | + cache: 'pnpm' |
| 47 | + cache-dependency-path: 'pnpm-lock.yaml' |
| 48 | + |
| 49 | + - name: Install project dependencies |
| 50 | + run: pnpm install --frozen-lockfile |
| 51 | + |
13 | 52 | - run: mkdir -p dist |
14 | | - - run: pnpm build:@apps/pyconkr && cp -r apps/pyconkr/dist/* dist/ |
| 53 | + |
| 54 | + - run: pnpm build:@apps/pyconkr ${{ env.BUMP_RULE }} && cp -r apps/pyconkr/dist/* dist/ |
| 55 | + |
15 | 56 | - run: pnpm build:@frontend && cp packages/common/dist/common.esm.js{,.map} dist/ && cp packages/shop/dist/shop.esm.js{,.map} dist/ |
16 | | - - uses: actions/configure-pages@v5 |
17 | | - - uses: actions/upload-pages-artifact@v3 |
18 | | - with: |
19 | | - path: "./dist" |
20 | | - |
21 | | - deploy: |
22 | | - needs: build |
23 | | - permissions: |
24 | | - pages: write |
25 | | - id-token: write |
26 | | - environment: |
27 | | - name: github-pages |
28 | | - url: ${{ steps.deployment.outputs.page_url }} |
29 | | - runs-on: ubuntu-latest |
30 | | - steps: |
31 | | - - uses: actions/deploy-pages@v4 |
32 | | - id: deployment |
| 57 | + |
| 58 | + - run: aws s3 cp --recursive ./dist s3://${{ env.AWS_S3_BUCKET }}/ |
| 59 | + |
| 60 | + - run: aws cloudfront create-invalidation --distribution-id ${{ env.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" |
0 commit comments