diff --git a/.github/workflows/staging-deploy-pr.yml b/.github/workflows/staging-deploy-pr.yml index f62d908029..ad0d7d2eb2 100644 --- a/.github/workflows/staging-deploy-pr.yml +++ b/.github/workflows/staging-deploy-pr.yml @@ -34,12 +34,32 @@ jobs: cancel-in-progress: true outputs: source_blob_url: ${{ steps.build-source.outputs.download_url }} + check_run_id: ${{ steps.create-check-run.outputs.check_run_id }} + check_run_name: ${{ steps.create-check-run.outputs.check_run_name }} steps: - name: Dump event context env: GITHUB_EVENT_CONTEXT: ${{ toJSON(github.event) }} run: echo "$GITHUB_EVENT_CONTEXT" + - name: Create check run + id: create-check-run + uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d + with: + script: | + // Create a check run + const CHECK_NAME = '${{ github.workflow }} / ${{ github.job }} (${{ github.event_name }})' + const { data } = await github.checks.create({ + name: CHECK_NAME, + head_sha: '${{github.sha}}', + owner: 'github', + repo: 'docs-internal', + status: 'in_progress', + started_at: new Date() + }) + core.setOutput('check_run_id', data.id) + core.setOutput('check_run_name', CHECK_NAME) + - name: Download build artifact uses: dawidd6/action-download-artifact@b9571484721e8187f1fd08147b497129f8972c74 with: @@ -177,6 +197,8 @@ jobs: HYDRO_SECRET: ${{ secrets.HYDRO_SECRET }} PR_URL: ${{ env.PR_URL }} SOURCE_BLOB_URL: ${{ needs.prepare.outputs.source_blob_url }} + CHECK_RUN_ID: ${{ needs.prepare.outputs.check_run_id }} + CHECK_RUN_NAME: ${{ needs.prepare.outputs.check_run_name }} with: script: | const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env @@ -205,7 +227,7 @@ jobs: const octokit = getOctokit() try { - const { PR_URL, SOURCE_BLOB_URL } = process.env + const { PR_URL, SOURCE_BLOB_URL, CHECK_RUN_ID, CHECK_RUN_NAME } = process.env const { owner, repo, pullNumber } = parsePrUrl(PR_URL) if (!owner || !repo || !pullNumber) { throw new Error(`'pullRequestUrl' input must match URL format 'https://github.com/github/(docs|docs-internal)/pull/123' but was '${PR_URL}'`) @@ -225,7 +247,36 @@ jobs: sourceBlobUrl: SOURCE_BLOB_URL, runId: context.runId }) + + await octokit.checks.update({ + owner: 'github', + repo: 'docs-internal', + conclusion: 'success', + status: 'completed', + name: CHECK_RUN_NAME, + check_run_id: CHECK_RUN_ID, + output: { + title: 'Successfully deployed to staging', + summary: 'Success', + text: 'Succeeded! 🚀\n\nSee full logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' + }, + completed_at: new Date() + }) } catch (error) { + await octokit.checks.update({ + owner: 'github', + repo: 'docs-internal', + conclusion: 'failure', + status: 'completed', + name: CHECK_RUN_NAME, + check_run_id: CHECK_RUN_ID, + output: { + title: `Failed to deploy to staging: ${error.message}`, + summary: error.message, + text: 'Failed! 🚫\n\nSee full logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' + } + completed_at: new Date() + }) console.error(`Failed to deploy to staging: ${error.message}`) console.error(error) throw error