mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 12:16:03 +09:00
fix(ci): build a stacked PR's images from its line's fork point (#5463)
## What this PR does A pull request stacked on another feature branch builds its images from its own diff against that branch, so one that changes only tests builds no images. The overlay then fills every package from main's or a release line's artifact, which has none of the stack's changes, and the stack's charts run on images that do not match them. In one stacked run cozystack-controller crash-looped on `flag provided but not defined: -enable-gpu`. With this change the build list of such a pull request comes from the fork point with the line whose artifact the overlay reads, so the images of the pull requests below it are built too. On main and the release lines nothing changes. When the fork point cannot be found, CI warns, builds every image, Talos included, and keeps the committed refs out of the overlay. #4460 already fixed the overlay tag for a feature-branch base; this is the build list beside it. #4911 applies the same fork-point rule to the Kairos worker disks only; this PR covers every image. The new hack/pr-changed-paths_test.bats and the existing overlay tests pass locally under Bats. I have not seen a stacked pull request run through this workflow yet. Closes #5444 ### Screenshots ### Downstream repositories - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(ci): build a stacked pull request's images from the fork point of the line its base belongs to, so a stack that changes only tests no longer runs e2e on main's images. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Build & Validation** * Pull request checks now account for renamed files when determining which builds and tests to run. * If changed-file detection fails, validation falls back to the full build matrix, gated tests, Talos builds, and package coverage. * Base-package overlays now select artifact references based on branch context, supporting stacked pull requests and release branches. * **Tests** * Added coverage for changed-file detection, rename handling, branch scenarios, and fallback validation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
5 files changed
+271
-29
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user