[t-mmyx6d0xfp0x] fix: open a pull request when main is protected
test / test (pull_request) Successful in 4s
test / test (pull_request) Successful in 4s
Every cascade from base and base-dev has failed since August: runner, base-dev and base-agent protect main against all pushes, so the direct push is refused three times and the release job fails, and a refused first target also skips the next cascade step. Push the bump to cascade/<name>-<tag> and open a pull request instead, so it lands through the target's review. Targets that still allow ci-bot to push (fritzlab/agent) keep the direct push. The script moves out of action.yaml into cascade.sh so tests/run can drive it against local bare repositories and a stubbed API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43875de6b4
commit
d3dce56c31
6 files changed
+238
-56
No files matched your search
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# Gitea API stub for cascade.sh tests: logs each call, answers CURL_STATUS.
|
||||
set -euo pipefail
|
||||
|
||||
out="" data="" url="" method=GET
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o) out="$2"; shift 2 ;;
|
||||
-X) method="$2"; shift 2 ;;
|
||||
--data) data="$2"; shift 2 ;;
|
||||
-w|-H) shift 2 ;;
|
||||
http*) url="$1"; shift ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
printf '%s %s %s\n' "$method" "$url" "$data" >>"${CURL_LOG}"
|
||||
status="${CURL_STATUS:-201}"
|
||||
if [ "$status" = 201 ]; then
|
||||
printf '{"html_url":"https://code.test/pulls/7"}' >"$out"
|
||||
else
|
||||
printf '{"message":"stub %s"}' "$status" >"$out"
|
||||
fi
|
||||
printf '%s' "$status"
|
||||
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for cascade.sh against local bare repositories. A pre-receive hook
|
||||
# stands in for Gitea branch protection; tests/bin/curl stands in for the API.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT="$(cd "$(dirname "$0")/.." && pwd)/cascade.sh"
|
||||
TEST_BIN="$(cd "$(dirname "$0")" && pwd)/bin"
|
||||
IMAGE=code.test/fritzlab/base-dev
|
||||
PASS=0
|
||||
FAIL=0
|
||||
ROOT=$(mktemp -d)
|
||||
trap 'rm -rf "${ROOT}"' EXIT
|
||||
|
||||
ok() { echo "PASS [$1]"; PASS=$((PASS + 1)); }
|
||||
bad() { echo "FAIL [$1]: $2"; echo " output: ${OUT}"; FAIL=$((FAIL + 1)); }
|
||||
|
||||
# fresh_remote <protected:0|1> <from-tag>: a bare fritzlab/target on main.
|
||||
fresh_remote() {
|
||||
rm -rf "${ROOT}/remotes" "${ROOT}/seed"
|
||||
mkdir -p "${ROOT}/remotes/fritzlab"
|
||||
git init -q --bare -b main "${ROOT}/remotes/fritzlab/target.git"
|
||||
git init -q -b main "${ROOT}/seed"
|
||||
printf 'FROM %s:%s\nRUN true\n' "${IMAGE}" "$2" >"${ROOT}/seed/Dockerfile"
|
||||
git -C "${ROOT}/seed" add Dockerfile
|
||||
git -C "${ROOT}/seed" -c user.name=t -c user.email=t@test commit -q -m seed
|
||||
git -C "${ROOT}/seed" push -q "${ROOT}/remotes/fritzlab/target.git" main
|
||||
if [ "$1" = 1 ]; then
|
||||
cat >"${ROOT}/remotes/fritzlab/target.git/hooks/pre-receive" <<'HOOK'
|
||||
#!/usr/bin/env bash
|
||||
while read -r _ _ ref; do
|
||||
if [ "$ref" = refs/heads/main ]; then
|
||||
echo "error: Not allowed to push to protected branch main" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
HOOK
|
||||
chmod +x "${ROOT}/remotes/fritzlab/target.git/hooks/pre-receive"
|
||||
fi
|
||||
: >"${ROOT}/curl.log"
|
||||
}
|
||||
|
||||
# cascade <tag> [CURL_STATUS]: run the action script; sets OUT and RC.
|
||||
cascade() {
|
||||
RC=0
|
||||
OUT=$(cd "${ROOT}" && env PATH="${TEST_BIN}:$PATH" CURL_LOG="${ROOT}/curl.log" \
|
||||
CURL_STATUS="${2:-201}" TARGET_REPO=fritzlab/target IMAGE="${IMAGE}" TAG_INPUT="$1" \
|
||||
FILE=Dockerfile TOKEN=test-token HOST=code.test MESSAGE= RUN_NUMBER=99 \
|
||||
GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="url.file://${ROOT}/remotes/.insteadOf" \
|
||||
GIT_CONFIG_VALUE_0="https://ci-bot:test-token@code.test/" \
|
||||
bash "${SCRIPT}" 2>&1) || RC=$?
|
||||
}
|
||||
|
||||
remote_from() {
|
||||
git --git-dir="${ROOT}/remotes/fritzlab/target.git" show "$1:Dockerfile" 2>/dev/null | head -1
|
||||
}
|
||||
|
||||
fresh_remote 0 20
|
||||
cascade 22
|
||||
if [ "$RC" -eq 0 ] && [ "$(remote_from main)" = "FROM ${IMAGE}:22" ] && [ ! -s "${ROOT}/curl.log" ]; then
|
||||
ok "open main takes the bump directly"
|
||||
else
|
||||
bad "open main takes the bump directly" "rc=${RC} main=$(remote_from main)"
|
||||
fi
|
||||
|
||||
fresh_remote 1 20
|
||||
cascade 22
|
||||
if [ "$RC" -eq 0 ] && [ "$(remote_from main)" = "FROM ${IMAGE}:20" ] \
|
||||
&& [ "$(remote_from cascade/base-dev-22)" = "FROM ${IMAGE}:22" ] \
|
||||
&& grep -q '^POST https://code.test/api/v1/repos/fritzlab/target/pulls ' "${ROOT}/curl.log" \
|
||||
&& grep -q '"head":"cascade/base-dev-22"' <(tr -d ' \n' <"${ROOT}/curl.log") \
|
||||
&& grep -q '"title":"bumpbase-devto#22"' <(tr -d ' \n' <"${ROOT}/curl.log") \
|
||||
&& grep -q 'proposed base-dev:22' <<<"${OUT}"; then
|
||||
ok "protected main gets a pull request"
|
||||
else
|
||||
bad "protected main gets a pull request" "rc=${RC} main=$(remote_from main) log=$(cat "${ROOT}/curl.log")"
|
||||
fi
|
||||
|
||||
cascade 22 409
|
||||
if [ "$RC" -eq 0 ] && grep -q 'cascade/base-dev-22 already exists' <<<"${OUT}" \
|
||||
&& grep -q 'already open' <<<"${OUT}"; then
|
||||
ok "a re-run reuses the open pull request"
|
||||
else
|
||||
bad "a re-run reuses the open pull request" "rc=${RC}"
|
||||
fi
|
||||
|
||||
fresh_remote 1 20
|
||||
cascade 22 403
|
||||
if [ "$RC" -eq 1 ] && grep -q 'answered HTTP 403' <<<"${OUT}"; then
|
||||
ok "a refused pull request fails the step"
|
||||
else
|
||||
bad "a refused pull request fails the step" "rc=${RC}"
|
||||
fi
|
||||
|
||||
fresh_remote 1 22
|
||||
cascade 22
|
||||
if [ "$RC" -eq 0 ] && grep -q 'already on base-dev:22, skipping' <<<"${OUT}" && [ ! -s "${ROOT}/curl.log" ]; then
|
||||
ok "a target already on the tag is left alone"
|
||||
else
|
||||
bad "a target already on the tag is left alone" "rc=${RC}"
|
||||
fi
|
||||
|
||||
echo "${PASS} passed, ${FAIL} failed"
|
||||
[ "${FAIL}" -eq 0 ]
|
||||
Reference in new issue
Block a user