diff --git a/.github/workflows/staging-deploy-pr.yml b/.github/workflows/staging-deploy-pr.yml index 1b7f65236c..d7080e369f 100644 --- a/.github/workflows/staging-deploy-pr.yml +++ b/.github/workflows/staging-deploy-pr.yml @@ -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: diff --git a/.github/workflows/staging-undeploy-pr.yml b/.github/workflows/staging-undeploy-pr.yml index cdbcf6593d..44411873ff 100644 --- a/.github/workflows/staging-undeploy-pr.yml +++ b/.github/workflows/staging-undeploy-pr.yml @@ -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"