Skip to content

Commit 9c5c5f9

Browse files
committed
fix(ci): overlay the right line's refs for a PR on a feature branch
The base-branch overlay pulled cozystack-packages:<base_ref>. A stacked PR's base is a feature branch such as fix/foo: the slash is not valid in an OCI tag and no artifact is published for it, so the pull failed, the step only warned, and every package the PR did not rebuild ran its committed release ref. With a committed ref older than its chart, that broke E2E (Grafana plugin 404). main and release-X.Y still read their own artifact. Any other base reads the artifact of whichever of main and the release lines it has the fewest commits on top of. Always picking main would put main's images under a release line's charts for a stack rooted on that line, the cross-generation mix that fails install. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 564f540 commit 9c5c5f9

2 files changed

Lines changed: 76 additions & 8 deletions

File tree

‎.github/workflows/pull-requests.yaml‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,24 +639,46 @@ jobs:
639639
# cozystack-packages:<line> for every maintained release-<major>.<minor>
640640
# branch, so each base branch has its own artifact to read.
641641
#
642+
# A base that is neither main nor a line (a stacked PR's feature branch) has
643+
# no artifact, and a `/` in it is not even a valid OCI tag. It reads the
644+
# artifact of whichever of main and the lines it has the fewest commits on
645+
# top of. A tie goes to main, so a stack on a line keeps that line's
646+
# generation only once the line has a commit of its own: a line fresh off
647+
# main is topologically the same as main at that commit.
648+
#
642649
# A missing artifact stays a no-op (packages keep their committed refs), which
643650
# also covers a line whose first build-release run has not landed yet.
644651
- name: Pull base-branch packages tree
645652
run: |
653+
ARTIFACT_REF="$BASE_REF"
654+
if [ "$BASE_REF" != "main" ] \
655+
&& ! printf '%s' "$BASE_REF" | grep -qE '^release-[0-9]+\.[0-9]+$'; then
656+
ARTIFACT_REF=main
657+
# A re-run can outlive its base: the payload keeps a branch deleted since.
658+
if git rev-parse --verify --quiet "origin/${BASE_REF}" >/dev/null; then
659+
best="$(git rev-list --count "origin/main..origin/${BASE_REF}")"
660+
for line in $(git for-each-ref --format='%(refname:lstrip=3)' 'refs/remotes/origin/release-*' \
661+
| grep -E '^release-[0-9]+\.[0-9]+$'); do
662+
n="$(git rev-list --count "origin/${line}..origin/${BASE_REF}")"
663+
if [ "$n" -lt "$best" ]; then best="$n"; ARTIFACT_REF="$line"; fi
664+
done
665+
fi
666+
echo "::notice::Base ${BASE_REF} publishes no packages artifact; overlaying cozystack-packages:${ARTIFACT_REF}."
667+
fi
646668
rm -rf _out/mainpkgs
647669
mkdir -p _out/mainpkgs
648-
if ! flux pull artifact "oci://${REGISTRY}/cozystack-packages:${BASE_REF}" \
670+
if ! flux pull artifact "oci://${REGISTRY}/cozystack-packages:${ARTIFACT_REF}" \
649671
--output _out/mainpkgs; then
650672
rm -rf _out/mainpkgs
651673
# Degrading to committed refs is safe, but SAY so: on a release line a
652674
# missing artifact means build-release.yaml has not published this line
653675
# yet (first build pending, or its branch filter does not match this
654676
# branch), and the PR is then testing the line's last release instead of
655677
# its tip. Silent would look identical to a working overlay.
656-
if [ "${BASE_REF}" = "main" ]; then
657-
echo "cozystack-packages:${BASE_REF} pull failed — keeping committed refs"
678+
if [ "${ARTIFACT_REF}" = "main" ]; then
679+
echo "cozystack-packages:${ARTIFACT_REF} pull failed — keeping committed refs"
658680
else
659-
echo "::warning title=No packages artifact for ${BASE_REF}::Keeping committed refs, so unbuilt packages use this line's last release rather than its tip. Check that build-release.yaml has run for ${BASE_REF}."
681+
echo "::warning title=No packages artifact for ${ARTIFACT_REF}::Keeping committed refs, so unbuilt packages use this line's last release rather than its tip. Check that build-release.yaml has run for ${ARTIFACT_REF}."
660682
fi
661683
fi
662684
env:

‎hack/overlay-main-images_test.bats‎

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@
204204
inside')"
205205
[ -n "$block" ] || { echo "the base-branch packages pull step is missing from $wf" >&2; exit 1; }
206206

207-
# The artifact tag must come from the base branch, passed via env.
208-
printf '%s\n' "$block" | grep -qF 'cozystack-packages:${BASE_REF}' || {
209-
echo "the packages artifact tag is not the PR's base branch. Reading a fixed" >&2
210-
echo "tag (e.g. :main) hands a release-line PR another generation's images." >&2
207+
# The artifact tag must be derived from the base branch, passed via env.
208+
printf '%s\n' "$block" | grep -qF 'cozystack-packages:${ARTIFACT_REF}' || {
209+
echo "the packages artifact tag is not derived from the PR's base branch. Reading" >&2
210+
echo "a fixed tag (e.g. :main) hands a release-line PR another generation's images." >&2
211211
exit 1; }
212212
printf '%s\n' "$block" | grep -qF 'BASE_REF: ${{ github.base_ref }}' || {
213213
echo "BASE_REF is not wired to github.base_ref in the pull step's env." >&2; exit 1; }
@@ -223,6 +223,52 @@
223223
return 0
224224
}
225225

226+
# A stacked PR's base is a feature branch: `fix/x` is not a valid OCI tag, and
227+
# no artifact is published for it anyway. Such a PR must read the artifact of
228+
# the line its stack grew from, not fall through to the committed release refs
229+
# (#4391), and not main's when the stack sits on a release line (#3437).
230+
@test "the pull step maps the base branch to a published artifact tag" {
231+
root=$(pwd)
232+
w="${BATS_TEST_TMPDIR:-$(mktemp -d)}"
233+
git init --quiet --initial-branch=main "$w/repo"
234+
cd "$w/repo"
235+
git config user.email [email protected]
236+
git config user.name ci
237+
git config commit.gpgsign false
238+
c() { git commit --quiet --allow-empty --message "$1"; }
239+
c m1
240+
git checkout --quiet -b release-1.5; c q1
241+
git checkout --quiet main; git checkout --quiet -b release-1.6; c r1
242+
git checkout --quiet -b stack/x; c s1
243+
git checkout --quiet release-1.6; git checkout --quiet -b release-1.6.1; c p1
244+
git checkout --quiet main; c m2; c m3
245+
# release-1.7 and fix/some-branch both grow from m3, so they tie: main must win.
246+
git checkout --quiet -b release-1.7; c x1
247+
git checkout --quiet main; git checkout --quiet -b fix/some-branch; c f1
248+
for b in main release-1.5 release-1.6 release-1.7 stack/x release-1.6.1 fix/some-branch; do
249+
git update-ref "refs/remotes/origin/$b" "$b"
250+
done
251+
252+
script="$(awk '
253+
$0 == " - name: Pull base-branch packages tree" { step = 1; next }
254+
step && /^ - name: / { exit }
255+
step && $0 == " run: |" { body = 1; next }
256+
body && /^ [^ ]/ { exit }
257+
body { sub(/^ /, ""); print }' "$root/.github/workflows/pull-requests.yaml")"
258+
[ -n "$script" ] || { echo "cannot extract the pull step's script" >&2; exit 1; }
259+
260+
mkdir -p "$w/bin"
261+
printf '#!/bin/sh\nprintf "%%s\\n" "$3" > "%s/pulled"\nexit 1\n' "$w" > "$w/bin/flux"
262+
chmod +x "$w/bin/flux"
263+
for pair in main=main release-1.6=release-1.6 fix/some-branch=main \
264+
stack/x=release-1.6 release-1.6.1=release-1.6 gone/branch=main; do
265+
rm -f "$w/pulled"
266+
BASE_REF="${pair%%=*}" REGISTRY=r PATH="$w/bin:$PATH" bash -eo pipefail -c "$script" >/dev/null
267+
[ "$(cat "$w/pulled")" = "oci://r/cozystack-packages:${pair#*=}" ] || {
268+
echo "base ${pair%%=*}: pulled '$(cat "$w/pulled")', want tag ${pair#*=}" >&2; exit 1; }
269+
done
270+
}
271+
226272
@test "every maintained release line publishes its own packages artifact" {
227273
root=$(pwd)
228274
wf="$root/.github/workflows/build-release.yaml"

0 commit comments

Comments
 (0)