Files
cozystack/.github/workflows/build-release.yaml
T
Marian Koreniuk ceb2063f34 ci: widen the docs-only gate to Markdown, images and repository metadata
The PR pipeline skipped build, Talos and E2E only when every changed path
was under docs/. A pull request that touched README.md, GOVERNANCE.md, an
issue template or LICENSE still built every image, booted a sandbox and
ran the suite, for files nothing in that pipeline reads.

Move the classifier into hack/code-changed.sh, the one source of truth for
both lanes: the in-tree `plan` job feeds it the --no-renames merge diff and
the fork `resolve` job feeds it the base-repo PR file list (filename and
previous_filename, so a packages/… -> docs/… rename still reads as code).
Non-code is the docs/ tree, Markdown outside packages/, img/, LICENSE and
the GitHub and review-bot metadata.

Markdown under packages/ stays code: Go controller tests read chart
READMEs. TestDocs_StateTheTimingsTheBinaryAndTheChartUse checks
packages/system/flux-plunger/README.md and runs only under
make test-controllers, i.e. only when hack/code-changed.sh prints true, so
a README-only PR there would skip the test and turn the next code PR on
main red. The classifier uses awk rather than grep to express that
exception. Other chart READMEs are generated by `make generate`, which
pre-commit re-runs, and contract-tested by hack/*.bats, which the `checks`
job still runs for every path except the two CI-only tools.

The push triggers of build-main, build-release and CodeQL mirror the
classifier so a docs-only merge no longer rebuilds main. They use a
`paths` filter (`**`, one `!` glob per non-code path, then `packages/**.md`)
because only `paths` documents re-including after a negation.
hack/code-changed_test.bats checks that the three filters are equal, that
every `!` glob is non-code, that every re-include is code, and that
CodeQL's pull_request trigger carries no path filter at all: it is a
required check on main.

Over the 200 merged PRs returned by `gh pr list --state merged --limit
200` on 2026-11-18 the gate on main (docs/ plus the two CI-only tools)
skipped 8, the new one 10 (#5168 and #5188 are newly skipped).

Assisted-by: LLM
Signed-off-by: Marian Koreniuk <moriarti@cp.if.ua>
2026-12-02 10:53:49 +01:00

182 lines
8.3 KiB
YAML

name: Build release line
# Publishes the per-line equivalent of what build-main.yaml publishes for main:
# every image tagged with the line's branch name, and the whole packages tree as
# the `cozystack-packages:<branch>` OCI artifact with each image reference
# digest-pinned to the images this run just pushed (`make build-parallel` ->
# packages/core/installer image-packages does the `flux push artifact`).
#
# Why it exists: pull-requests.yaml overlays image refs for every package a PR
# did NOT rebuild, so that e2e and the installer do not test last-release images
# for everything outside the PR's build matrix. That overlay had only
# `cozystack-packages:main` to read, which meant a release-line PR was handed
# MAIN's binaries to run against its own line's charts — a cross-generation mix
# that failed deterministically (see #3437: main's cozystack-controller served an
# aggregated OpenAPI release-1.6's charts could not validate against). With this
# artifact published per line, the overlay reads the PR's own base branch and the
# generations match.
#
# Cost: one full `make build-parallel` per push to a maintained line, i.e. per
# merged backport. That is the price of release-line PRs testing their line's
# tip rather than its last release.
env:
# Same per-CI registry as pull-requests.yaml and build-main.yaml.
REGISTRY: iad.ocir.io/idyksih5sir9/cozystack
on:
push:
# Maintained LINE branches only: `release-<major>.<minor>`. The `+` quantifies
# the preceding character class, and `.` is literal, so this matches
# release-1.6 but NOT the per-release staging branches promote-rc.yaml creates
# (release-1.6.1) nor rc staging branches (release-1.6.0-rc.4) — building
# those would be pure waste, since their images are built by tags.yaml.
branches: ['release-[0-9]+.[0-9]+']
# Mirrors hack/code-changed.sh; hack/code-changed_test.bats keeps them equal.
# `paths`, not `paths-ignore`: Markdown under packages/ is code (Go tests
# read chart READMEs), and only `paths` documents re-including after `!`.
paths:
- '**'
- '!docs/**'
- '!cmd/backport-batch/**'
- '!cmd/api-gate/**'
- '!img/**'
- '!.gemini/**'
- '!.github/ISSUE_TEMPLATE/**'
- '!.github/CODEOWNERS'
- '!.github/PULL_REQUEST_TEMPLATE.md'
- '!.github/labels.yml'
- '!.github/renovate.json'
- '!.coderabbit.yaml'
- '!security-insights.yml'
- '!LICENSE'
- '!**.md'
- 'packages/**.md'
# Run against a line on request. The push trigger above cannot cover the moment
# a line is BORN: cut-prerelease.yaml creates release-X.Y at a commit that is
# already on main, so that push carries no new commits, and GitHub does not run
# a workflow whose `paths`/`paths-ignore` filter finds no changed files. Without
# a dispatch the line would have no `cozystack-packages:<line>` artifact until
# its first cherry-pick merged, and until then pull-requests.yaml's overlay
# would find nothing to pull and leave every package on its committed ref — at
# freeze time, the PREVIOUS release's, which is the cross-generation mix #3437
# fixed. The freeze step dispatches this workflow for the branch it just made.
#
# Also the recovery path when a line build fails or is cancelled: re-run it
# without having to push an empty commit to the line.
workflow_dispatch:
# Per line: a newer push to the same line supersedes an in-flight build, but
# different lines build independently.
concurrency:
group: build-release-${{ github.ref_name }}
cancel-in-progress: true
permissions:
contents: read
jobs:
build-line:
if: github.repository == 'cozystack/cozystack'
name: Build ${{ github.ref_name }} images and packages artifact
runs-on: oracle-vm-24cpu-96gb-x86-64
timeout-minutes: 120
permissions:
contents: read
packages: write
steps:
# workflow_dispatch takes ANY ref, and the "Run workflow" ref selector
# preselects the default branch — which is exactly where the recovery
# advice above, and cut-prerelease.yaml's warning, send an operator. Since
# IMAGE_TAG below is github.ref_name, a dispatch from 'main' spends two
# hours republishing cozystack-packages:main and every main image tag while
# build-main.yaml may be writing the same ones: the 409 tag-collision class
# #2711 fixed. Nothing is mislabeled (the content really is that ref), but
# a runner and a cache generation are gone.
#
# The push trigger is already filtered to release-X.Y; this closes the
# dispatch path to the same set, and keeps holding if that filter is ever
# widened. Anchored at both ends on purpose: unanchored, the per-release
# staging branches (release-1.6.1, release-1.6.0-rc.4) would qualify, and
# those are built by tags.yaml. Fails rather than skips — a skipped job
# reads in the run list like one that produced the artifact.
- name: Refuse a build for a non-line ref
env:
REF_NAME: ${{ github.ref_name }}
REF_TYPE: ${{ github.ref_type }}
run: |
if [ "$REF_TYPE" != "branch" ] \
|| ! printf '%s' "$REF_NAME" | grep -qE '^release-[0-9]+\.[0-9]+$'; then
echo "::error::Refusing to build '$REF_NAME' ($REF_TYPE). This workflow publishes cozystack-packages:<ref> and every image tagged <ref>, so it may only run for a maintained release line (release-X.Y)."
echo "::error::Pick the release-X.Y branch in the 'Run workflow' ref selector. To build main, use build-main.yaml."
exit 1
fi
echo "Building line '$REF_NAME'."
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
fetch-tags: true
# This workflow holds packages:write and an OCIR push token; it never
# pushes git, so don't leave the checkout's GITHUB_TOKEN in .git/config
# where a later build step could read it.
persist-credentials: false
# Ephemeral runners lack the flux CLI the installer's image-packages step
# shells out to.
- name: Set up flux
uses: fluxcd/flux2/action@04acaec6161ac4fb1a82ffafa88901c03271d34f # v2.8.6
with:
version: "2.8.6"
- name: Set up Docker config
run: |
if [ -d ~/.docker ]; then
cp -r ~/.docker "${{ runner.temp }}/.docker"
fi
- name: Login to OCIR
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.OCIR_USER }}
password: ${{ secrets.OCIR_TOKEN }}
registry: iad.ocir.io
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
# Same isolated buildkit as build-main.yaml, so a line build never contends
# with PR builds on the shared embedded builder.
- name: Set up Buildx (docker-container driver)
id: buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
driver: docker-container
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
- name: Build line images and publish the packages artifact
run: make build-parallel
env:
DOCKER_CONFIG: ${{ runner.temp }}/.docker
BUILDER: ${{ steps.buildx.outputs.name }}
# amd64 only, as in build-main.yaml.
PLATFORM: linux/amd64
# The line keeps a mode=max cache of its own, which its rc builds in
# tags.yaml import too: main's cache (:buildcache, written only by
# build-main.yaml) misses more with every Dockerfile main changes after
# the line branched. The concurrency group above runs one build per
# line, so this is the only writer of the line's ref, and main's ref is
# only read.
CACHE_TAG: buildcache-${{ github.ref_name }}
CACHE_FROM_TAGS: buildcache-${{ github.ref_name }} buildcache
WRITE_CACHE: '1'
# Floating per-line handle: images and the packages artifact both land
# under the branch name (e.g. :release-1.6). Versioned and :latest tags
# belong to releases (tags.yaml / finalize), never to this workflow.
IMAGE_TAG: ${{ github.ref_name }}
PUBLISH_VERSIONED: '0'
PUBLISH_FLOATING: '0'