Files
cozystack/hack/pr-artifact-ref.sh
T
Aleksei Sviridkin da8d8e69bb 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>
2026-11-26 21:46:54 +03:00

33 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Print the packages artifact a pull request on <base-ref> reads its unbuilt
# images from. Main and the release lines publish their own. Any other base,
# a stacked pull request's feature branch, 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 main at the cut commit in the graph,
# so a stack on it ties and reads main's, and keeps doing so 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. A base deleted since the run started reads main's.
set -eu
if [ "$#" -ne 1 ]; then
echo "usage: pr-artifact-ref.sh <base-ref>" >&2
exit 2
fi
base=$1
if [ "$base" = main ] || printf '%s\n' "$base" | grep -qE '^release-[0-9]+\.[0-9]+$'; then
printf '%s\n' "$base"
exit 0
fi
artifact=main
if git rev-parse --verify --quiet "origin/${base}" >/dev/null; then
best="$(git rev-list --count "origin/main..origin/${base}")"
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}")"
if [ "$n" -lt "$best" ]; then best="$n"; artifact="$line"; fi
done
fi
printf '%s\n' "$artifact"