Skip to content

Commit

Permalink
Use python script to cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Jan 28, 2021
1 parent 67fbd82 commit d6d02c8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/actions/cancel-workflow-runs
Submodule cancel-workflow-runs deleted from 953e05
15 changes: 6 additions & 9 deletions .github/workflows/cancel_duplicates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ jobs:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
if: steps.check_queued.outputs.count >= 20
uses: actions/checkout@v2
with:
persist-credentials: false
submodules: recursive

- name: Cancel duplicate workflow runs
if: steps.check_queued.outputs.count >= 20
uses: ./.github/actions/cancel-workflow-runs
with:
cancelMode: allDuplicates
sourceRunId: ${{ github.event.workflow_run.id }}
token: ${{ secrets.GITHUB_TOKEN }}
notifyPRCancel: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
pip install click requests typing_extensions python-dateutil
python ./scripts/cancel_github_workflows.py
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,3 @@
[submodule ".github/actions/comment-on-pr"]
path = .github/actions/comment-on-pr
url = https://github.com/unsplash/comment-on-pr
[submodule ".github/actions/cancel-workflow-runs"]
path = .github/actions/cancel-workflow-runs
url = https://github.com/potiuk/cancel-workflow-runs
6 changes: 4 additions & 2 deletions scripts/cancel_github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def cancel_github_workflows(
pr = get_pull_request(repo, pull_number=branch_or_pull)
title = f"pull request #{pr['number']} - {pr['title']}"
else:
target_type = "branch"
title = f"branch [{branch_or_pull}]"

print(
Expand Down Expand Up @@ -191,7 +190,10 @@ def cancel_github_workflows(
# sort old jobs to the front, so to cancel older jobs first
runs = sorted(runs, key=lambda x: x["created_at"])
if runs:
print(f"Found {len(runs)} potential runs of\n status: {statuses}\n event: {events}\n")
print(
f"Found {len(runs)} potential runs of\n"
f" status: {statuses}\n event: {events}\n"
)
else:
print(f"No {' or '.join(statuses)} workflow runs found.\n")
return
Expand Down

0 comments on commit d6d02c8

Please sign in to comment.