diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-12-15 18:49:29 +0100 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-12-15 18:49:29 +0100 |
commit | dbb599f2e4337aa80cf71462f04bd32216d8bb90 (patch) | |
tree | 25e124a0d30e7955eeea32474527316709ded85f /.github | |
parent | d17c5a31dc5bba829599ac044b5903f5e21f36fd (diff) |
workflows/check-by-name: Cancel on merge conflicts
Diffstat (limited to '.github')
-rw-r--r-- | .github/workflows/check-by-name.yml | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/.github/workflows/check-by-name.yml b/.github/workflows/check-by-name.yml index 294775fa1c8e2..5e3e65641f82b 100644 --- a/.github/workflows/check-by-name.yml +++ b/.github/workflows/check-by-name.yml @@ -8,8 +8,9 @@ on: # Using pull_request_target instead of pull_request avoids having to approve first time contributors pull_request_target -# The tool doesn't need any permissions, it only outputs success or not based on the checkout -permissions: {} +permissions: + # We need this permission to cancel the workflow run if there's a merge conflict + actions: write jobs: check: @@ -62,7 +63,14 @@ jobs: if [[ "$mergeable" == "true" ]]; then echo "The PR can be merged, checking the merge commit $mergedSha" else - echo "The PR cannot be merged, it has a merge conflict" + echo "The PR cannot be merged, it has a merge conflict, cancelling the workflow.." + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/"$GITHUB_REPOSITORY"/actions/runs/"$GITHUB_RUN_ID"/cancel + sleep 60 + # If it's still not canceled after a minute, something probably went wrong, just exit exit 1 fi echo "mergedSha=$mergedSha" >> "$GITHUB_ENV" |