Skip to content

Commit

Permalink
Implements canceling of future duplicate runs (but the latest) (apach…
Browse files Browse the repository at this point in the history
…e#11980)

* Implements canceling of future duplicate runs (but the latest)

Previous version of the cancel-workflow-runs action implemented
canceling of only past duplicates, but when there are queues
involved, some future "cancel-workflow-runs" might be in a queue
for  long time. This change has the effect that cancel-workflow-runs
for duplicates will also allow future runs of the same branch/repo
sparing only the most recent run - no matter if the duplicates
were older than my own run.

This should handle the case where we have queues blocking the
"cancel-workflow-runs" from running.

* Update .github/workflows/build-images-workflow-run.yml

Co-authored-by: Kaxil Naik <[email protected]>

Co-authored-by: Kaxil Naik <[email protected]>
  • Loading branch information
potiuk and kaxil authored Oct 30, 2020
1 parent 06597da commit 36b5cc6
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/build-images-workflow-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ on: # yamllint disable-line rule:truthy
workflow_run:
workflows: ["CI Build"]
types: ['requested']

env:
MOUNT_LOCAL_SOURCES: "false"
MOUNT_FILES: "true"
Expand Down Expand Up @@ -67,7 +66,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Cancel duplicated 'CI Build' runs"
uses: potiuk/cancel-workflow-runs@0acb1c01f6740dfbca6eab6e21a5b5066e8bafb3 # v3_3
uses: potiuk/cancel-workflow-runs@c8448eb1e435664b3731ea1ead2efa0d1bb83b5b # v4_0
with:
token: ${{ secrets.GITHUB_TOKEN }}
cancelMode: duplicates
Expand All @@ -85,7 +84,7 @@ jobs:
# in GitHub Actions, we have to use Job names to match Event/Repo/Branch from the
# build-info step there to find the duplicates ¯\_(ツ)_/¯.

uses: potiuk/cancel-workflow-runs@0acb1c01f6740dfbca6eab6e21a5b5066e8bafb3 # v3_3
uses: potiuk/cancel-workflow-runs@c8448eb1e435664b3731ea1ead2efa0d1bb83b5b # v4_0
with:
cancelMode: namedJobs
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -94,9 +93,7 @@ jobs:
[".*Event: ${{ steps.source-run-info.outputs.sourceEvent }}
Repo: ${{ steps.source-run-info.outputs.sourceHeadRepo }}
Branch: ${{ steps.source-run-info.outputs.sourceHeadBranch }}.*"]
if: >
env.BUILD_IMAGES == 'true' && steps.source-run-info.outputs.sourceEvent != 'schedule'
&& steps.source-run-info.outputs.sourceEvent != 'push'
if: env.BUILD_IMAGES == 'true'
- name: "Cancel all 'CI Build' runs where some jobs failed"

# We find any of the "CI Build" workflow runs, where any of the important jobs
Expand All @@ -105,7 +102,7 @@ jobs:
# can cancel all the matching "Build Images" workflow runs in the two following steps.
# Yeah. Adding to the complexity ¯\_(ツ)_/¯.

uses: potiuk/cancel-workflow-runs@0acb1c01f6740dfbca6eab6e21a5b5066e8bafb3 # v3_3
uses: potiuk/cancel-workflow-runs@c8448eb1e435664b3731ea1ead2efa0d1bb83b5b # v4_0
id: cancel-failed
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -139,14 +136,14 @@ jobs:
# it to cancel any jobs that have matching names containing Source Run Id:
# followed by one of the run ids. Yes I know it's super complex ¯\_(ツ)_/¯.
if: env.BUILD_IMAGES == 'true' && steps.source-run-info-failed.outputs.cancelledRuns != '[]'
uses: potiuk/cancel-workflow-runs@0acb1c01f6740dfbca6eab6e21a5b5066e8bafb3 # v3_3
uses: potiuk/cancel-workflow-runs@c8448eb1e435664b3731ea1ead2efa0d1bb83b5b # v4_0
with:
cancelMode: namedJobs
token: ${{ secrets.GITHUB_TOKEN }}
notifyPRCancel: true
jobNameRegexps: ${{ steps.extract-cancelled-failed-runs.outputs.matching-regexp }}
- name: "Cancel duplicated 'CodeQL' runs"
uses: potiuk/cancel-workflow-runs@0acb1c01f6740dfbca6eab6e21a5b5066e8bafb3 # v3_3
uses: potiuk/cancel-workflow-runs@c8448eb1e435664b3731ea1ead2efa0d1bb83b5b # v4_0
id: cancel
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -367,7 +364,7 @@ jobs:
needs: [build-images]
steps:
- name: "Canceling the 'CI Build' source workflow in case of failure!"
uses: potiuk/cancel-workflow-runs@cancel_message # v3
uses: potiuk/cancel-workflow-runs@c8448eb1e435664b3731ea1ead2efa0d1bb83b5b # v4_0
with:
token: ${{ secrets.GITHUB_TOKEN }}
cancelMode: self
Expand All @@ -382,7 +379,7 @@ jobs:
needs: [build-images]
steps:
- name: "Canceling the 'CI Build' source workflow in case of failure!"
uses: potiuk/cancel-workflow-runs@0acb1c01f6740dfbca6eab6e21a5b5066e8bafb3 # v3_3
uses: potiuk/cancel-workflow-runs@c8448eb1e435664b3731ea1ead2efa0d1bb83b5b # v4_0
with:
token: ${{ secrets.GITHUB_TOKEN }}
cancelMode: self
Expand Down

0 comments on commit 36b5cc6

Please sign in to comment.