Skip to content

Commit

Permalink
Reconfigure workflow concurrency groups to avoid conflicts across PRs (
Browse files Browse the repository at this point in the history
…github#21884)

* Reconfigure workflow concurrency groups to avoid conflicts across PRs

* Remove superfluous and duplicative job display names
  • Loading branch information
JamesMGreene authored Oct 5, 2021
1 parent 9ca7c41 commit 5ea869c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/staging-build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ on:
permissions:
contents: read

# This allows one Build workflow run to interrupt another
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label }}'
cancel-in-progress: true

jobs:
debug:
runs-on: ubuntu-latest
Expand All @@ -27,8 +32,10 @@ jobs:
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
runs-on: ubuntu-latest
timeout-minutes: 5
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
concurrency:
group: staging_${{ github.head_ref }}
group: 'PR Staging @ ${{ github.event.pull_request.head.label }}'
cancel-in-progress: true
steps:
- name: Check out repo
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/staging-deploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ permissions:
pull-requests: read
statuses: write

# IMPORTANT: Intentionally OMIT a `concurrency` configuration from this workflow's
# top-level as we do not have any guarantee of identifying values being available
# within the `github.event` context for PRs from forked repos!
#
# The implication of this shortcoming is that we may have multiple workflow runs
# of this running at the same time for different commits within the same PR.
# However, once they reach the `concurrency` configurations deeper down within
# this workflow's jobs, then we can expect concurrent short-circuiting to begin.

env:
CONTEXT_NAME: '${{ github.workflow }} / deploy (${{ github.event.workflow_run.event }})'
ACTIONS_RUN_LOG: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
Expand Down Expand Up @@ -184,8 +193,10 @@ jobs:
}}
runs-on: ubuntu-latest
timeout-minutes: 1
# This interrupts Build, Deploy, and pre-write Undeploy workflow runs in
# progress for this PR branch.
concurrency:
group: 'staging_${{ needs.pr-metadata.outputs.head_ref }}'
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
outputs:
pull_request_state: ${{ steps.check-pr.outputs.state }}
Expand All @@ -210,8 +221,10 @@ jobs:
if: ${{ needs.check-pr-before-prepare.outputs.pull_request_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.
concurrency:
group: 'staging_${{ needs.pr-metadata.outputs.head_ref }}'
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
outputs:
source_blob_url: ${{ steps.build-source.outputs.download_url }}
Expand Down Expand Up @@ -374,8 +387,10 @@ 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.
concurrency:
group: 'staging_${{ needs.pr-metadata.outputs.head_ref }}'
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
outputs:
pull_request_state: ${{ steps.check-pr.outputs.state }}
Expand All @@ -400,8 +415,10 @@ 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.
concurrency:
group: 'staging_${{ needs.pr-metadata.outputs.head_ref }}'
group: 'PR Staging @ ${{ needs.pr-metadata.outputs.head_label }}'
cancel-in-progress: true
steps:
- name: Check out repo's default branch
Expand Down
24 changes: 20 additions & 4 deletions .github/workflows/staging-undeploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ permissions:
contents: read
deployments: write

# This prevents one Undeploy workflow run from interrupting another
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label }}'
cancel-in-progress: false

jobs:
debug:
runs-on: ubuntu-latest
Expand All @@ -22,14 +27,25 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"

undeploy:
cancel-jobs-before-undeploy:
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
name: Undeploy
runs-on: ubuntu-latest
timeout-minutes: 2
# This interrupts Build and Deploy workflow runs in progress for this PR
# branch. However, it does so with an intentionally short, independent job
# so that the following `undeploy` job cannot be cancelled once started!
concurrency:
group: staging_${{ github.head_ref }}
group: 'PR Staging @ ${{ github.event.pull_request.head.label }}'
cancel-in-progress: true
steps:
- name: Cancelling other deployments via concurrency configuration
run: |
echo 'Cancelling other deployment runs (if any)...'
undeploy:
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
runs-on: ubuntu-latest
timeout-minutes: 2
# IMPORTANT: Intentionally OMIT a `concurrency` configuration from this job!
steps:
- name: Check out repo's default branch
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
Expand Down

0 comments on commit 5ea869c

Please sign in to comment.