Skip to content

ci: Port the flatpak-builder-lint action to Python (GEN-005) - #2702

Merged
zackees merged 3 commits into
masterfrom
infra/2700-flatpak-lint-python
Oct 27, 2026
Merged

zackees merged 3 commits into
masterfrom
infra/2700-flatpak-lint-python

Conversation

@zackees

@zackees zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member

What this does

.github/actions/flatpak-builder-lint/action.yaml was one of the GEN-005 approved exceptions: CI logic living in shell. It carried two inline run: blocks — an artifact-type guard, and the flatpak-builder-lint call with a two-stage jq pipeline that turns the linter's JSON into ::warning::/::error:: annotations.

Both are ci/flatpak_builder_lint.py now (guard, lint subcommands, stdlib only, #!/usr/bin/env -S uv run --script), the action calls it as uv run --no-project, and the path's [[exceptions]] block leaves ci.toml. The flatpak-build job in build-project.yaml — the action's only caller, three steps: manifest, appstream, builddir, repo — installs astral-sh/setup-uv before the action, and a composite uses: runs on the runner, so uv is available.

RED

9e34df047 adds ci/test_flatpak_builder_lint.py, which fails on master — the module does not exist and the action still carries inline shell:

$ uv run --no-project python -m unittest ci/test_flatpak_builder_lint.py
AssertionError: ci/flatpak_builder_lint.py is missing: the action still runs shell
Ran 10 tests — FAILED (failures=10)

GREEN

f433806e0 (the branch tip b05435373, amended to carry the test's own argument expectation — the tool path is argv[0]) is the port.

$ uv run --no-project python -m unittest ci/test_flatpak_builder_lint.py
Ran 10 tests ... OK
$ cd ci && uv run --no-project python -m unittest test_flatpak_builder_lint test_uv_run test_ci_toml
Ran 56 tests ... OK
$ uvx [email protected] check ci/flatpak_builder_lint.py ci/test_flatpak_builder_lint.py
All checks passed!   (ruff format is not run here; the repo forbids it)

ci-lint precheck (pinned ci.yml@a1917ce):

master 1369daf30 this branch
violations 11 11
approved exceptions 485 483
needs_review 10 10

No GEN-005 finding for .github/actions/flatpak-builder-lint/action.yaml remains and nothing new appeared.

Differential run — old block vs module, same fixtures

The old run: block was extracted verbatim from master, substituted with builddir/appstream and run under bash -eo pipefail against a stub flatpak-builder-lint that prints a fixed body and exits with a fixed code; the module ran on the same fixture in the same directory:

artifact fixture old new
builddir {"warnings":["unused-key","old-runtime"],"errors":["missing-icon"]} exit 1, 3 annotations exit 1, 3 annotations (suffix differs, below)
repo {"warnings":[],"errors":[]} exit 0, no output identical
manifest {"errors":[]} exit 0, no output identical
appstream body, exit 0 body printed, exit 0 identical
appstream body, exit 1 body + ::error::Flatpak appstream info is not valid, exit 1 identical
builddir empty body, exit 3 ::error::Error while running flatpak-builder-lint, exit 2 identical

The one difference is a defect in the old block, deliberately fixed. It set template=" found in the Flatpak <artifact>" but interpolated ${template} inside a single-quoted jq program, so jq printed the literal text ${template} — every annotation ended unused-key${template} instead of unused-key found in the Flatpak builddir (jq interpolates with \(…), not ${…}). The module emits the suffix the block's own comment describes; ci/test_flatpak_builder_lint.py pins the exact lines.

Two smaller, documented divergences, both in the fail-safe direction: a non-JSON body yields no annotations instead of a jq parse error under -eo pipefail (the real tool always prints JSON), and a warnings/errors value that is not a list is skipped, matching the try the original filter wrapped around map.

Not verified here

The flatpak lane is workflow_dispatch-only, so PR CI does not execute it; the evidence above is the module test plus the differential run, not a green flatpak build. The action's step semantics (arguments, annotations, exit codes) are unchanged apart from the suffix fix.

Fixes #2700. Refs #962 (closed tracker; this is one of the remaining GEN-005 exceptions).

RED on master: ci/flatpak_builder_lint.py does not exist and
.github/actions/flatpak-builder-lint/action.yaml still carries two
inline run: blocks (artifact guard, lint + jq annotation pipeline).

    uv run --no-project python -m unittest ci/test_flatpak_builder_lint.py
    AssertionError: ci/flatpak_builder_lint.py is missing: the action still runs shell
    Ran 10 tests -- FAILED (failures=10)
The action's two inline run: blocks (artifact guard; flatpak-builder-lint
call plus the two-stage jq annotation pipeline) are ci/flatpak_builder_lint.py
now, invoked as `uv run --no-project`, and the path's GEN-005 exception
block leaves ci.toml.

    uv run --no-project python -m unittest ci/test_flatpak_builder_lint.py
    Ran 10 tests ... OK

ci-lint precheck: 11 violation(s), 483 approved exception(s), 10 needs_review
(was 485 exceptions; GEN-005 245 -> 243, no new finding).

@zackees zackees left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed the port against the two inline run: blocks it replaces. Behaviour matches, and I checked the edges that differ:

  • lint inherits the step's working-directory (cwd=None), so --path stays relative to it as the shell's did.
  • The empty-body-with-non-zero-exit case still exits 2 before the appstream branch, so a broken tool is not misreported as invalid appstream.
  • Tool stderr still reaches the job log, and the return code is the tool's except for the two error paths (2), which is the shell's contract.
  • guard is now an exact match on the four kinds. The old =~ builddir|repo|manifest|appstream was unanchored, so builddirx used to pass; rejecting it is the intent and no caller passes anything but the four.

Tests: uv run --no-project python -m unittest ci/test_flatpak_builder_lint.py → 10 tests OK, and ci/test_*.py discovery in ci/local_gate.py picks the file up. RED first (test(ci): pin ...) then the implementation, and the ci.toml GEN-005 exception for the action path is gone, so the path leaves the baseline.

I pushed one fixup commit (da3bbb5) for two things the port needed:

  1. publish.yaml had no uv. flatpak-publish runs in ghcr.io/flathub-infra/flatpak-github-actions:freedesktop-26.08 and the module docstring's claim that "the flatpak job that calls the action sets uv up before it" only holds for build-project.yaml. That job (gated on github.repository_owner == 'obsproject') calls the action five times with no setup-uv, so it would fail with uv: command not found once it runs. Added the same pinned astral-sh/setup-uv@bec219d step its sibling flatpak jobs use. Its other four callers (flatpak-build, flatpak-compiler-consumer) already set uv up before their first lint step.
  2. A SyntaxWarning on every run. The docstring was not raw, so \( was an invalid escape sequence and printed SyntaxWarning before the linter did anything. It is a raw docstring now, and its list of deliberate differences says three, not two.

One thing worth knowing for later, not a defect here: ci/flatpak_pruned_build_probe.py:140 still invokes flatpak-builder-lint directly rather than through this module. It is Python and outside GEN-005's business, so I left it alone.

…arning

The action is a ci/ Python module now (GEN-005, #2700), so the
flatpak-publish job in publish.yaml needs setup-uv before it calls the
action. Its sibling jobs in build-project.yaml already do; this job has
no uv step, so the action would fail there with 'uv: command not found'
(Runner: ghcr.io/flathub-infra/flatpak-github-actions).

The module docstring is raw now: '\(' was an invalid escape sequence, so
every run printed a SyntaxWarning before the linter ever ran. Its list of
deliberate differences also says three, not two.
@zackees
zackees force-pushed the infra/2700-flatpak-lint-python branch from da3bbb5 to 66e4fcc Compare October 27, 2026 22:12
@zackees
zackees added this pull request to the merge queue Oct 27, 2026
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Amended the fixup (66e4fcc): ci/test_ci_toml.py requires every astral-sh/setup-uv step in a workflow to carry save-cache: ${{ github.ref == 'refs/heads/master' }}, which my first version (da3bbb5) left off. Format 🔍 / checks caught it; the amended head passes it along with the rest of PR CI (31 checks, 0 failed), so I queued the PR.

@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Regression check on master, from the Flatpak lane in run 40595018476 (job 122510595479): the lane is red on this change, and it is my fault as much as the author's — I reviewed and queued it.

Run uv run --no-project "/home/runner/work/obs-studio/obs-studio/ci/flatpak_builder_lint.py" guard --artifact 'manifest'
error: Failed to spawn: /home/runner/work/obs-studio/obs-studio/ci/flatpak_builder_lint.py
  cause: No such file or directory (os error 2)

${{ github.workspace }} interpolates to the runner's host path, while a job container mounts the tree at /__w/<repo>/<repo>, so the module cannot be spawned there. Nothing in this PR could have caught it: no PR lane runs flatpak-build or flatpak-publish, which is why #2702's checks were green.

#2707 fixes it — the action derives the repo root from GITHUB_ACTION_PATH (the container-side value the inline shell it replaced used for exceptions.json), verified end to end in ghcr.io/flathub-infra/flatpak-github-actions:freedesktop-26.08: the host path exits 2 with exactly that message, the container path and a real lint --artifact manifest both exit 0.

MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…bs-rust#2705) (obs-rust#2706)

* ci: Pin that the Flatpak lint action addresses its module relatively (obs-rust#2705)

The Flatpak job runs in a container at /__w/obs-studio/obs-studio, but
${{ github.workspace }} in a composite action's run: resolves to the runner
host path, so the module never spawns. The pin fails on master.

* ci: Address the Flatpak lint module relative to the job's container (obs-rust#2705)

The Flatpak job runs inside a container at /__w/obs-studio/obs-studio, while
${{ github.workspace }} and ${{ github.action_path }} interpolate the runner
host path (/home/runner/work/...). Passing those as arguments is not translated
the way working-directory: is, so obs-rust#2702's GEN-005 port made the first lint step
die with 'Failed to spawn: .../ci/flatpak_builder_lint.py' before the build.

Both steps already carry working-directory: ${{ inputs.workingDirectory }}
(the workspace by default), so the module and the action's own exceptions.json
are now addressed relative to it, matching the neighbouring
ci/flatpak_compiler_diagnostics.py step in the same job.

Verified locally: the new pin passes, ci/test_flatpak_builder_lint.py stays
green, guard exits 0 for manifest and 2 for an unknown kind, and the action
YAML parses with both run commands as intended. The Flatpak lane itself only
runs from Scheduled/dispatch, so a workflow_dispatch is the real proof.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

infra: Port the flatpak-builder-lint composite action to Python (GEN-005 burn-down)

1 participant