igneum/tools/ci/sims-branch-check.sh

35 lines
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# The simulators job of .github/workflows/ci.yml runs on master and release-* pushes, and on pull requests into them, ONLY (main,
# 7 October 2026: with build-2 in the runner pool the queue still read 22 because every code push cost two box jobs; a
# feature-branch code push now runs the igneum-pow tests alone). This check reads the job's `if:` line and evaluates the rule
# with the expression's own shape for the known cases, so a change that lets a feature-branch push run the simulators fails it.
#
# tools/ci/sims-branch-check.sh # exit 1 with the case that resolved wrongly (the check IS its self-test)
set -euo pipefail
cd "$(dirname "$0")/../.."
line=$(awk '/^ sims:/{f=1} f && /^ if:/{print; exit}' .github/workflows/ci.yml)
[ -n "$line" ] || { echo "sims-branch: no if: line under the sims job" >&2; exit 1; }
for want in "github.event_name == 'push'" "github.ref == 'refs/heads/master'" "startsWith(github.ref, 'refs/heads/release-')" \
"github.event_name == 'pull_request'" "github.base_ref == 'master'" "startsWith(github.base_ref, 'release-')" "needs.changes.outputs.code == 'true'"; do
case "$line" in *"$want"*) ;; *) echo "sims-branch: the sims if: line lacks \"$want\": $line" >&2; exit 1 ;; esac
done
# the rule, as the expression reads: code and ((push and (master or release-*)) or (pull_request and base (master or release-*)))
rule() { # <code> <event> <ref> <base_ref> -> run|skip
local code="$1" ev="$2" ref="$3" base="$4"
[ "$code" = true ] || { echo skip; return; }
if [ "$ev" = push ] && { [ "$ref" = refs/heads/master ] || [[ "$ref" == refs/heads/release-* ]]; }; then echo run; return; fi
if [ "$ev" = pull_request ] && { [ "$base" = master ] || [[ "$base" == release-* ]]; }; then echo run; return; fi
echo skip
}
fail=0
expect() { local want="$1"; shift; local got; got=$(rule "$@"); if [ "$got" = "$want" ]; then echo "sims-branch: [$*] -> $got"; else echo "sims-branch: [$*] -> $got, expected $want" >&2; fail=1; fi; }
expect run true push refs/heads/master ""
expect run true push refs/heads/release-0.3.20 ""
expect skip true push refs/heads/build-server ""
expect skip true push refs/heads/feature/x ""
expect run true pull_request refs/pull/12/merge master
expect run true pull_request refs/pull/12/merge release-0.3.21
expect skip true pull_request refs/pull/12/merge build-server
expect skip false push refs/heads/master ""
[ "$fail" = 0 ] && echo "sims-branch: the simulators run on master and release-* pushes and on pull requests into them only"
exit $fail