|
| 1 | +name: Staging - Build PR Docker |
| 2 | + |
| 3 | +# **What it does**: Builds PRs before deploying them. |
| 4 | +# **Why we have it**: Because it's not safe to share our deploy secrets with forked repos: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 5 | +# **Who does it impact**: All contributors. |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + types: |
| 10 | + - opened |
| 11 | + - reopened |
| 12 | + - synchronize |
| 13 | + - unlocked |
| 14 | + branches: |
| 15 | + - 'docker-*' |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }} |
| 20 | + name: Build |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 5 |
| 23 | + concurrency: |
| 24 | + group: staging_${{ github.head_ref }} |
| 25 | + cancel-in-progress: true |
| 26 | + steps: |
| 27 | + - name: Check out repo |
| 28 | + uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f |
| 29 | + |
| 30 | + # Make sure only approved files are changed if it's in github/docs |
| 31 | + - name: Check changed files |
| 32 | + if: github.repository == 'github/docs' && github.event.pull_request.user.login != 'Octomerger' |
| 33 | + uses: dorny/paths-filter@eb75a1edc117d3756a18ef89958ee59f9500ba58 |
| 34 | + id: filter |
| 35 | + with: |
| 36 | + # Base branch used to get changed files |
| 37 | + base: 'main' |
| 38 | + |
| 39 | + # Enables setting an output in the format in `${FILTER_NAME}_files |
| 40 | + # with the names of the matching files formatted as JSON array |
| 41 | + list-files: json |
| 42 | + |
| 43 | + # Returns list of changed files matching each filter |
| 44 | + filters: | |
| 45 | + notAllowed: |
| 46 | + - '*.mjs' |
| 47 | + - '*.ts' |
| 48 | + - '*.tsx' |
| 49 | + - '*.json' |
| 50 | + - 'Dockerfile*' |
| 51 | +
|
| 52 | + # When there are changes to files we can't accept |
| 53 | + - name: 'Fail when not allowed files are changed' |
| 54 | + if: ${{ steps.filter.outputs.notAllowed }} |
| 55 | + run: exit 1 |
| 56 | + |
| 57 | + - name: Create an archive |
| 58 | + run: | |
| 59 | + tar -cf app.tar \ |
| 60 | + assets/ \ |
| 61 | + content/ \ |
| 62 | + stylesheets/ \ |
| 63 | + pages/ \ |
| 64 | + data/ \ |
| 65 | + includes/ \ |
| 66 | + lib/ \ |
| 67 | + middleware/ \ |
| 68 | + translations/ \ |
| 69 | + server.mjs \ |
| 70 | + package*.json \ |
| 71 | + .npmrc \ |
| 72 | + feature-flags.json \ |
| 73 | + next.config.js \ |
| 74 | + tsconfig.json \ |
| 75 | + next-env.d.ts \ |
| 76 | + Dockerfile |
| 77 | +
|
| 78 | + # Upload only the files needed to run + build this application. |
| 79 | + # We are not willing to trust the rest (e.g. script/) for the remainder |
| 80 | + # of the deployment process. |
| 81 | + - name: Upload build artifact |
| 82 | + uses: actions/upload-artifact@27121b0bdffd731efa15d66772be8dc71245d074 |
| 83 | + with: |
| 84 | + name: pr_build_docker |
| 85 | + path: app.tar |
| 86 | + |
| 87 | + - name: Send Slack notification if workflow fails |
| 88 | + uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd |
| 89 | + if: ${{ failure() }} |
| 90 | + with: |
| 91 | + channel: ${{ secrets.DOCS_STAGING_DEPLOYMENT_FAILURES_SLACK_CHANNEL_ID }} |
| 92 | + bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} |
| 93 | + color: failure |
| 94 | + text: Staging build (docker) failed for PR ${{ github.event.pull_request.html_url }} at commit ${{ github.sha }}. See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
0 commit comments