Skip to content

Commit fe767f3

Browse files
Actions staging deployment with Status updates instead of Check Runs (github#21283)
* Update Staging deployment workflow to create Status updates * Update local Staging deployment script to create Status updates Co-authored-by: Rachael Sewell <rachmari@github.com>
1 parent 64d43ee commit fe767f3

2 files changed

Lines changed: 97 additions & 46 deletions

File tree

.github/workflows/staging-deploy-pr.yml

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ env:
1919
# with the `github.event.workflow_run.head_branch` that triggered the preceding
2020
# `pull_request` event that triggered the "Staging - Build PR" workflow.
2121
PR_URL: ${{ github.event.workflow_run.repository.html_url }}/pull/${{ github.event.workflow_run.pull_requests[0].number }}
22+
CONTEXT_NAME: '${{ github.workflow }} / deploy (${{ github.event.workflow_run.event }})'
23+
ACTIONS_RUN_LOG: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
2224

2325
jobs:
2426
prepare:
@@ -34,28 +36,25 @@ jobs:
3436
cancel-in-progress: true
3537
outputs:
3638
source_blob_url: ${{ steps.build-source.outputs.download_url }}
37-
check_run_id: ${{ steps.create-check-run.outputs.check_run_id }}
38-
check_run_name: ${{ steps.create-check-run.outputs.check_run_name }}
3939
steps:
40-
- name: Create check run
41-
id: create-check-run
40+
- name: Create initial status
4241
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
42+
env:
43+
CONTEXT_NAME: ${{ env.CONTEXT_NAME }}
44+
ACTIONS_RUN_LOG: ${{ env.ACTIONS_RUN_LOG }}
4345
with:
4446
script: |
47+
const { CONTEXT_NAME, ACTIONS_RUN_LOG } = process.env
4548
const { owner, repo } = context.repo
46-
47-
// Create a check run
48-
const CHECK_NAME = '${{ github.workflow }} check run'
49-
const { data } = await github.checks.create({
50-
name: CHECK_NAME,
51-
head_sha: '${{ github.event.workflow_run.head_sha }}',
49+
await github.repos.createStatus({
5250
owner,
5351
repo,
54-
status: 'in_progress',
55-
started_at: (new Date()).toISOString()
52+
sha: '${{ github.event.workflow_run.head_sha }}',
53+
context: CONTEXT_NAME,
54+
state: 'pending',
55+
description: 'The app is being deployed. See logs.',
56+
target_url: ACTIONS_RUN_LOG
5657
})
57-
core.setOutput('check_run_id', data.id)
58-
core.setOutput('check_run_name', CHECK_NAME)
5958
6059
- name: Download build artifact
6160
uses: dawidd6/action-download-artifact@b9571484721e8187f1fd08147b497129f8972c74
@@ -146,14 +145,34 @@ jobs:
146145
-H 'Content-Type:' \
147146
--data-binary @app.tar.gz
148147
148+
- name: Create failure status
149+
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
150+
if: ${{ failure() }}
151+
env:
152+
CONTEXT_NAME: ${{ env.CONTEXT_NAME }}
153+
ACTIONS_RUN_LOG: ${{ env.ACTIONS_RUN_LOG }}
154+
with:
155+
script: |
156+
const { CONTEXT_NAME, ACTIONS_RUN_LOG } = process.env
157+
const { owner, repo } = context.repo
158+
await github.repos.createStatus({
159+
owner,
160+
repo,
161+
sha: '${{ github.event.workflow_run.head_sha }}',
162+
context: CONTEXT_NAME,
163+
state: 'error',
164+
description: 'Failed to deploy. See logs.',
165+
target_url: ACTIONS_RUN_LOG
166+
})
167+
149168
- name: Send Slack notification if workflow fails
150169
uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
151170
if: ${{ failure() }}
152171
with:
153172
channel: ${{ secrets.DOCS_STAGING_DEPLOYMENT_FAILURES_SLACK_CHANNEL_ID }}
154173
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
155174
color: failure
156-
text: Staging preparation failed for PR ${{ env.PR_URL }} at commit ${{ github.sha }}. See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
175+
text: Staging preparation failed for PR ${{ env.PR_URL }} at commit ${{ github.event.workflow_run.head_sha }}. See ${{ env.ACTIONS_RUN_LOG }}
157176

158177
deploy:
159178
needs: prepare
@@ -188,8 +207,8 @@ jobs:
188207
HYDRO_SECRET: ${{ secrets.HYDRO_SECRET }}
189208
PR_URL: ${{ env.PR_URL }}
190209
SOURCE_BLOB_URL: ${{ needs.prepare.outputs.source_blob_url }}
191-
CHECK_RUN_ID: ${{ needs.prepare.outputs.check_run_id }}
192-
CHECK_RUN_NAME: '${{ needs.prepare.outputs.check_run_name }}'
210+
CONTEXT_NAME: ${{ env.CONTEXT_NAME }}
211+
ACTIONS_RUN_LOG: ${{ env.ACTIONS_RUN_LOG }}
193212
with:
194213
script: |
195214
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env
@@ -220,7 +239,7 @@ jobs:
220239
const actionsRunLog = 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
221240
222241
try {
223-
const { PR_URL, SOURCE_BLOB_URL, CHECK_RUN_ID, CHECK_RUN_NAME } = process.env
242+
const { PR_URL, SOURCE_BLOB_URL, CONTEXT_NAME, ACTIONS_RUN_LOG } = process.env
224243
const { owner, repo, pullNumber } = parsePrUrl(PR_URL)
225244
if (!owner || !repo || !pullNumber) {
226245
throw new Error(`'pullRequestUrl' input must match URL format 'https://github.com/github/(docs|docs-internal)/pull/123' but was '${PR_URL}'`)
@@ -241,37 +260,16 @@ jobs:
241260
runId: context.runId
242261
})
243262
244-
await octokit.checks.update({
263+
await github.repos.createStatus({
245264
owner,
246265
repo,
247-
conclusion: 'success',
248-
status: 'completed',
249-
name: CHECK_RUN_NAME,
250-
check_run_id: CHECK_RUN_ID,
251-
details_url: actionsRunLog,
252-
output: {
253-
title: 'Successfully deployed to staging',
254-
summary: 'Success',
255-
text: `Succeeded! 🚀\n\nSee full logs: ${actionsRunLog}`
256-
},
257-
completed_at: (new Date()).toISOString()
266+
sha: '${{ github.event.workflow_run.head_sha }}',
267+
context: CONTEXT_NAME,
268+
state: 'success',
269+
description: 'Successfully deployed! See logs.',
270+
target_url: ACTIONS_RUN_LOG
258271
})
259272
} catch (error) {
260-
await octokit.checks.update({
261-
owner,
262-
repo,
263-
conclusion: 'failure',
264-
status: 'completed',
265-
name: CHECK_RUN_NAME,
266-
check_run_id: CHECK_RUN_ID,
267-
details_url: actionsRunLog,
268-
output: {
269-
title: `Failed to deploy to staging: ${error.message}`,
270-
summary: error.message,
271-
text: `Failed! 🚫\n\nSee full logs: ${actionsRunLog}`
272-
},
273-
completed_at: (new Date()).toISOString()
274-
})
275273
console.error(`Failed to deploy to staging: ${error.message}`)
276274
console.error(error)
277275
throw error
@@ -286,11 +284,31 @@ jobs:
286284
// TODO: Create a new deployment status for it as "inactive"
287285
return 'TODO'
288286
287+
- name: Create failure status
288+
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
289+
if: ${{ failure() }}
290+
env:
291+
CONTEXT_NAME: ${{ env.CONTEXT_NAME }}
292+
ACTIONS_RUN_LOG: ${{ env.ACTIONS_RUN_LOG }}
293+
with:
294+
script: |
295+
const { CONTEXT_NAME, ACTIONS_RUN_LOG } = process.env
296+
const { owner, repo } = context.repo
297+
await github.repos.createStatus({
298+
owner,
299+
repo,
300+
sha: '${{ github.event.workflow_run.head_sha }}',
301+
context: CONTEXT_NAME,
302+
state: 'error',
303+
description: 'Failed to deploy. See logs.',
304+
target_url: ACTIONS_RUN_LOG
305+
})
306+
289307
- name: Send Slack notification if workflow fails
290308
uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
291309
if: ${{ failure() }}
292310
with:
293311
channel: ${{ secrets.DOCS_STAGING_DEPLOYMENT_FAILURES_SLACK_CHANNEL_ID }}
294312
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
295313
color: failure
296-
text: Staging deployment failed for PR ${{ env.PR_URL }} at commit ${{ github.sha }}. See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
314+
text: Staging deployment failed for PR ${{ env.PR_URL }} at commit ${{ github.event.workflow_run.head_sha }}. See ${{ env.ACTIONS_RUN_LOG }}

script/deploy.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ async function deployProduction() {
147147
}
148148

149149
async function deployStaging({ owner, repo, pullNumber, forceRebuild = false, destroy = false }) {
150+
// Hardcode the Status context name to match Actions
151+
const CONTEXT_NAME = 'Staging - Deploy PR / deploy (pull_request)'
152+
150153
// This helper uses the `GITHUB_TOKEN` implicitly
151154
const octokit = getOctokit()
152155

@@ -163,16 +166,46 @@ async function deployStaging({ owner, repo, pullNumber, forceRebuild = false, de
163166
pullRequest,
164167
})
165168
} else {
169+
await octokit.repos.createStatus({
170+
owner,
171+
repo,
172+
sha: pullRequest.head.sha,
173+
context: CONTEXT_NAME,
174+
state: 'pending',
175+
description: 'The app is being deployed. See local logs.',
176+
})
177+
166178
await deployToStaging({
167179
octokit,
168180
pullRequest,
169181
forceRebuild,
170182
})
183+
184+
await octokit.repos.createStatus({
185+
owner,
186+
repo,
187+
sha: pullRequest.head.sha,
188+
context: CONTEXT_NAME,
189+
state: 'success',
190+
description: 'Successfully deployed! See local logs.',
191+
})
171192
}
172193
} catch (error) {
173194
const action = destroy ? 'undeploy from' : 'deploy to'
174195
console.error(`Failed to ${action} staging: ${error.message}`)
175196
console.error(error)
197+
198+
if (!destroy) {
199+
await octokit.repos.createStatus({
200+
owner,
201+
repo,
202+
sha: pullRequest.head.sha,
203+
context: CONTEXT_NAME,
204+
state: 'error',
205+
description: 'Failed to deploy. See local logs.',
206+
})
207+
}
208+
176209
process.exit(1)
177210
}
178211
}

0 commit comments

Comments
 (0)