1
0
mirror of synced 2026-01-07 09:01:31 -05:00

Add a label to the PR to block deploy attempts during an undeploy (#21885)

This commit is contained in:
James M. Greene
2021-10-05 11:21:15 -05:00
committed by GitHub
parent 5ea869c59f
commit fa810d97b4
2 changed files with 42 additions and 7 deletions

View File

@@ -192,7 +192,8 @@ jobs:
(github.repository == 'github/docs-internal' || github.repository == 'github/docs')
}}
runs-on: ubuntu-latest
timeout-minutes: 1
# This timeout should match or exceed the value of the timeout for Undeploy
timeout-minutes: 5
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
concurrency:
@@ -208,12 +209,33 @@ jobs:
PR_NUMBER: ${{ needs.pr-metadata.outputs.number }}
with:
script: |
const sleep = require('await-sleep') // Does not require ESM
const blockingLabel = 'automated-block-deploy'
const { owner, repo } = context.repo
const { data: pullRequest } = await github.pulls.get({
owner,
repo,
pull_number: process.env.PR_NUMBER
})
const startTime = Date.now()
let pullRequest = {}
let blocked = true
// Keep polling the PR until the blocking label has been removed
while (blocked) {
const { data: pr } = await github.pulls.get({
owner,
repo,
pull_number: process.env.PR_NUMBER
})
blocked = pr.labels.some(({ name }) => name === blockingLabel)
if (blocked) {
console.warn(`WARNING! PR currently has blocking label "${blockingLabel}" (after ${Date.now() - startTime} ms). Will check again soon...`)
await sleep(15000) // Wait 15 seconds and check again
} else {
console.log(`PR was unblocked (after ${Date.now() - startTime} ms)!`)
pullRequest = pr
}
}
core.setOutput('state', pullRequest.state)
prepare-for-deploy:

View File

@@ -44,9 +44,15 @@ jobs:
undeploy:
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
runs-on: ubuntu-latest
timeout-minutes: 2
timeout-minutes: 5
# IMPORTANT: Intentionally OMIT a `concurrency` configuration from this job!
steps:
- name: Add a label to the PR to block deployment during undeployment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh pr edit $PR_NUMBER --add-label "automated-block-deploy"
- name: Check out repo's default branch
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
@@ -107,3 +113,10 @@ jobs:
console.error(error)
throw error
}
- if: ${{ always() }}
name: Remove the label from the PR to unblock deployment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh pr edit $PR_NUMBER --remove-label "automated-block-deploy"