Skip to content

Commit

Permalink
Remove the concept of "undeployment" as a part of the PR deployment l…
Browse files Browse the repository at this point in the history
…ifecycle (github#23731)

* Update remove-stale-staging-resources workflow to completely replace undeploy workflow
* Delete the staging-undeploy-pr workflow file
* Delete all undeployment scripts and logic
* Remove all references to the automated-block-deploy label used for undeployment
* Simplify staging cross-workflow concurrency needs
  • Loading branch information
JamesMGreene authored Jan 6, 2022
1 parent 00fc555 commit be4249b
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 425 deletions.
50 changes: 0 additions & 50 deletions .github/actions-scripts/staging-undeploy.js

This file was deleted.

12 changes: 8 additions & 4 deletions .github/workflows/remove-stale-staging-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ name: Remove stale staging resources
# This cleans up any rogue staging applications and environments that outlasted
# the closure of their corresponding pull requests.
# **Why we have it**:
# Staging applications and environments sometimes fail to be destroyed when
# their corresponding pull request is closed or merged.
# Staging applications and environments should be destroyed after their
# corresponding pull request is closed or merged, especially to save money spent
# on Heroku App staging deployments for closed PRs.
# **Who does it impact**:
# Anyone with a closed, spammy, or deleted pull request in docs or docs-internal.

Expand All @@ -15,7 +16,8 @@ on:

permissions:
contents: read
pull-requests: read
deployments: write
pull-requests: write

jobs:
remove_stale_staging_apps:
Expand Down Expand Up @@ -60,5 +62,7 @@ jobs:
- name: Run script
run: script/remove-stale-staging-envs.js
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_FR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ELEVATED_TOKEN: ${{ secrets.DOCS_BOT_FR }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
18 changes: 1 addition & 17 deletions .github/workflows/staging-build-and-deploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ permissions:
statuses: write

# This allows a subsequently queued workflow run to interrupt previous runs
# These are different from the concurrency in that here it checks if the
# whole workflow runs again. The "inner concurrency" is used for
# undeployments to cleaning up resources.
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
Expand All @@ -44,11 +41,7 @@ jobs:
runs-on: self-hosted

timeout-minutes: 5
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
concurrency:
group: 'PR Staging @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

steps:
- name: Check out repo
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
Expand Down Expand Up @@ -85,15 +78,6 @@ jobs:
DOCUBOT_REPO_PAT: ${{ secrets.DOCUBOT_REPO_PAT }}
GIT_BRANCH: ${{ github.event.pull_request.head.sha }}

- name: Check that the PR isn't blocking deploys
# We can't use ${{...}} on this if statement because of this bug
# https://github.com/cschleiden/actions-linter/issues/114
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'automated-block-deploy')
run: |
echo "The PR appears to have the label 'automated-block-deploy'"
echo "Will not proceed to deploy the PR."
exit 2
- name: Create a Heroku build source
id: build-source
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/staging-build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:

runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
timeout-minutes: 5
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
# This interrupts Build and Deploy workflow runs in progress for this PR branch.
concurrency:
group: 'PR Staging @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
Expand Down
68 changes: 5 additions & 63 deletions .github/workflows/staging-deploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,68 +198,12 @@ jobs:
color: failure
text: Staging build failed for PR ${{ needs.pr-metadata.outputs.url }} at commit ${{ needs.pr-metadata.outputs.head_sha }}. See ${{ env.BUILD_ACTIONS_RUN_LOG }}. This run was ${{ env.ACTIONS_RUN_LOG }}.

check-pr-before-prepare:
needs: pr-metadata
if: >-
${{
needs.pr-metadata.outputs.number != '0' &&
github.event.workflow_run.conclusion == 'success'
}}
runs-on: ubuntu-latest
# 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:
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
outputs:
pull_request_state: ${{ steps.check-pr.outputs.state }}
steps:
- name: Check pull request state
id: check-pr
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
PR_NUMBER: ${{ needs.pr-metadata.outputs.number }}
with:
script: |
// Equivalent of the 'await-sleep' module without the install
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
const blockingLabel = 'automated-block-deploy'
const { owner, repo } = context.repo
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:
needs: [pr-metadata, check-pr-before-prepare]
if: ${{ needs.check-pr-before-prepare.outputs.pull_request_state == 'open' }}
needs: pr-metadata
if: ${{ needs.pr-metadata.outputs.state == 'open' }}
runs-on: ubuntu-latest
timeout-minutes: 5
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
# This interrupts Build and Deploy workflow runs in progress for this PR branch.
concurrency:
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
Expand Down Expand Up @@ -395,8 +339,7 @@ jobs:
needs: [pr-metadata, prepare-for-deploy]
runs-on: ubuntu-latest
timeout-minutes: 1
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
# This interrupts Build and Deploy workflow runs in progress for this PR branch.
concurrency:
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
Expand All @@ -423,8 +366,7 @@ jobs:
if: ${{ needs.check-pr-before-deploy.outputs.pull_request_state == 'open' }}
runs-on: ubuntu-latest
timeout-minutes: 10
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
# This interrupts Build and Deploy workflow runs in progress for this PR branch.
concurrency:
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
Expand Down
94 changes: 0 additions & 94 deletions .github/workflows/staging-undeploy-pr.yml

This file was deleted.

Loading

0 comments on commit be4249b

Please sign in to comment.