chore: Github actions and dependencies improvements #1330
Workflow file for this run
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 staging | |
| on: | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| pull-requests: write | |
| name: Deploy to staging | |
| steps: | |
| # Post a PR comment before deploying | |
| - name: Post a comment while building | |
| if: github.event.number | |
| uses: mshick/add-pr-comment@v2 | |
| with: | |
| message-id: praul | |
| message: | | |
| ## Branch preview | |
| ⏳ Deploying a preview site... | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/checkout@v4 | |
| - uses: pnpm/action-setup@v4 | |
| - uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.npm | |
| ${{ github.workspace }}/.next/cache | |
| # Generate a new cache whenever packages or source files change. | |
| key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }} | |
| # If source files changed but packages didn't, rebuild from a prior cache. | |
| restore-keys: | | |
| ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- | |
| # Extract branch name | |
| - name: Extract branch name | |
| shell: bash | |
| ## Allow only alphanumeric characters and convert to lower case, | |
| run: echo "branch=$(echo $GITHUB_HEAD_REF | sed 's/[^a-z0-9]/_/ig' | sed 's/[A-Z]/\L&/g')" >> $GITHUB_OUTPUT | |
| id: extract_branch | |
| - name: Install dependencies | |
| shell: bash | |
| run: pnpm install --frozen-lockfile | |
| - name: Build app | |
| shell: bash | |
| run: pnpm build | |
| env: | |
| NEXT_PUBLIC_HOST_URL: 'https://docs.staging.5afe.dev' | |
| NODE_OPTIONS: '--max-old-space-size=8000' | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v3 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| # Deploy the main branch to staging | |
| - name: Deploy to the staging S3 | |
| if: github.ref == 'refs/heads/main' | |
| env: | |
| BUCKET: s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/current | |
| run: bash ./.github/scripts/s3_upload.sh | |
| # Deploy to S3 | |
| - name: Deploy PR branch | |
| if: github.event.number | |
| env: | |
| BUCKET: s3://${{ secrets.AWS_REVIEW_BUCKET_NAME }}/docs/${{ steps.extract_branch.outputs.branch }} | |
| run: bash ./.github/scripts/s3_upload.sh | |
| # Comment with the deployment link | |
| - name: Post an epic deployment link in the PR | |
| if: always() && github.event.number | |
| uses: mshick/add-pr-comment@v2 | |
| with: | |
| message-id: praul | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| message: | | |
| ## Branch preview | |
| ✅ Deployed successfully in branch deployment: | |
| https://${{ steps.extract_branch.outputs.branch }}--docs.review.5afe.dev | |
| message-failure: | | |
| ## Branch preview | |
| ❌ Deploy failed! |