Skip to content

Feat: Add linting reusable workflow - #34

Merged
tykeal merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:feat/linting-workflow
Sep 21, 2026
Merged

tykeal merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:feat/linting-workflow

Conversation

@ModeSevenIndustrialSolutions

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds linting.yaml, a reusable workflow that runs pre-commit hooks with prek, standalone from pre-commit.ci. It supersedes compose-repo-linting.yaml in lfit/releng-reusable-workflows.

It serves two populations. Repositories with no pre-commit.ci — every Gerrit-mirrored project among them — need something to run their hooks in CI. Repositories that do have it still need the hooks it cannot run: its sandbox blocks network access at scan time and caps environment size, so hooks like gha-workflow-linter and aislop end up under ci.skip and never run in CI at all.

Pinned to the commit behind standalone-linting-action v0.4.1.

The default runs everything

With no inputs the workflow runs every hook in the configuration. ci_skipped: true selects the ci.skip set instead; hooks names an explicit subset.

An earlier revision had this the other way round. @tykeal caught it in review:

if there is no ci.skip section of the configuration file, then linting is just skipped … Gerrit based repositories cannot use pre-commit.ci

The reasoning that settles it is the direction each default fails in:

Default Misconfiguration Result
ci.skip Gerrit repo, no ci.skip green, nothing linted — silent
run everything repo forgets to narrow duplicate work — visible, never unsafe

Shape

plan (single job)  ->  lint (matrix, one job per task)

Selection

Given Runs Jobs
nothing every hook in the resolved configuration 1
ci_skipped: true the ci.skip set one per hook
hooks: 'a b' those hooks one per hook
config_path/config_url every hook in that configuration 1
plan (JSON) the tasks the array describes one per task
no configuration anywhere nothing — skips green 0

skip_hooks sits across all of these and is the equivalent of the legacy pre_commit_skips. The executor applies it, not the plan job — prek matches an exclusion against a hook's alias as well as its id, and reimplementing that here would give two different answers.

Migration from compose-repo-linting

Wholesale, and usually with no with: block at all:

compose-repo-linting linting
GERRIT_* (nine, required) none; the workflow checks out for itself
pre_commit_skips skip_hooks, the same comma/space list
pipx run pre-commit prek at a pinned version, via uvx
separate actionlint job actionlint runs as a hook like any other
runs everything not skipped the same, and the default

The governing invariant

A green check must mean "linted, nothing wrong" — never "could not tell".

That rule drove most of the review, because the same failure kept reappearing by different routes. Each is closed with a regression fixture:

Route Would have reported green having run nothing
Pre-filter regex ci: {"skip": [...]} and two other YAML spellings
Pre-filter escapes "\x73kip" decodes to skip; on a fork PR the config is attacker-controlled
Pre-filter exit status grep exits 2 for "could not read"; if ! folded that into "no match"
Org fallback status A rate limit, 500 or DNS failure read as "no configuration"
Org fallback 404 GitHub returns 404 for anything a token cannot see, so a private .github looked identical to none
Hook id as an option --help reaches prek, which exits 0
ci.skip undefined ids Filtered away, so a typo ran nothing — or half the job, silently
Config symlinks Escaping, dangling, and resolving-to-a-non-file
path_prefix with no config Fell through to the org fallback and linted a configuration never named
Duplicate keys JSON and YAML silently keep the last value
Type coercion "ci_skipped": "false" truthy; "hooks": [] folding into "run everything"
Empty strings {"config_path": ""} read as omitted, then ran every hook
Unhardened runner harden-runner returns early and silent on several runner shapes
sys.path hijack A fork committing yaml.py could forge has_work=false before the resolver ran a line

Hook stages

prek runs pre-commit hooks, and manual ones when named. Measured with one hook per stage, the other nine exit 0 having printed nothing — so a repository declaring gitlint gets a green check that never touched it.

The resolver cannot fix that; the executor decides what it ran, tracked as lfreleng-actions/standalone-linting-action#156 with lfreleng-actions/standalone-linting-action#143 behind it. It can refuse to let it pass unmentioned, so the plan job now warns and names the hooks. docs/linting.md states the limitation plainly.

Security

  • Refuses pull_request_target; token export is an allow-list, so unknown events run unprivileged rather than trusted by default
  • The resolver runs isolated — python -I - under uv --no-config
  • No expression interpolation in run: blocks; everything reaches a shell through env
  • Path containment before first read — both [ -f ] and grep follow symlinks
  • Download hygiene — HTTPS only, enforced per redirect hop; 1 MiB, a wall-clock deadline, and a 300s budget
  • config_url redacted in the job summary — the grammar admits userinfo and query strings, which is how a private configuration arrives; the executor gets the URL whole, the summary gets origin and path
  • No planning/linting drift — the plan job hashes every remote configuration and the lint job verifies the same digest

Runner

runs_on defaults to ubuntu-latest. Not ubuntu-slim: harden-runner detects it, logs a note, and returns without installing its agent, while RUNNER_OS still reads Linux. So neither job trusts the label — each tests for the agent itself.

Condition block audit
GitHub-hosted, agent running proceeds proceeds
GitHub-hosted, no agent fails warns
Self-hosted, or environment unknown fails warns
Not Linux fails fails

Tests

Two suites, both extracting their subject from the workflow so the fixtures exercise shipped code rather than a copy:

  • tests/test-lint-plan.sh — 171 assertions over the Python resolver
  • tests/test-locate-rules.sh — 87 assertions over the shell rules that decide whether the resolver runs at all

Every guard added during review was mutation-tested; several fixtures were rewritten after mutation showed them passing for the wrong reason.

The most recent of those: in plan mode primary_problem defers rather than exiting, so a repository carrying prek.toml beside a YAML file left a readable candidate behind, and the assignment took it. That set primary, which the resolver reads in preference to PRIMARY_ERROR, so an entry relying on the primary was linted against the file prek ignores — the outcome the prek.toml refusal exists to prevent. The assignment now skips a deferred error, as the checks after it already did.

Files

  • .github/workflows/linting.yaml — the reusable
  • .github/workflows/linting-action.yaml — self-test caller (three jobs: ci_skipped, an explicit hooks, and the no-input default against a one-hook fixture, since pre-commit.ci already lints this repository in full)
  • tests/resources/minimal-lint-config.yaml — that fixture
  • examples/linting/github.yaml — consumer caller
  • docs/linting.md — full reference, security model, migration notes
  • tests/test-lint-plan.sh, tests/test-locate-rules.sh + pre-commit hooks
  • README section; actionlint and zizmor entries for the new example

Validation

  • actionlint — clean
  • prek run --all-files — all hooks pass
  • 171 + 87 fixtures pass
  • zizmor --persona=auditor — clean. main has since adopted GitHub's self-repository form ($/), so the new caller uses it too. actionlint still rejects the form as a malformed reusable-workflow reference, so .github/actionlint.yaml carries the matching path-scoped ignore, following the convention main established: one pattern per called workflow, not a blanket $/ wildcard, so a mistyped sibling path is still reported.

Follow-up

Closes the dangling reference tracked by lfreleng-actions/standalone-linting-action#142.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions requested review from a team and a balanced review from Copilot August 20, 2026 14:10

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings August 20, 2026 14:17

This comment was marked as resolved.

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings August 20, 2026 14:37

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings August 20, 2026 14:46
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions force-pushed the feat/linting-workflow branch 2 times, most recently from f212af4 to ddc1f1f Compare August 20, 2026 14:48

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings August 20, 2026 14:53

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings August 20, 2026 14:59

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings August 20, 2026 15:14

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings August 20, 2026 15:24
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions force-pushed the feat/linting-workflow branch 2 times, most recently from 97e1509 to 41a9074 Compare August 20, 2026 15:30

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

An organisation ruleset will mandate this estate-wide, so the common
case must cost close to nothing and must never block a merge. It
supersedes compose-repo-linting.yaml in lfit/releng-reusable-workflows.

With no inputs the workflow runs EVERY hook in the configuration.
'ci_skipped: true' selects the hooks a repository lists under
'ci.skip' instead -- the hooks pre-commit.ci cannot run, because its
sandbox blocks network access at scan time and caps environment size.

An earlier revision had that the other way round, and the direction
each default fails in settles it. Defaulting to ci.skip means a
Gerrit-mirrored repository, which cannot use pre-commit.ci and so
carries no ci.skip, reports green having linted nothing. Defaulting
to everything means a repository that forgets to narrow does
duplicate work: visible, and never unsafe.

Two jobs. The plan job locates a configuration, resolves the task
set, and publishes a matrix; the lint job runs one task per parallel
job through standalone-linting-action.

Abort fast when there is nothing to do. A sparse checkout fetches the
configuration file alone, and no tasks leaves has_work false so the
matrix never instantiates. A grep pre-filter looks for a skip key
before any tooling installs, in ci_skipped mode alone: under the
default a configuration with no ci.skip still has a full run's worth
of work, so aborting on its absence would be the silent green the
default exists to prevent.

Fall back to linting/.pre-commit-config.yaml in the organisation's
'.github' repository when a repository carries no configuration, so
an estate keeps one central policy rather than a copy everywhere.

Beyond the default, accept explicit hook ids, an alternate local
configuration, a remote HTTPS one, or a JSON plan combining all of
them as parallel tasks. skip_hooks crosses all of them, excluding
hooks from whichever set the mode selected, and is the equivalent of
the legacy pre_commit_skips.

The workflow runs repository-defined tools against repository
content, including content from forks, so treat the configuration as
attacker-controlled: refuse pull_request_target outright, keep every
variable out of run: blocks and behind env, confine paths to the
workspace with realpath, require HTTPS with bounded size, time and
redirects, and cap the fan-out at 50 tasks. The plan job hashes every
remote configuration and the lint job verifies the same digest, so
what runs cannot differ from what the plan validated.

Those guarantees rest on harden-runner, which supports fewer runners
than a Linux test implies: it returns without installing its agent on
ubuntu-slim, in containers, on community-tier ARM64 and on bare
self-hosted runners, printing a note rather than failing, while
RUNNER_OS still reads Linux. Default to ubuntu-latest and have both
jobs test for the agent itself, an observed fact no new runner image
can walk past. A missing agent fails a 'block' run, where the caller
asked for enforcement and is not getting it, and warns under 'audit',
which records traffic and blocks none of it.

Pinned to the commit behind standalone-linting-action v0.4.1, which
matches an exclusion against a hook's alias in every mode, so
skip_hooks needs no caveat about which mode is in play. The docs now
also state which hook stages a run reaches: prek runs pre-commit
hooks, and manual ones when named, so a commit-msg hook such as
gitlint never runs here and a green check must not be read as
covering it.

A 404 from the organisation fallback lookup no longer means the
fallback is absent on its own. GitHub answers 404 rather than 403
for anything a token cannot see, so a private '.github' repository
returns 404 for a file sitting right there, and reading that as
'nothing to lint' is the silent green this workflow refuses. The
repository itself is asked, and a readable one makes the absence a
fact.

A 404 on the repository cannot be resolved, though: an organisation
with no '.github' answers exactly the same, and its documented
outcome is a green skip. So that case warns and carries on, and
org_fallback_required turns it into a failure for an organisation
that knows its fallback is there. Anything else remains an error.

prek_version joins the inputs checked for control characters before
their pattern runs. 'grep -qE ^...$' anchors per line, so a value
spelling '0.4.14<newline>junk' matched on its first line and passed,
carrying the remainder to the executor and its cache key.

The job summary redacts config_url. The accepted grammar admits
userinfo and a query string -- a presigned URL, or an embedded token,
being how a private configuration commonly arrives -- and the summary
is readable by anyone who can see the run. The executor still gets
the URL whole; the summary gets an origin, a path, and a note naming
each part dropped.

A configuration declaring hooks at stages a run never reaches now
says so. prek passes over nine of the eleven stages without output at
exit 0, so a repository naming gitlint gets a green check that never
touched it, and the run-all default reports 'all hooks' while doing
so. The resolver cannot fix that -- the executor decides what it ran,
tracked as standalone-linting-action#156 -- but it can refuse to let
it pass unmentioned, so it warns and names the hooks.

The self-test caller gains a third job. The two existing ones both
resolve to a non-empty matrix.hooks, leaving the DEFAULT path, and
the GitHub expression that drives it, covered only by fixtures that
inspect the JSON the expression reads. A minimal fixture
configuration runs it end to end for one trivial hook rather than
linting this repository a second time.

An unmonitored runner fails on an UNTRUSTED event whatever the
egress policy. Audit mode records rather than blocks, so on a trusted
event an absent agent costs telemetry; where the hooks were written
by whoever opened the pull request, it costs the only record that
they ran at all, and a self-hosted runner carries their work into the
next job. Withholding the token does not cover that, protecting the
token rather than the host.

The planner refuses credentials in a URL. The grammar admits
'user:pass@host', but urllib leaves the pair in Request.host and
builds no Authorization header, so the request goes to a host by that
literal name -- such a URL could never have worked at plan time. A
presigned query string stays supported, and the redirect refusal now
redacts through the same helper the summary uses, since a target the
server chooses inherits whatever the caller's URL carried.

The stage check gained the three things it was missing: the runnable
set now depends on how the task invokes prek, since run-all leaves
manual hooks alone while naming one reaches it; 'default_stages'
supplies the stages of a hook that declares none, which a
configuration pinning everything to commit-msg depends on; and plan
entries are checked too, having been the one mode left quiet. Hook
ids and stage names are escaped before reaching the annotation --
they come from the configuration, which on a fork pull request is
written by the person opening it, and a newline would close the
::warning:: line and open the next as a fresh workflow command.

harden-runner moves to v2.21.1, matching the other seven pins in
this repository.

The stage check is PARTIAL, and now says so. A remote hook takes its
stages from its own repository's manifest, which the plan job does
not fetch -- so this repository's own 'gitlint' entry, which is a
bare id, resolves to commit-msg through a file the check never sees.
Silence from it means 'the configuration does not say', not 'every
hook runs', and both the annotation and the documentation state that.
An empty 'stages: []' falls back to default_stages, as pre-commit's
own merge does, rather than reading as unrestricted.

Both arguments of primary_problem go through single_line. A summary
can carry a readlink result from a symlink in the checkout, written
on a fork pull request by whoever opened it, and a newline there
would close the annotation and open the next line as a fresh
workflow command. The deferred arm already did this; the fatal arm
did not.

The caller example gains a push trigger. Gerrit mirrors never see a
pull request, and they are the population with no pre-commit.ci, so
copying a pull_request-only example to one produced no lint check at
all -- against a migration path that names them first.

Both spellings of the configuration filename are discovered. prek
finds '.pre-commit-config.yaml' and '.pre-commit-config.yml' alike,
and probing the first alone left a repository using the second
looking like one with no configuration -- which falls through to the
organisation fallback, or to a green skip. The sparse checkout
fetches both and the candidate resolution prefers '.yaml', the same
order prek uses.

fail() sanitises its message. load_config hands PyYAML's diagnostic
straight to it, and that quotes the offending source across several
lines, from a file this job did not write -- so raw, every line after
the first left the annotation.

An explicitly empty 'default_stages: []' is a declared empty set
rather than an absent key: such a hook runs at no stage at all, and
collapsing the two read it as one that always runs.

The fixture suite runs when this repository's own configuration
changes. It reads that file as its default fixture and asserts hook
ids from it, so a rename could invalidate the fixtures without the
suite noticing.

Plan entries validate the configuration's shape before the stage
check reads it. That check walks 'repos[].hooks[]' expecting
mappings, so 'repos: [just-a-string]' raised a bare AttributeError
from inside it rather than the resolver's own diagnosis. The scalar
path already validated first.

The zizmor placeholder ignores move from github.yaml:78 to :90. They
are line-scoped by design, so that an edit above a placeholder makes
the finding reappear rather than a file-wide ignore hiding a real
one -- and adding the push trigger to the example did exactly that.

skip_hooks forwarding gains end-to-end cover. That input travels
from the caller, through the plan job, to the executor step, and no
resolver fixture can reach it -- the resolver never reads it and the
executor applies it. The run-all self-test fixture gains a second
hook that always fails and names it in skip_hooks, so the job passes
only while the forwarding works.

A prek.toml configuration is refused rather than misread. prek
prefers its own file over both YAML spellings, so meeting one either
way was wrong: alone it read as a repository with no configuration
and skipped green, and beside a YAML file this workflow passed the
YAML to '--config' and linted what prek would have ignored. The file
is fetched so the locate step can see it, and the run stops with a
diagnosis naming both alternatives.

That refusal now holds in plan mode too. primary_problem returns
there rather than exiting, so a repository carrying prek.toml beside
a YAML file left a readable candidate behind and the assignment took
it, setting 'primary' -- which the resolver reads in preference to
PRIMARY_ERROR. An entry relying on the primary was then linted
against the file prek ignores, the very outcome the refusal exists
to prevent. The assignment now skips a deferred error, as the two
checks after it already did.

A repository entry without a 'repo' key is refused. prek rejects
the whole configuration for it -- 'missing field `repo`' -- while
the resolver walked past, found no hook ids, and read the result as
a deliberately empty configuration: zero tasks and a green check
over a file prek would not have loaded.

Two fixture suites extract their subjects from the workflow rather
than copying them, so they exercise the code that runs in CI:
tests/test-lint-plan.sh covers the resolver, and
tests/test-locate-rules.sh the shell rules that decide whether the
resolver runs at all. Over half the cases are rejections.

actionlint and zizmor are both clean. The caller uses GitHub's
self-repository form ('$/') rather than a local path, matching the
spelling main adopted after this branch was written, and
.github/actionlint.yaml gains the path-scoped ignore that form still
needs: actionlint does not know it yet and rejects it as malformed.
One pattern covers all three jobs, because it names the workflow
being called rather than the call site, so a mistyped sibling path
is still reported.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Unresolved functional and security defects could prevent fallback linting or allow green checks without executing intended work.

Review effort: Balanced
Findings: None

Resolved since last review (1)

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants