Skip to content

Read local Azure Pipelines templates, Cirrus CI, and make's text functions - #379

Open
leftibot wants to merge 3 commits into
cpp-best-practices:mainfrom
leftibot:ci-leftovers
Open

leftibot wants to merge 3 commits into
cpp-best-practices:mainfrom
leftibot:ci-leftovers

Conversation

@leftibot

Copy link
Copy Markdown
Collaborator

These are the CI-reading gaps left over from #376 and #377: local Azure Pipelines templates, Cirrus CI, and make text functions. They are three commits, one per reader.

Make: addprefix, addsuffix, subst, patsubst, and rules they name

nvm names a rule for each shell it tests: SHELL_TARGETS := $(addprefix test-,$(SHELLS)), then $(SHELL_TARGETS):. Its CI runs make test-bash, which read as "no rule of the makefile builds it".

  • Text functions: the four join filter, filter-out, findstring and strip, evaluated where their arguments are known.
  • Targets and prerequisites: a reference in either is expanded with the variables set so far, as make does when it reads the rule. A word still holding a reference (a $(foreach)) is kept as written, as before.
  • Why prerequisites too: the corpus caught this. Expanding only targets broke pyenv: its test-docker: $(TEST_UNIT_DOCKER_PREFIX) had matched the rule $(TEST_UNIT_DOCKER_PREFIX): only because both were left as written.

Azure Pipelines: the repository's own templates

The ansible collections and dotnet/command-line-api describe their CI in local templates. Each was an unknown ("templates are not read").

  • Where templates are read: a step, job, stage or extends template is read where it is named. Its path is relative to the file that names it, or to the root after /.
  • Parameters: they take the values passed, over their defaults. The values are expanded where they are passed, as Azure does.
  • Template expressions: a new evaluator, ci/azure_expressions.py, reuses the GitHub expression parser for the shared syntax. It handles:
    • ${{ parameters.x }};
    • ${{ if }}, ${{ elseif }} and ${{ else }};
    • ${{ each }};
    • Azure's functions (eq, format, coalesce, length, replace, …).
  • Conditions on run variables: a condition on a predefined variable that depends on the run (command-line-api's in(variables['Build.Reason'], 'PullRequest')) can't be decided. Its branch is followed as one the pipeline may take, as the Make reader follows recipes the environment decides.
  • Other unset variables: a variable not set where the template is expanded (a matrix leg's _BuildConfig) is empty, as Azure evaluates it.
  • Still unknown, each with its reason:
    • a template in another repository (x.yml@tools);
    • a missing template;
    • a cycle;
    • nesting past Azure's limit of 100 levels, tested at the limit;
    • an expression the evaluator doesn't know (counter, ${{ insert }}).

Cirrus CI

Cirrus CI was only scanned heuristically, so clj-kondo's macOS build-and-test task made its CI questions unknown. .cirrus.yml is now read as its tasks:

  • Tasks: task: and <name>_task: (a repeated task: key is read each time), plus docker builders. Each leg of a matrix: is a task of its own.
  • Repeated keys: they need the top level as ordered pairs, so CiProvider gains parse, and a new yaml_support.load_pairs keeps every pair.
  • Instances: the instance named gives the OS and image:
    • container runs on Linux, macos_instance on macOS, windows_container on Windows, freebsd_instance on FreeBSD;
    • compute_engine_instance runs on its platform;
    • others, such as persistent_worker, run on an unknown OS.
  • Scripts: they run under set -e and set -o pipefail on Unix, which is how Cirrus's agent writes them (internal/agent/executor/cmd.go), and in cmd on Windows.
  • Advisory scripts: background scripts, and the scripts of a task that allow_failures, can't fail it.

Corpus

Compared against main's recording:

  • No status changes in any project, in either the allow-unknown or the strict results.
  • 12 unknowns are gone, and nothing new is unread:
    • ansible's two templates, now 118 jobs instead of 2;
    • command-line-api's jobs template, now 8 jobs instead of 0, with its conditional Debug leg;
    • clj-kondo's heuristic Cirrus scan;
    • nvm's four test-<shell> targets;
    • neovim's three doc targets;
    • one of dune's targets.
  • What's still unread there: neovim's targets now reach recipes that run $(NVIM_PRG), a variable nothing sets. Those two recipes are reported in place of the three targets.
  • Message-only changes elsewhere: the list of providers searched now places Cirrus CI among those that are read.

Tests

  • Each reader has its own tests: tests/test_azure_expressions.py, the template tests in tests/test_azure_pipelines.py, tests/test_cirrus_ci.py, the Make ones in tests/test_expansion.py, and a limit test for templates.
  • Mutants: every branch of the new code was checked against a mutant. Every surviving mutant got a test or, where the mutated code was redundant, a simplification.
  • Shared helper: tests that write the same command for every CI provider now write a Cirrus task.

Gates

pytest, ruff, ruff format, mypy, lizard, coverage, jscpd and strict self-validation: all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

leftibot and others added 3 commits November 24, 2026 21:32
…hey name

nvm names a rule for each shell it tests, `SHELL_TARGETS := $(addprefix test-,$(SHELLS))` and
`$(SHELL_TARGETS):`, and its CI runs `make test-bash`. The Make reader left the targets as
written, so each read as "no rule of the makefile builds it" (seen in cpp-best-practices#376's corpus run).

- addprefix, addsuffix, subst and patsubst join filter, filter-out, findstring and strip as
  text functions evaluated where their arguments are known.
- A rule's targets and prerequisites that hold a reference are expanded with the variables set
  so far, as make expands them when it reads the rule; each word is a rule of its own. One left
  with a reference unexpanded (a `$(foreach)`) is kept as written, as before. Expanding
  prerequisites too keeps pyenv's `test-docker: $(TEST_UNIT_DOCKER_PREFIX)` pointing at the rule
  `$(TEST_UNIT_DOCKER_PREFIX):` now names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
The ansible collections and dotnet/command-line-api describe their CI in local templates
(`.azure-pipelines/templates/matrix.yml`, `eng/pipelines/*.yml`). The reader made each an
unknown ("templates are not read"), so none of their jobs or commands were seen.

- A step, job, stage or `extends` template of the repository is read where it is named. Its
  path is relative to the file that names it, or to the root after `/`. Its jobs are named
  after the pipeline, and its facts point at the template.
- Its parameters take the values passed, over their declared defaults (a list of name/default
  entries or a mapping).
- Template expressions are evaluated by a new module, `ci/azure_expressions`, which reuses
  the GitHub expression parser for the shared syntax:
  - `${{ parameters.x }}` and an `each` loop's variable take their values;
  - `${{ if }}`, `${{ elseif }}` and `${{ else }}` insert the branch that holds;
  - `${{ each }}` inserts its body for each item;
  - Azure's functions are evaluated (`eq`, `format`, `coalesce`, `length`, `replace`, …),
    with string comparisons ignoring case;
  - `${{ variables.x }}` is left for the job's variables where the scope does not set it;
  - a condition on a variable the pipeline sets as it runs (command-line-api's
    `${{ if in(variables['Build.Reason'], 'PullRequest') }}`) cannot be decided, so its branch
    is followed as one the pipeline may take, as the Make reader follows a recipe the environment
    decides; the branches after it may be taken too, until one surely is. That holds for the
    predefined variables that depend on the run (`Build.*`, `System.*`, `Agent.*`, …).
    Another variable not set where the template is expanded (a matrix leg's `_BuildConfig`)
    is empty there, as Azure evaluates it.
- The parameters a pipeline passes are expanded where it passes them, as Azure does, so a job
  matrix with a conditional leg reaches the template expanded.
- Still unknown, each with its reason: a template of another repository (`x.yml@tools`), a
  missing one, a cycle, nesting past Azure's limit of 100 levels, and an expression the
  evaluator does not know (`counter`, runtime values, `${{ insert }}`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
Cirrus CI was detected but only scanned heuristically, so clj-kondo's macOS build and test task
made every CI question about it unknown.

A `.cirrus.yml` is now read as its tasks:
- `task:` and `<name>_task:`; a repeated `task:` key is each read, through a new
  `yaml_support.load_pairs` that keeps the top level's pairs in order. A provider now says how
  its text is parsed (`CiProvider.parse`).
- `docker_builder:` and `<name>_docker_builder:`.
- Each leg of a task's `matrix:` is a task of its own.
- The instance a task names, or the top's, gives its OS and its container's image: containers
  run on Linux, `macos_instance` on macOS, `windows_container` on Windows,
  `freebsd_instance` on FreeBSD, and `compute_engine_instance` and docker builders on their
  `platform`; others, such as `persistent_worker`, run on an unknown OS.
- Scripts run in order with the top's and the task's `env:`:
  - on Unix under `set -e` and `set -o pipefail`, which is how Cirrus's agent writes the
    script;
  - on Windows in cmd.
- A background script, or any script of a task that `allow_failures`, cannot fail the task.

Tests that write the same command for every provider now write a Cirrus task. The snapshots
list Cirrus CI among the providers that are read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.12195% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.44%. Comparing base (79c1e97) to head (58793c7).

Files with missing lines Patch % Lines
project_validator/ci/azure_expressions.py 95.29% 8 Missing ⚠️
project_validator/yaml_support.py 60.00% 6 Missing ⚠️
project_validator/ci/cirrus.py 97.22% 2 Missing ⚠️
project_validator/build_systems/make.py 96.55% 1 Missing ⚠️
project_validator/ci/azure_pipelines.py 98.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #379      +/-   ##
==========================================
- Coverage   99.50%   99.44%   -0.07%     
==========================================
  Files         320      322       +2     
  Lines       21149    21495     +346     
  Branches     2540     2610      +70     
==========================================
+ Hits        21045    21376     +331     
- Misses        104      119      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant