fix(ci): build a stacked PR's images from its line's fork point

A pull request whose base is another feature branch listed its changes
against that base, so one that changed only tests built no images. The
overlay then filled every package from main's or a release line's
artifact, which has none of the stack's changes, and the stack's charts
ran on images that did not match them: in one stacked run
cozystack-controller crash-looped on "flag provided but not defined:
-enable-gpu".

The overlay's choice of artifact moves into hack/pr-artifact-ref.sh,
unchanged. The plan step now takes its path lists from
hack/pr-changed-paths.sh, which uses the same choice: on main and the
release lines, which read their own artifact, it is the pull request's
own diff as before; on any other base it is the diff from the fork
point with the line whose artifact the base reads, so the images of the
pull requests below are built too, and a stack on a release line does
not rebuild everything for the line's own commits. When the fork point
cannot be found nothing may trust the lists: the step warns, builds
every image, Talos included, runs the backport-batch tests and keeps
every package's committed refs out of the overlay.

Closes: #5444
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
Aleksei Sviridkin committed 2026-11-26 21:46:54 +03:00
1 parent a2b341e31b
commit da8d8e69bb
5 files changed
+271 -29

No files matched your search

+39 -29
View File
@@ -147,7 +147,19 @@ jobs:
env:
BASE_REF: ${{ github.base_ref }}
run: |
git diff --name-only "origin/${BASE_REF}...HEAD" > /tmp/changed.txt
# hack/pr-changed-paths.sh lists a stacked pull request's changes
# against its fork point from main, so the images of the pull requests
# below it are built too. When it cannot, nothing below may trust the
# lists: every image is built, every gated test runs and every package
# keeps its committed refs.
full=false
if ! hack/pr-changed-paths.sh --renames "$BASE_REF" /tmp/changed.txt \
|| ! hack/pr-changed-paths.sh "$BASE_REF" /tmp/changed_norenames.txt; then
echo "::warning title=build-list::could not list the changed paths against the base; building every image and keeping every package's committed refs"
full=true
: > /tmp/changed.txt
: > /tmp/changed_norenames.txt
fi
# The docs-only decision reads a RENAME-BLIND list. `git diff
# --name-only` applies rename detection and reports a rename as its
# new path alone, so moving a code file into docs/ reads as a
@@ -167,7 +179,6 @@ jobs:
# under-builds on a cross-package rename. That behaviour predates this
# line and is not what the docs-only decision is for, so it is left
# alone here rather than widened by a side effect.
git diff --name-only --no-renames "origin/${BASE_REF}...HEAD" > /tmp/changed_norenames.txt
echo "Changed files:"; sed 's/^/ /' /tmp/changed_norenames.txt
# `code` is false when every path is under docs/ or in a CI-only Go
# tool that no image builds (cmd/backport-batch, cmd/api-gate): there
@@ -175,7 +186,7 @@ jobs:
# answers the same question from the PR file list with the same
# prefixes, and hack/gate-concurrency-contract.bats holds the two lists
# equal.
if grep -qvE '^(docs/|cmd/backport-batch/|cmd/api-gate/)' /tmp/changed_norenames.txt; then
if [ "$full" = true ] || grep -qvE '^(docs/|cmd/backport-batch/|cmd/api-gate/)' /tmp/changed_norenames.txt; then
echo "code=true" >> "$GITHUB_OUTPUT"
else
echo "code=false" >> "$GITHUB_OUTPUT"
@@ -187,13 +198,25 @@ jobs:
else
echo "docs=false" >> "$GITHUB_OUTPUT"
fi
backport_batch="$(hack/backport-batch-tests-needed.sh /tmp/changed_norenames.txt)"
if [ "$full" = true ]; then
backport_batch=true
else
backport_batch="$(hack/backport-batch-tests-needed.sh /tmp/changed_norenames.txt)"
fi
echo "backport-batch tests needed: $backport_batch"
echo "backport_batch=$backport_batch" >> "$GITHUB_OUTPUT"
matrix="$(hack/build-matrix.sh /tmp/changed.txt)"
if [ "$full" = true ]; then
matrix="$(hack/build-matrix.sh FULL)"
else
matrix="$(hack/build-matrix.sh /tmp/changed.txt)"
fi
echo "Build matrix: $matrix"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
talos="$(hack/build-talos-needed.sh /tmp/changed_norenames.txt)"
if [ "$full" = true ]; then
talos=true
else
talos="$(hack/build-talos-needed.sh /tmp/changed_norenames.txt)"
fi
echo "Talos build needed: $talos"
echo "talos=$talos" >> "$GITHUB_OUTPUT"
# Package dirs the PR edited (packages/<area>/<name>). Their committed
@@ -201,7 +224,11 @@ jobs:
# otherwise an upstream image bump in a non-build-unit package would be
# silently reverted in e2e/the installer artifact (see
# hack/overlay-main-images.sh). Whitespace-separated, no trailing slash.
touched="$(sed -nE 's#^(packages/[^/]+/[^/]+)/.*#\1#p' /tmp/changed.txt | sort -u | tr '\n' ' ')"
if [ "$full" = true ]; then
touched="$(find packages -mindepth 2 -maxdepth 2 -type d | sort | tr '\n' ' ')"
else
touched="$(sed -nE 's#^(packages/[^/]+/[^/]+)/.*#\1#p' /tmp/changed.txt | sort -u | tr '\n' ' ')"
fi
echo "Touched packages: $touched"
echo "touched=$touched" >> "$GITHUB_OUTPUT"
if [ "$matrix" = "[]" ]; then
@@ -744,33 +771,16 @@ jobs:
# branch, so each base branch has its own artifact to read.
#
# A base that is neither main nor a line (a stacked PR's feature branch) has
# no artifact, and a `/` in it is not even a valid OCI tag. It reads the
# artifact of whichever of main and the lines it has the fewest commits on
# top of. A tie goes to main. A line with no commit of its own yet is, in
# the graph, main at the cut commit, so a stack on it ties and reads the
# artifact built from main's tip. That artifact carries newer images than
# the line once main moves past the cut. The stack keeps reading it until
# it contains a commit of the line's own. Breaking the tie towards the
# line instead would misroute the far more common branch forked from main
# before the cut, which ties the same way.
# no artifact, and a `/` in it is not even a valid OCI tag.
# hack/pr-artifact-ref.sh picks the artifact such a base reads; the plan
# step lists the changes against the same artifact's line.
#
# A missing artifact stays a no-op (packages keep their committed refs), which
# also covers a line whose first build-release run has not landed yet.
- name: Pull base-branch packages tree
run: |
ARTIFACT_REF="$BASE_REF"
if [ "$BASE_REF" != "main" ] \
&& ! printf '%s' "$BASE_REF" | grep -qE '^release-[0-9]+\.[0-9]+$'; then
ARTIFACT_REF=main
# A re-run can outlive its base: the payload keeps a branch deleted since.
if git rev-parse --verify --quiet "origin/${BASE_REF}" >/dev/null; then
best="$(git rev-list --count "origin/main..origin/${BASE_REF}")"
for line in $(git for-each-ref --format='%(refname:lstrip=3)' 'refs/remotes/origin/release-*' \
| grep -E '^release-[0-9]+\.[0-9]+$'); do
n="$(git rev-list --count "origin/${line}..origin/${BASE_REF}")"
if [ "$n" -lt "$best" ]; then best="$n"; ARTIFACT_REF="$line"; fi
done
fi
ARTIFACT_REF="$(hack/pr-artifact-ref.sh "$BASE_REF")"
if [ "$ARTIFACT_REF" != "$BASE_REF" ]; then
echo "::notice::Base ${BASE_REF} publishes no packages artifact; overlaying cozystack-packages:${ARTIFACT_REF}."
fi
rm -rf _out/mainpkgs