Skip to content

Commit f8fb128

Browse files
committed
fix(ci): stop a blank line lost to yq from costing a package its overlay
The overlay keeps a package on its committed release ref when the artifact copy differs from the repo on any line that is not image-reference-bearing. A blank line is such a line, and the build produces one on its own: yq -i re-emits the document when it stamps a digest, and a blank line separating two top-level keys does not come back. So a file the PR never touched differs from the artifact on a line carrying no configuration, and loses its overlay for it. That was the whole of the remaining drift list. Against the public nightly artifact at its own revision, with the tree checked out at that same revision: before drift=5 overlaid=29 core/platform, cozystack-api, dashboard, kubeovn-webhook, linstor-gui after drift=0 overlaid=34 Each of the five differed from the artifact by one blank line and its own ref, nothing else, which is reproducible locally by running the stamping assignment over the committed file. cozystack-api and dashboard are not peripheral: an e2e result about either was a result about the last release rather than about main. Discount blank lines before the test. A line with content still counts, so a real config difference keeps the committed ref as before. Assisted-by: LLM Signed-off-by: IvanHunters <[email protected]>
1 parent dffa880 commit f8fb128

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎hack/overlay-main-images.sh‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,16 @@ for new in $(find "$MAINPKGS" -type d -name charts -prune -o \
115115
[ -f "$cur" ] || continue # not in the PR tree -> don't introduce it
116116
cmp -s "$cur" "$new" && { same=$((same + 1)); continue; }
117117

118-
if diff "$cur" "$new" | sed -n 's/^[<>] //p' | grep -qvE "$img_line"; then
118+
# Blank lines are dropped before the test. `yq -i` does not preserve them:
119+
# stamping a digest re-emits the document, and a blank line separating two
120+
# top-level keys does not come back. The stamp therefore changes a file the
121+
# PR never touched, on a line carrying no configuration at all, and the whole
122+
# file loses its overlay for it. That is not a corner case -- on the run
123+
# behind #4265 it was the entire remaining drift list: core/platform,
124+
# cozystack-api, dashboard, kubeovn-webhook and linstor-gui each differed
125+
# from the artifact by one blank line and their own ref, nothing else.
126+
if diff "$cur" "$new" | sed -n 's/^[<>] //p' \
127+
| grep -vE '^[[:space:]]*$' | grep -qvE "$img_line"; then
119128
echo "drift (non-ref change) in $cur -> keeping committed ref"
120129
drift=$((drift + 1))
121130
drift_files="$drift_files $(dirname "${cur#packages/}")"

‎hack/overlay-main-images_test.bats‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,39 @@
258258
rm -rf "$w"
259259
}
260260

261+
# `yq -i` re-emits the document when the build stamps a digest, and a blank
262+
# line separating two top-level keys does not survive that. So the artifact copy
263+
# of a file the PR never touched differs from the committed one by a line
264+
# carrying no configuration, and treating that as a config change costs the file
265+
# its overlay. Five packages drifted on nothing else (#4265).
266+
@test "a blank line lost to yq is not a config change" {
267+
root=$(pwd)
268+
w=$(mktemp -d)
269+
mkdir -p "$w/packages/system/epsilon" "$w/main/system/epsilon"
270+
printf '_cluster: {}\n\nepsilon:\n image: "ghcr.io/cozystack/cozystack/epsilon:v1.6.0@sha256:aaaa"\n' > "$w/packages/system/epsilon/values.yaml"
271+
printf '_cluster: {}\nepsilon:\n image: "iad.ocir.io/x/cozystack/epsilon:main@sha256:bbbb"\n' > "$w/main/system/epsilon/values.yaml"
272+
( cd "$w" && "$root/hack/overlay-main-images.sh" main '[]' ) > "$w/out.txt"
273+
grep -q 'overlay: packages/system/epsilon/values.yaml' "$w/out.txt"
274+
! grep -q 'drift (non-ref change)' "$w/out.txt"
275+
grep -q 'iad.ocir.io/x/cozystack/epsilon:main' "$w/packages/system/epsilon/values.yaml"
276+
rm -rf "$w"
277+
}
278+
279+
# A blank line is discounted, a line with CONTENT is not: the guard that keeps
280+
# a real config difference from riding along with the ref lines is the same one,
281+
# so it needs its own case rather than trusting the blank-line test above.
282+
@test "a real config line still counts as drift alongside a blank line" {
283+
root=$(pwd)
284+
w=$(mktemp -d)
285+
mkdir -p "$w/packages/system/zeta" "$w/main/system/zeta"
286+
printf '_cluster: {}\n\nzeta:\n image: "ghcr.io/cozystack/cozystack/zeta:v1.6.0@sha256:aaaa"\n replicas: 2\n' > "$w/packages/system/zeta/values.yaml"
287+
printf '_cluster: {}\nzeta:\n image: "iad.ocir.io/x/cozystack/zeta:main@sha256:bbbb"\n replicas: 3\n' > "$w/main/system/zeta/values.yaml"
288+
( cd "$w" && "$root/hack/overlay-main-images.sh" main '[]' ) > "$w/out.txt"
289+
grep -q 'drift (non-ref change) in packages/system/zeta/values.yaml' "$w/out.txt"
290+
grep -q 'replicas: 2' "$w/packages/system/zeta/values.yaml"
291+
rm -rf "$w"
292+
}
293+
261294
@test "drift is summarised as a GitHub annotation naming the packages" {
262295
root=$(pwd)
263296
w=$(mktemp -d)

0 commit comments

Comments
 (0)