mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 02:54:26 +00:00
The Validation step "Assert the base branch is fully merged into the PR head" ran main_merged.sh, which fetches the live tip of main when the job starts. PR runs wait in the queue for hours while image-update PRs land on main several times an hour, so nearly every queued run failed Validation on start and had to be re-pushed after another main merge (PR #1265: behind_by=0 at push, behind_by=9 while its run still queued). main_merged.sh takes a new INFINITO_MAIN_COMMIT override: when set, it fetches that full commit SHA from the remote and requires HEAD to contain it instead of the live tip; a set but malformed or empty value exits 2. The Validation step passes github.event.pull_request.base.sha, the main tip at event time, which the step's pull_request-only guard always provides. The run tests the merge against that base, so the gate still guarantees the tested tree contains it. The local pre-push hook (make test-main-merged) leaves the override unset and keeps checking the live tip: a push happens right now, so lagging the current main is the real defect there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.6 KiB
Bash
Executable File
41 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Pre-push gate: fail unless the upstream main branch is fully merged into HEAD.
|
|
# Fetches the remote main tip and requires every commit on it to be reachable
|
|
# from the current tip, so a branch can never be pushed while it lags main.
|
|
#
|
|
# Env overrides: INFINITO_MAIN_REMOTE (default origin), INFINITO_MAIN_BRANCH
|
|
# (default main), INFINITO_MAIN_COMMIT (unset: check the live branch tip; set:
|
|
# fetch and check this full commit SHA of that branch instead, e.g. the base
|
|
# SHA a CI event carries).
|
|
set -euo pipefail
|
|
|
|
remote="${INFINITO_MAIN_REMOTE:-origin}" # nocheck: git maintainer tooling knob, not a deployment env key
|
|
branch="${INFINITO_MAIN_BRANCH:-main}" # nocheck: git maintainer tooling knob, not a deployment env key
|
|
|
|
if [[ -v INFINITO_MAIN_COMMIT ]]; then
|
|
target="${INFINITO_MAIN_COMMIT}" # nocheck: git maintainer tooling knob, not a deployment env key
|
|
if [[ ! "$target" =~ ^[0-9a-f]{40}([0-9a-f]{24})?$ ]]; then
|
|
echo "❌ assert-main-merged: INFINITO_MAIN_COMMIT must be a full commit SHA, got '${target}'." >&2
|
|
exit 2
|
|
fi
|
|
label="${remote}/${branch}@${target}"
|
|
else
|
|
target="$branch"
|
|
label="${remote}/${branch}"
|
|
fi
|
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
echo "assert-main-merged: fetching ${label} ..." >&2
|
|
git fetch --quiet "$remote" "$target"
|
|
|
|
if git merge-base --is-ancestor FETCH_HEAD HEAD; then
|
|
echo "✅ assert-main-merged: ${label} is fully merged into HEAD." >&2
|
|
exit 0
|
|
fi
|
|
|
|
behind="$(git rev-list --count HEAD..FETCH_HEAD)"
|
|
echo "❌ assert-main-merged: ${label} has ${behind} commit(s) not merged into HEAD." >&2
|
|
echo " Merge upstream main first, e.g.: git pull ${remote} ${branch}" >&2
|
|
exit 1
|