-
Notifications
You must be signed in to change notification settings - Fork 10
ci: cancel upstream run on downstream cancellation #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jonas Elfering (keulinho)
merged 2 commits into
main
from
codex/cancel-upstream-on-downstream-cancel
Jun 16, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) | ||
| TMP_DIR=$(mktemp -d) | ||
|
|
||
| trap 'rm -rf "${TMP_DIR}"' EXIT | ||
|
|
||
| cat > "${TMP_DIR}/gh" <<'EOF' | ||
| #!/usr/bin/env bash | ||
| if [[ "${1} ${2}" == "run view" ]]; then | ||
| printf '{"status":"completed","conclusion":"%s"}\n' "${GH_CONCLUSION}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ "${1} ${2}" == "run cancel" ]]; then | ||
| echo "cancel called" | ||
| exit "${GH_CANCEL_EXIT:-0}" | ||
| fi | ||
|
|
||
| exit 1 | ||
| EOF | ||
| chmod +x "${TMP_DIR}/gh" | ||
|
|
||
| run_case() { | ||
| local conclusion=${1} | ||
| local expected_code=${2} | ||
| local expected_message=${3} | ||
| local output | ||
| local code | ||
|
|
||
| set +e | ||
| output=$(PATH="${TMP_DIR}:${PATH}" GH_CONCLUSION="${conclusion}" bash "${SCRIPT_DIR}/wait.bash" shopware/example 1 https://github.com/shopware/example/actions/runs/1 2>&1) | ||
| code=$? | ||
| set -e | ||
|
|
||
| if [[ "${code}" -ne "${expected_code}" ]]; then | ||
| echo "Expected exit code ${expected_code} for ${conclusion}, got ${code}" | ||
| echo "${output}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "${output}" != *"${expected_message}"* ]]; then | ||
| echo "Expected output for ${conclusion} to contain: ${expected_message}" | ||
| echo "${output}" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| run_case success 0 "Downstream workflow succeeded!" | ||
| run_case failure 1 "Downstream workflow concluded with 'failure'." | ||
| run_case cancelled 1 "Downstream workflow was cancelled." | ||
|
|
||
| set +e | ||
| output=$(PATH="${TMP_DIR}:${PATH}" GH_CONCLUSION="cancelled" GH_CANCEL_EXIT=1 UPSTREAM_TOKEN=token UPSTREAM_REPOSITORY=shopware/shopware UPSTREAM_RUN_ID=1 bash "${SCRIPT_DIR}/wait.bash" shopware/example 1 https://github.com/shopware/example/actions/runs/1 2>&1) | ||
| code=$? | ||
| set -e | ||
|
|
||
| if [[ "${code}" -ne 1 || "${output}" != *"Could not cancel upstream workflow run."* ]]; then | ||
| echo "Expected failed upstream cancellation to fall back to a failed downstream wait" | ||
| echo "${output}" | ||
| exit 1 | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we want those test scripts 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the alternative would be to inline the code here then I would go with a test script for now.
We don't have a clear structure for testing workflows yet but this can be easily adapted later.