Files
cozystack/hack/promote-rc-dispatch-ref_test.bats
T
Marian Koreniuk e89821ca2e ci(release): refuse a Promote RC dispatch from any ref but main
A workflow_dispatch runs the copy of promote-rc.yaml at the ref it was
dispatched from. On 2026-10-16 a dispatch from release-1.6 ran that
branch's older copy, one job instead of five, and had to be re-run from
main. Since the release assets are signed, the same dispatch would now
fail at the upload step, after the staging branch, the promotion-*
candidate and the draft release already exist, and
docs/release/signatures-and-sbom.md pins the signature identity to this
workflow on main.

Make the first step of parse compare github.ref with refs/heads/main and
fail with an error that names main, so a dispatch from a release branch,
a tag or a SHA stops before the first write. The bats test runs the
step's shell under dash for main, a release branch, a tag and an empty
ref, and pins the step to be the first one in parse.

The release docs tell the operator to dispatch from main and state that
only a copy carrying the check refuses other refs: older release-X.Y
copies stay callable and still write before stopping.

Assisted-by: LLM
Signed-off-by: Marian Koreniuk <moriarti@cp.if.ua>
2026-11-27 19:14:10 +01:00

41 lines
1.4 KiB
Bash

#!/usr/bin/env bats
# promote-rc.yaml is dispatched from main only: a dispatch from another ref
# runs that ref's copy of the workflow, and the release signature names main
# as the identity. The refuse step has to be the first thing parse does, so a
# wrong dispatch fails before the staging branch, the promotion-* candidate or
# the draft release exist.
#
# Run with: bats hack/promote-rc-dispatch-ref_test.bats
load test_helper
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
WF="$REPO_ROOT/.github/workflows/promote-rc.yaml"
STEP_NAME="Refuse a dispatch from any ref but main"
_step_run() {
yq ".jobs.parse.steps[] | select(.name == \"$STEP_NAME\").run" "$WF"
}
@test "the refuse step is the first step of parse and reads github.ref" {
[ "$(yq '.jobs.parse.steps[0].name' "$WF")" = "$STEP_NAME" ]
[ "$(yq '.jobs.parse.steps[0].env.REF' "$WF")" = '${{ github.ref }}' ]
}
@test "a dispatch from main passes" {
step="$(_step_run)"
[ -n "$step" ]
run env REF=refs/heads/main dash -c "$step"
[ "$status" -eq 0 ]
}
@test "a dispatch from a release branch or a tag fails and names main" {
step="$(_step_run)"
for ref in refs/heads/release-1.7 refs/tags/v1.7.0-rc.3 ""; do
run env REF="$ref" dash -c "$step"
[ "$status" -ne 0 ]
printf '%s\n' "$output" | grep -qF "::error::"
printf '%s\n' "$output" | grep -qF "from 'main'"
done
}