|
| 1 | +name: Staging - Deploy PR |
| 2 | + |
| 3 | +# **What it does**: To deploy PRs to a Heroku staging environment. |
| 4 | +# **Why we have it**: To deploy with high visibility in case of failures. |
| 5 | +# **Who does it impact**: All contributors. |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + types: |
| 10 | + - opened |
| 11 | + - reopened |
| 12 | + - synchronize |
| 13 | + - unlocked |
| 14 | + |
| 15 | +jobs: |
| 16 | + deploy: |
| 17 | + if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }} |
| 18 | + name: Deploy |
| 19 | + runs-on: ubuntu-latest |
| 20 | + timeout-minutes: 10 |
| 21 | + concurrency: |
| 22 | + group: staging_${{ github.head_ref }} |
| 23 | + cancel-in-progress: true |
| 24 | + steps: |
| 25 | + - name: Check out repo |
| 26 | + uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f |
| 27 | + with: |
| 28 | + # Enables cloning the Early Access repo later with the relevant PAT |
| 29 | + persist-credentials: 'false' |
| 30 | + |
| 31 | + - name: Setup node |
| 32 | + uses: actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e |
| 33 | + with: |
| 34 | + node-version: 16.x |
| 35 | + |
| 36 | + - name: Get npm cache directory |
| 37 | + id: npm-cache |
| 38 | + run: | |
| 39 | + echo "::set-output name=dir::$(npm config get cache)" |
| 40 | +
|
| 41 | + - name: Cache node modules |
| 42 | + uses: actions/cache@0781355a23dac32fd3bac414512f4b903437991a |
| 43 | + with: |
| 44 | + path: ${{ steps.npm-cache.outputs.dir }} |
| 45 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 46 | + restore-keys: | |
| 47 | + ${{ runner.os }}-node- |
| 48 | +
|
| 49 | + - name: Install dependencies |
| 50 | + run: npm ci |
| 51 | + |
| 52 | + - name: Deploy |
| 53 | + uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }} |
| 57 | + DOCUBOT_REPO_PAT: ${{ secrets.DOCUBOT_REPO_PAT }} |
| 58 | + HYDRO_ENDPOINT: ${{ secrets.HYDRO_ENDPOINT }} |
| 59 | + HYDRO_SECRET: ${{ secrets.HYDRO_SECRET }} |
| 60 | + with: |
| 61 | + script: | |
| 62 | + const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env |
| 63 | +
|
| 64 | + // Exit if GitHub Actions PAT is not found |
| 65 | + if (!GITHUB_TOKEN) { |
| 66 | + throw new Error('You must supply a GITHUB_TOKEN environment variable!') |
| 67 | + } |
| 68 | +
|
| 69 | + // Exit if Heroku API token is not found |
| 70 | + if (!HEROKU_API_TOKEN) { |
| 71 | + throw new Error('You must supply a HEROKU_API_TOKEN environment variable!') |
| 72 | + } |
| 73 | +
|
| 74 | + const getOctokit = require('./script/helpers/github') |
| 75 | + const deployToStaging = require('./script/deployment/deploy-to-staging') |
| 76 | +
|
| 77 | + // This helper uses the `GITHUB_TOKEN` implicitly! |
| 78 | + // We're using our usual version of Octokit vs. the provided `github` |
| 79 | + // instance to avoid versioning discrepancies. |
| 80 | + const octokit = getOctokit() |
| 81 | +
|
| 82 | + try { |
| 83 | + await deployToStaging({ |
| 84 | + herokuToken: HEROKU_API_TOKEN, |
| 85 | + octokit, |
| 86 | + pullRequest: context.payload.pull_request, |
| 87 | + runId: context.runId |
| 88 | + }) |
| 89 | + } catch (error) { |
| 90 | + console.error(`Failed to deploy to staging: ${error.message}`) |
| 91 | + console.error(error) |
| 92 | + throw error |
| 93 | + } |
0 commit comments