fix: squash weekly recipe PRs before CI

This commit is contained in:
notplants
2026-11-09 20:30:25 +00:00
parent e37e10c86b
commit 22d8ea0ae9
3 changed files with 40 additions and 39 deletions
+28 -32
View File
@@ -20,11 +20,9 @@
# never reflected it.
#
# Default mode (open a PR — preconditions: HEAD has the upgrade commit(s)):
# - If an open UPGRADE PR already exists for this recipe (branch 'upgrade-*'), the new work is added
# as a commit ON TOP of THAT PR's branch (a fast-forward — NO force-push) and the PR is updated +
# re-tested — ONE evolving upgrade PR per recipe, NOT a second parallel PR. Otherwise a fresh
# 'upgrade-<version>' branch + PR is opened. (The only force-push here is the mirror-main sync
# above, which intentionally mirrors upstream main; PR branches are never force-pushed.)
# - Publish the final recipe tree as ONE commit directly on current upstream main before !testme.
# If an open upgrade PR exists, replace its branch with this single commit using
# --force-with-lease, then re-test the same PR. Otherwise open a fresh upgrade PR.
# - Unrelated open PRs (e.g. a backup fix) are NEVER closed or touched — left for the operator.
# - Only PRs already merged into upstream main are closed (no-op merges) — see above.
#
@@ -165,9 +163,8 @@ if [ "${MODE}" = "--reconcile-only" ]; then
exit 0
fi
# --- DEFAULT: if an open upgrade PR exists, push the new work onto ITS branch and re-test it, so
# there's ONE evolving upgrade PR per recipe rather than parallel ones. Only if none exists do we
# open a fresh upgrade-<version> PR. Unrelated open PRs are never touched. ---
# --- DEFAULT: publish one commit with the final tree on current upstream main. This collapses
# old local commits and merge commits while preserving the exact content to be tested. ---
if [ -n "${EXTEND_PR}" ]; then
BRANCH="${EXTEND_BRANCH}"
echo "→ Extending existing open upgrade PR #${EXTEND_PR} (branch ${BRANCH}) with the new work — it will be re-tested; NOT opening a separate PR."
@@ -178,39 +175,38 @@ else
BRANCH="upgrade-$(git rev-parse --short HEAD)"
fi
# Land the work on the PR branch WITHOUT force-pushing. If the branch already exists (extend case, or
# a stale same-named branch), add a commit ON TOP of its tip — a fast-forward, so the PR's history is
# preserved and it re-tests. Otherwise push a fresh branch.
# Do not create an empty PR when the proposed tree equals current upstream main.
UPSTREAM_TREE=$(git rev-parse "${NEW_MAIN_SHA}^{tree}")
WORK_TREE=$(git rev-parse 'HEAD^{tree}')
[ "${WORK_TREE}" != "${UPSTREAM_TREE}" ] || {
echo "ERROR: proposed recipe tree is identical to upstream main; nothing to PR."
exit 1
}
# The PR branch is a single commit on the current upstream tip. Reusing an existing PR requires a
# guarded rewrite; the lease rejects concurrent updates instead of overwriting another writer.
SQUASHED=$(GIT_AUTHOR_NAME="${GITEA_USERNAME}" GIT_AUTHOR_EMAIL="${GITEA_USERNAME}@git.autonomic.zone" \
GIT_COMMITTER_NAME="${GITEA_USERNAME}" GIT_COMMITTER_EMAIL="${GITEA_USERNAME}@git.autonomic.zone" \
git commit-tree "${WORK_TREE}" -p "${NEW_MAIN_SHA}" -m "${LATEST_MSG}")
if git rev-parse --verify --quiet "refs/remotes/gitea/${BRANCH}" >/dev/null; then
EXIST_TIP=$(git rev-parse "refs/remotes/gitea/${BRANCH}")
if [ "$(git rev-parse 'HEAD^{tree}')" = "$(git rev-parse "${EXIST_TIP}^{tree}")" ]; then
echo "→ '${BRANCH}' already has this exact tree — nothing new to push (will still re-test)."
if [ "$(git rev-parse "${EXIST_TIP}^{tree}")" = "${WORK_TREE}" ] &&
[ "$(git rev-parse "${EXIST_TIP}^" 2>/dev/null || true)" = "${NEW_MAIN_SHA}" ]; then
echo "→ '${BRANCH}' already has this one-commit diff — nothing new to push (will still re-test)."
else
# Parent the new commit on the branch tip AND (when the branch predates it) on upstream main, so
# the recorded HISTORY matches the tree we are pushing. Without the second parent the merge-base
# stays stale: git would later treat upstream's post-branch changes as "removed by this PR" and a
# merge could revert them (the gitea #5 / forgejo-removal drift, 2026-08-10). No force-push: this
# is still a fast-forward from the branch tip.
EXTRA_PARENT=()
if ! git merge-base --is-ancestor "${NEW_MAIN_SHA}" "${EXIST_TIP}"; then
EXTRA_PARENT=(-p "${NEW_MAIN_SHA}")
echo " (also parenting on upstream main ${NEW_MAIN_SHA:0:8} — branch predated it)"
fi
ONTOP=$(GIT_AUTHOR_NAME="${GITEA_USERNAME}" GIT_AUTHOR_EMAIL="${GITEA_USERNAME}@git.autonomic.zone" \
GIT_COMMITTER_NAME="${GITEA_USERNAME}" GIT_COMMITTER_EMAIL="${GITEA_USERNAME}@git.autonomic.zone" \
git commit-tree "$(git rev-parse 'HEAD^{tree}')" -p "${EXIST_TIP}" "${EXTRA_PARENT[@]}" -m "${LATEST_MSG}")
echo "→ Adding the new work on top of '${BRANCH}' (fast-forward, no force-push)..."
git push gitea "${ONTOP}:refs/heads/${BRANCH}"
echo "→ Replacing '${BRANCH}' with one commit on upstream ${NEW_MAIN_SHA:0:8} (force-with-lease)..."
git push --force-with-lease="refs/heads/${BRANCH}:${EXIST_TIP}" gitea \
"${SQUASHED}:refs/heads/${BRANCH}"
fi
else
echo "→ Pushing new branch '${BRANCH}'..."
git push gitea "HEAD:refs/heads/${BRANCH}"
echo "→ Pushing one-commit branch '${BRANCH}' on upstream ${NEW_MAIN_SHA:0:8}..."
git push gitea "${SQUASHED}:refs/heads/${BRANCH}"
fi
PR_BODY="${RECIPE_PR_BODY:-$(printf 'Recipe upgrade.\n\nCommits on top of upstream main:\n\n%s\n' "$(git log origin/main..HEAD --pretty='- %h %s')")}"
PR_BODY="${RECIPE_PR_BODY:-$(printf 'Recipe upgrade as one commit on upstream %s.\n\n%s\n' "${NEW_MAIN_SHA:0:8}" "$(git diff --stat "${NEW_MAIN_SHA}" "${SQUASHED}")")}"
PR_BODY="${PR_BODY}
Tested green on the cc-ci recipe CI server (full suite, cold, against this PR head). NOT merged — for operator review.
CI verification is run against this one-commit PR head. NOT merged — for operator review.
cc @trav @notplants"