Files
cozystack/hack/code-changed.sh
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

36 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# Classify a changed-path list for the PR pipeline: prints `true` when at least
# one path can reach the product (Go, charts, images, build inputs, workflows)
# and `false` when every path is documentation or repository metadata.
#
# This is the single source of truth for the docs-only gate: pull-requests.yaml
# `plan` feeds it the merge diff and e2e-fork.yaml `resolve` feeds it the
# base-repo PR file list. A rename must appear as BOTH paths (git diff
# --no-renames, or filename + previous_filename), so a packages/... -> docs/...
# move still reads as code. A blank line reads as code: fail closed.
#
# Non-code: the docs/ tree, Markdown outside packages/, images, LICENSE, GitHub
# and review-bot metadata. Markdown under packages/ stays code: Go controller
# tests read chart READMEs (internal/controller/fluxplunger/hook_contract_test.go
# checks packages/system/flux-plunger/README.md), and those run only when this
# prints `true`. The Bats lane of the `checks` job runs for every path except
# the CI-only tools in this list (cmd/backport-batch, cmd/api-gate), so non-code
# files still get their contract tests; they only skip build and e2e.
# The push `paths` filters in build-main.yaml, build-release.yaml and codeql.yml
# mirror this classifier (CodeQL's pull_request trigger has none: it is
# a required check); hack/code-changed_test.bats keeps them in step.
set -eu
if [ "$#" -ne 1 ] || [ ! -f "$1" ] || [ ! -r "$1" ]; then
echo "usage: code-changed.sh <readable-changed-files>" >&2
exit 2
fi
non_code_pattern='^(docs/|cmd/backport-batch/|cmd/api-gate/|img/|\.gemini/|\.github/ISSUE_TEMPLATE/|\.github/(CODEOWNERS|PULL_REQUEST_TEMPLATE\.md|labels\.yml|renovate\.json)$|\.coderabbit\.yaml$|security-insights\.yml$|LICENSE$)'
# ENVIRON, not -v: -v would expand the backslash escapes in the pattern.
pattern="$non_code_pattern" awk '
!($0 ~ ENVIRON["pattern"] || ($0 ~ /\.md$/ && $0 !~ /^packages\//)) { code = 1 }
END { print (code ? "true" : "false") }
' "$1"