Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# The maintained actionlint fork (#1501) that knows current runner labels, pinned by digest.
# This stage is a reference only; the binary is copied into the devcontainer image below.
FROM docker.io/kjanat/actionlint:1.17.0@sha256:d484cccadf56b6a356466ade9af4c8e05c5dce1badaf0a9ecd0d7639d68d9c92 AS actionlint

FROM debian:sid

# Avoid interactive prompts during apt operations in CI
Expand Down Expand Up @@ -49,3 +53,7 @@ COPY src/ /tmp/devops-cli/src/
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system --break-system-packages --no-deps /tmp/devops-cli && \
rm -rf /tmp/devops-cli

# Provide the pinned actionlint binary on PATH so the bare `actionlint` command resolves.
# Placed last so a source change above rebuilds no earlier layer.
COPY --from=actionlint /usr/local/bin/actionlint /usr/local/bin/actionlint
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ jobs:
- name: Install Trivy
run: uv run devops install-tools --tool trivy --only-missing

# The pinned actionlint validates the workflows. It is the same digest-pinned image that the
# devcontainer Dockerfile copies, so the gate does not run actionlint twice (#1119).
- name: Run actionlint
uses: docker://docker.io/kjanat/actionlint:1.17.0@sha256:d484cccadf56b6a356466ade9af4c8e05c5dce1badaf0a9ecd0d7639d68d9c92

- name: Static Analysis Quality Gate
run: uv run devops ci --check --no-cache --skip test,outdated
run: uv run devops ci --check --no-cache --skip test,outdated,actionlint

# The scan skips Trivy's filesystem scan, `trivy`, which took 194 s over this tree. The audit
# row of the quality gate checks the dependencies.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-10-29
skip_specs: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Design

## Context

The `actionlint-py` PyPI wrapper is stalled at version 1.7.12, which rejects `ubuntu-26.04` as an unknown label, blocking the lint gate. The maintained upstream `actionlint` has reached v1.17.0. The devcontainer already provides other tools via `COPY --from` stages, and the CI workflow already uses `docker://` actions for other tools.

## Goals / Non-Goals

**Goals:**

- Replace `actionlint-py` (stalled PyPI wrapper) with `kjanat/actionlint` v1.17.0 (maintained upstream binary).
- Deliver the binary as a digest-pinned Docker image so the gate never depends on a mutable PyPI release.
- Keep the `actionlint` row of `devops ci` unchanged in name and behavior.
- Pass all existing tests without lowering any threshold.

**Non-Goals:**

- Changing the `actionlint` linter's behavior or configuration.
- Adding new checks to the CI gate.
- Changing the devcontainer's base image.

## Decisions

- **Use a digest-pinned Docker image.** The devcontainer `Dockerfile` adds a `FROM docker.io/kjanat/actionlint:1.17.0@sha256:d484ccca…` stage and `COPY --from` of the binary into the final image. This pins the exact binary by content hash, so a future registry update cannot change what the gate runs. Rejected: using a tag-pinned image. A tag can be moved to a different binary; a digest cannot.
- **Invoke `actionlint` bare on `PATH`.** The devcontainer provides the binary at `/usr/local/bin/actionlint`. The gate's `CheckSpec` command changes from `["uv", "run", "actionlint"]` to `["actionlint"]`. The `shutil.which` pre-check in the subcommand gives a clear message when the binary is absent (e.g. on a host without the devcontainer). Rejected: keeping `uv run actionlint`. This would require `actionlint-py` to remain in the dependency group, which this change removes.
- **Add a `docker://` step in CI.** The `Static Analysis` job of `ci.yml` adds a `docker://docker.io/kjanat/actionlint:1.17.0@sha256:d484ccca…` step that runs the linter in CI. The gate now skips `actionlint` (it runs as a separate `uses:` step). This mirrors the existing pattern for other tools delivered via `docker://`. Rejected: running `actionlint` inside the `devops ci` gate in CI. The binary would not be on `PATH` in the CI runner.
- **Add an offline digest-parity test.** `test_actionlint_digest_pinned_in_dockerfile_and_ci` asserts that the Dockerfile `FROM` and the CI workflow `uses:` reference the same digest-pinned image. This prevents the two from drifting apart.

## Risks / Trade-offs

- [The Docker Hub image is removed or the digest becomes unavailable] → The digest is content-addressed; as long as Docker Hub retains the blob, the build is reproducible. The repository pins the digest in both the Dockerfile and the CI workflow, and the digest-parity test holds them together.
- [A host without the devcontainer runs `devops ci actionlint`] → The `shutil.which` pre-check exits with a clear message naming the missing binary and the install source.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Proposal

## Why

Issue #1119: the `actionlint-py` PyPI wrapper is stalled at version 1.7.12, which rejects `ubuntu-26.04` as an unknown label. The maintained upstream `actionlint` has reached v1.17.0, which accepts `ubuntu-26.04`. This change replaces the stalled PyPI wrapper with the maintained upstream binary, delivered as a digest-pinned Docker image so the gate never depends on a mutable PyPI release.

## What Changes

- The devcontainer `Dockerfile` adds a `FROM docker.io/kjanat/actionlint:1.17.0@sha256:d484ccca…` stage and `COPY --from` of the `actionlint` binary into the final image.
- `pyproject.toml` removes `actionlint-py` from the `dev` dependency group; `uv.lock` is regenerated.
- `src/devops_cli/commands/ci.py` changes the `actionlint` row's command from `["uv", "run", "actionlint"]` to `["actionlint"]`, and adds a `shutil.which` pre-check in the subcommand that exits with a clear message when the binary is not on `PATH` (skipped during `--dry-run`).
- `.github/workflows/ci.yml` adds a `docker://docker.io/kjanat/actionlint:1.17.0@sha256:d484ccca…` step to the `Static Analysis` job, and the gate now skips `actionlint` (it runs as a separate `uses:` step).
- `tests/test_ci.py`, `tests/test_ci_dry_run.py` and `tests/test_workflow_contracts.py` are updated to match the new invocation and to assert that the Dockerfile and CI workflow reference the same digest.
- `src/devops_cli/ai/knowledge_base/devops_cli/libraries/bandit_actionlint.md` and `python_packages.md` are updated to reflect the new invocation.

The change alters no observable behavior of `devops ci`: the `actionlint` row still runs the same linter against the same files, and the gate result is unchanged. It is a dependency and delivery-method refactor. `skip_specs: true`.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

None. The `actionlint` row of `devops ci` runs the same linter against the same files; only the binary's origin and invocation method change.

## Impact

- Code: `src/devops_cli/commands/ci.py` (CheckSpec command, `shutil.which` pre-check).
- Build: `.devcontainer/Dockerfile` (FROM + COPY stage).
- Config: `pyproject.toml` (remove `actionlint-py`), `uv.lock` (regenerated).
- CI: `.github/workflows/ci.yml` (docker:// step, skip list).
- Tests: `tests/test_ci.py`, `tests/test_ci_dry_run.py`, `tests/test_workflow_contracts.py`.
- Docs: `src/devops_cli/ai/knowledge_base/devops_cli/libraries/bandit_actionlint.md`, `python_packages.md`.

## Feasibility

- `docker.io/kjanat/actionlint:1.17.0` exists on Docker Hub and its manifest is digest-addressable at `sha256:d484cccadf56b6a356466ade9af4c8e05c5dce1badaf0a9ecd0d7639d68d9c92`. The binary lives at `/usr/local/bin/actionlint` inside the image (confirmed via `docker inspect`).
- `actionlint` v1.17.0 accepts `ubuntu-26.04` as a valid label (upstream release notes), unblocking the lint gate.
- `COPY --from=image` is excluded from the COPY-coverage invariant in `tests/test_architectural_invariants.py:962-1000`, so the new COPY stage does not trip the ratchet.

## Existing Tool Considered

- `kjanat/actionlint` v1.17.0 is the upstream, actively maintained actionlint binary. Rather than continuing to depend on the stalled `actionlint-py` PyPI wrapper (last release 1.7.12), this change uses the upstream binary directly via a digest-pinned Docker image, which is the canonical distribution channel for the actionlint project.
- The change deletes the `actionlint-py==1.7.12.25` entry from `pyproject.toml` and the corresponding lock entry from `uv.lock`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Tasks

## 1. Update tests for the new invocation

- [x] 1.1 Update `tests/test_ci.py`, `tests/test_ci_dry_run.py` and `tests/test_workflow_contracts.py` to match the new `["actionlint"]` invocation, add `shutil.which` mocks, add `test_ci_actionlint_not_on_path`, add the allowlist entry for the `docker://` step, add the `covered_rows` fix, add the digest-parity test, and verify they pass (`uv run pytest tests/test_ci.py tests/test_ci_dry_run.py tests/test_workflow_contracts.py`)

## 2. Implementation of the digest-pinned delivery

- [x] 2.1 Add the `FROM docker.io/kjanat/actionlint:1.17.0@sha256:d484ccca…` stage and `COPY --from` to `.devcontainer/Dockerfile`, remove `actionlint-py` from `pyproject.toml`, regenerate `uv.lock`, change the `CheckSpec` command to `["actionlint"]` and add the `shutil.which` pre-check in `src/devops_cli/commands/ci.py` (`uv run pytest tests/test_ci.py tests/test_ci_dry_run.py tests/test_workflow_contracts.py tests/test_architectural_invariants.py`)
- [x] 2.2 Add the `docker://` actionlint step to the `Static Analysis` job of `.github/workflows/ci.yml` and update the `--skip` list (`uv run pytest tests/test_ci.py tests/test_ci_dry_run.py tests/test_workflow_contracts.py`)

## 3. Documentation

- [x] 3.1 Update `src/devops_cli/ai/knowledge_base/devops_cli/libraries/bandit_actionlint.md` and `python_packages.md` to reflect the new invocation (`uv run devops docs check`)

## 4. Full gate and OpenSpec archive

- [x] 4.1 Verify all tests and static checks pass (`uv run devops ci --check --no-cache --skip test,outdated,actionlint`)
- [x] 4.2 Archive OpenSpec change (`uv run devops openspec archive 1119-actionlint-docker-image`)

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ dev = [
"pytest-randomly==5.0.0",
"pytest-timeout==2.4.0",
"bandit==1.9.4",
"actionlint-py==1.7.12.25",
"zizmor==1.30.1",
"pre-commit==4.6.2",
"hypothesis==6.168.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tags:
| :--- | :--- |
| **Official Documentation** | [bandit.readthedocs.io](https://bandit.readthedocs.io/) • [github.com/rhysd/actionlint](https://github.com/rhysd/actionlint) |
| **Public Git Repository** | [github.com/PyCQA/bandit](https://github.com/PyCQA/bandit) • [github.com/rhysd/actionlint](https://github.com/rhysd/actionlint) |
| **Official PyPI Packages** | `bandit==1.9.4`, `actionlint-py==1.7.12.25` |
| **Pinned Packages** | `bandit==1.9.4` (PyPI) • `actionlint 1.17.0` (docker.io/kjanat/actionlint, digest-pinned) |
| **DevOps CLI Integration** | [`src/devops_cli/commands/ci.py`](../../../../../../src/devops_cli/commands/ci.py) • [`src/devops_cli/security/`](../../../../../../src/devops_cli/security/) |

---
Expand Down Expand Up @@ -62,7 +62,7 @@ uv run bandit -r src --ini .bandit --severity-level low
uv run bandit -r tests --ini .bandit --severity-level medium

# Execute Actionlint against all GitHub Actions workflow definitions
uv run actionlint
actionlint
```

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ The development environment leverages modern Python engineering tools managed vi
| **`pytest-randomly`** | `5.0.0` | Shuffles test order and reseeds `random` for each test; blocked in `addopts` (`-p no:randomly`) and enabled only by `devops ci test --repeat`. | `uv run devops ci test --repeat 3 <test files>` |
| **`pytest-timeout`** | `2.4.0` | Fails a test that hangs at the per-test bound in `[tool.pytest.ini_options]` (`timeout`, `timeout_method = "signal"`), so a stuck test fails in its own process and the run carries on. | `@pytest.mark.timeout(<seconds>)` for a test that needs longer |
| **`bandit`** | `1.9.4` | AST-based Python security analyzer detecting insecure patterns (CWE checks). | `uv run devops ci security` (`bandit -r src` at low, `bandit -r tests` at medium, with `--ini .bandit`) |
| **`actionlint-py`** | `1.7.12.25` | GitHub Actions workflow syntax and expression validation engine. | `uv run actionlint` |

| **`pre-commit`** | `4.6.2` | Multi-hook manager orchestrating git commit quality gates. | `uv run pre-commit run --all-files` |
| **`hatchling`** | `>=1.32.4` | Build backend complying with PEP 517 / PEP 621 for wheel generation. | `uv build` |

Expand Down
10 changes: 9 additions & 1 deletion src/devops_cli/commands/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import re
import shlex
import shutil
import signal
import subprocess
import sys
Expand Down Expand Up @@ -769,7 +770,7 @@ def get_check_specs() -> list[CheckSpec]:
CheckSpec(
name="actionlint",
display_title=MESSAGES.ci.actionlint,
cmd=["uv", "run", "actionlint"],
cmd=["actionlint"],
span_name="ci.step.actionlint",
metric_step="actionlint",
),
Expand Down Expand Up @@ -2011,6 +2012,13 @@ def actionlint(
set_dry_run(True)
if not _verify_python_314_environment():
raise typer.Exit(1)
if not dry_run and shutil.which("actionlint") is None:
print_error(
"actionlint is not on PATH. The devcontainer image provides it. "
"For other hosts, install it from https://github.com/kjanat/actionlint "
"or the actionlint install page."
)
raise typer.Exit(1)
spec = get_check_spec("actionlint")
if not _run(spec.cmd):
raise typer.Exit(1)
Expand Down
29 changes: 29 additions & 0 deletions tests/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,25 @@ def mock_run(cmd, *args, **kwargs):
return subprocess.CompletedProcess(args=cmd, returncode=0, stdout="", stderr="")

monkeypatch.setattr("subprocess.run", mock_run)
monkeypatch.setattr(
shutil,
"which",
lambda name: "/usr/local/bin/actionlint" if name == "actionlint" else None,
)

result = runner.invoke(app, ["actionlint"])
assert result.exit_code == 0
assert any("actionlint" in c for c in called)


def test_ci_actionlint_not_on_path(monkeypatch) -> None:
monkeypatch.setattr(shutil, "which", lambda name: None)
result = runner.invoke(app, ["actionlint"])
assert result.exit_code == 1
assert "actionlint" in result.output
assert "devcontainer" in result.output


def test_ci_lint_command(monkeypatch) -> None:
called = []

Expand Down Expand Up @@ -2361,6 +2374,11 @@ def mock_run(cmd: list[str], *a: Any, **kw: Any) -> subprocess.CompletedProcess[

monkeypatch.setattr(subprocess, "run", mock_run)
monkeypatch.setattr(ci_module, "run_subprocess", mock_run)
monkeypatch.setattr(
shutil,
"which",
lambda name: "/usr/local/bin/actionlint" if name == "actionlint" else None,
)

spec = get_check_spec(expected_row)
args = [subcmd]
Expand Down Expand Up @@ -2641,6 +2659,10 @@ def _validate_ci_workflow_parity(workflow_data: dict[str, Any]) -> None:
"static",
"Install Trivy",
): "Installs the pinned Trivy that the Security Scan step runs, with the lock's installer",
(
"static",
"Run actionlint",
): "Runs the pinned actionlint via the docker image, so the gate skips it (#1119)",
(
"test",
"Install promtool",
Expand Down Expand Up @@ -2684,6 +2706,13 @@ def _validate_ci_workflow_parity(workflow_data: dict[str, Any]) -> None:
)
covered_rows.update(rows)

# The docker:// actionlint step covers the actionlint row without a `run` command (#1119).
for job_info in jobs.values():
for step in job_info.get("steps", []):
uses = step.get("uses", "") if isinstance(step, dict) else ""
if "kjanat/actionlint" in uses:
covered_rows.add("actionlint")

missing = all_spec_names - covered_rows
assert not missing, (
f"CI workflow does not cover all check table rows. Missing: {sorted(missing)}"
Expand Down
7 changes: 6 additions & 1 deletion tests/test_ci_dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ def test_ci_all_checks_dry_run(recorder: list[list[str]]) -> None:
in res.stdout,
) == (True, True, True)
for spec in specs:
target_name = spec.cmd[2] if len(spec.cmd) > 2 and spec.cmd[0] == "uv" else spec.cmd[1]
if len(spec.cmd) > 2 and spec.cmd[0] == "uv":
target_name = spec.cmd[2]
elif len(spec.cmd) > 1:
target_name = spec.cmd[1]
else:
target_name = spec.cmd[0]
assert target_name in res.stdout
# No pass badges or summary table under dry run
assert ("✓ pass" in res.stdout, "CI Summary" in res.stdout) == (False, False)
Expand Down
30 changes: 28 additions & 2 deletions tests/test_workflow_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,14 @@ def _uses(node: Any) -> Iterator[str]:

def test_every_remote_action_is_pinned_to_a_commit_sha() -> None:
"""A tag or branch can be moved to other code; a 40-character commit SHA cannot. Local
`./` actions are this repository's own."""
`./` actions are this repository's own. `docker://` images are pinned by digest (#1119)."""
unpinned = [
f"{path}: {ref}"
for path in _automation_files()
for ref in _uses(_load_workflow(path))
if not ref.startswith("./") and not re.fullmatch(r"[^@\s]+@[0-9a-f]{40}", ref)
if not ref.startswith("./")
and not re.fullmatch(r"[^@\s]+@[0-9a-f]{40}", ref)
and not (ref.startswith("docker://") and re.search(r"@sha256:[0-9a-f]{64}", ref))
]
assert unpinned == []

Expand Down Expand Up @@ -1253,3 +1255,27 @@ def test_a_pull_request_that_changes_an_image_pin_resolves_each_pinned_image() -
},
],
)


def test_actionlint_digest_pinned_in_dockerfile_and_ci() -> None:
"""The Dockerfile FROM and the ci.yml uses: reference the same digest-pinned image (#1119)."""
dockerfile = Path(".devcontainer/Dockerfile").read_text(encoding="utf-8")
ci_yaml = Path(".github/workflows/ci.yml").read_text(encoding="utf-8")

dockerfile_match = re.search(
r"FROM\s+(docker\.io/kjanat/actionlint:1\.17\.0@sha256:[0-9a-f]{64})\s+AS\s+actionlint",
dockerfile,
)
assert dockerfile_match, "Dockerfile FROM actionlint digest-pinned image not found"

ci_yaml_match = re.search(
r"uses:\s+(docker://docker\.io/kjanat/actionlint:1\.17\.0@sha256:[0-9a-f]{64})",
ci_yaml,
)
assert ci_yaml_match, "ci.yml uses: actionlint digest-pinned image not found"

dockerfile_ref = dockerfile_match.group(1)
ci_yaml_ref = ci_yaml_match.group(1).removeprefix("docker://")
assert dockerfile_ref == ci_yaml_ref, (
f"Dockerfile and ci.yml actionlint digests differ: {dockerfile_ref} != {ci_yaml_ref}"
)
8 changes: 0 additions & 8 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading