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
44 changes: 44 additions & 0 deletions .github/workflows/linux-x86-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,53 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
verify:
name: Verify local attestations
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository &&
!contains(github.event.pull_request.labels.*.name, 'ci-full')
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
outputs:
skip_call: ${{ steps.plan.outputs.skip_call }}
skip_unit: ${{ steps.plan.outputs.skip_unit }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
fetch-depth: 0
- uses: astral-sh/setup-uv@v5
- name: Plan PR gates from the base
id: plan
if: hashFiles('ci/prooft_verify.py') != '' && hashFiles('ci-attestations.yml') != ''
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: uv run --no-project python ci/prooft_verify.py "$BASE_SHA" "$HEAD_SHA" "$PR_TITLE"

call:
name: Lint (format, Clippy, Dylint)
needs: verify
if: ${{ !cancelled() && needs.verify.outputs.skip_call != 'true' }}
uses: ./.github/workflows/_lint.yml
with:
source-sha: ${{ github.event_name == 'workflow_dispatch' && inputs.candidate_sha || github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
runs-on: ubuntu-24.04
run-dylint: true

unit:
name: Linux x86 Unit Test
needs: verify
if: >-
!cancelled() && github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'ci-test') &&
!contains(github.event.pull_request.labels.*.name, 'ci-full') &&
needs.verify.outputs.skip_unit != 'true'
uses: ./.github/workflows/_unit-test.yml
with:
source-sha: ${{ github.event.pull_request.head.sha }}
runs-on: ubuntu-24.04
4 changes: 3 additions & 1 deletion .github/workflows/linux-x86-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
# ci-test PRs share the verifier in linux-x86-lint.yml. Keep this cell
# for ci-full PR coverage and exact-SHA release dispatches.
call:
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && (contains(github.event.pull_request.labels.*.name, 'ci-test') || contains(github.event.pull_request.labels.*.name, 'ci-full')))
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-full'))
uses: ./.github/workflows/_unit-test.yml
with:
source-sha: ${{ github.event_name == 'workflow_dispatch' && inputs.candidate_sha || github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
Expand Down
16 changes: 16 additions & 0 deletions ci-attestations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 1
lanes:
lint:
inputs: ["crates/**", "dylints/**", "src/**", "ci/**", "tests/**", "examples/**", "demo/**", "vscode-plugin/**", ".github/workflows/_lint.yml", Cargo.toml, Cargo.lock, rust-toolchain.toml, pyproject.toml, uv.lock, setup.py, MANIFEST.in, README.md, LICENSE, lint, push, ci-attestations.yml]
test:
inputs: ["crates/**", "dylints/**", "src/**", "ci/**", "tests/**", "examples/**", "demo/**", "vscode-plugin/**", ".github/workflows/**", Cargo.toml, Cargo.lock, rust-toolchain.toml, pyproject.toml, uv.lock, setup.py, MANIFEST.in, README.md, LICENSE, lint, test, push, ci-attestations.yml]
gates:
general/linux-x64/lint: {lane: lint}
rust/all/fmt: {lane: lint}
rust/x86_64-unknown-linux-gnu/clippy: {lane: lint}
rust/x86_64-unknown-linux-gnu/dylint: {lane: lint}
rust/x86_64-unknown-linux-gnu/test: {lane: test}
python/linux-x64/test: {lane: test}
jobs:
linux-x86-lint.yml:call: [general/linux-x64/lint, rust/all/fmt, rust/x86_64-unknown-linux-gnu/clippy, rust/x86_64-unknown-linux-gnu/dylint]
linux-x86-lint.yml:unit: [rust/x86_64-unknown-linux-gnu/test, python/linux-x64/test]
28 changes: 28 additions & 0 deletions ci/attest_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Run the same unit tests as CI with concurrency scaled to host load."""

import os
import subprocess
import sys


def load_aware_workers(cpus: int, load: float) -> int:
"""Keep full concurrency on an idle host and scale down on a busy host."""
return min(cpus, max(2, int(cpus * cpus / max(cpus, load))))


def main() -> int:
if sys.platform != "linux":
raise RuntimeError("Linux unit attestations require Linux")
cpus = len(os.sched_getaffinity(0))
load = os.getloadavg()[0]
workers = str(load_aware_workers(cpus, load))
print(
f"Unit tests: {workers} workers ({cpus} CPUs, 1-minute load {load:.1f})",
flush=True,
)
env = {**os.environ, "RUST_TEST_THREADS": workers, "CARGO_BUILD_JOBS": workers}
return subprocess.run(["./test"], env=env, check=False).returncode


if __name__ == "__main__":
raise SystemExit(main())
24 changes: 20 additions & 4 deletions ci/check_full_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@
"macos-x86",
"macos-arm",
}
# The x86 Linux lint workflow also serves ordinary PRs. These two jobs
# are expected to skip during exact-SHA dispatch and ci-full PR runs.
PR_ONLY_JOBS = {
"linux-x86-lint.yml": {"Verify local attestations", "Linux x86 Unit Test"},
}
POLL_SECONDS = 120 # 29 workflows × runs/jobs endpoints; stay well below API limits.


def parse_time(value):
return dt.datetime.fromisoformat(value.replace("Z", "+00:00"))


def cell_result(run, jobs, sha, event, earliest):
def cell_result(run, jobs, sha, event, earliest, *, pr_only_jobs=()):
if run["head_sha"] != sha or run["event"] != event:
return "wrong-sha-or-event"
if parse_time(run["created_at"]) < earliest:
Expand All @@ -36,9 +41,13 @@ def cell_result(run, jobs, sha, event, earliest):
return "pending"
if run["conclusion"] != "success":
return run["conclusion"] or "failed"
if not jobs:
if not any(job.get("name") not in pr_only_jobs for job in jobs):
return "missing-jobs"
if any(job["conclusion"] != "success" for job in jobs):
if any(
job["conclusion"] != "success"
and not (job.get("name") in pr_only_jobs and job["conclusion"] == "skipped")
for job in jobs
):
return "skipped-or-failed-job"
return "passed"

Expand Down Expand Up @@ -104,7 +113,14 @@ def collect(repo, sha, event, earliest, workflows):
if run["status"] == "completed":
jobs = pages(f"repos/{repo}/actions/runs/{run['id']}/jobs", "jobs")
report[workflow] = {
"result": cell_result(run, jobs, sha, event, earliest),
"result": cell_result(
run,
jobs,
sha,
event,
earliest,
pr_only_jobs=PR_ONLY_JOBS.get(workflow, ()),
),
"run_id": run["id"],
"url": run["html_url"],
"jobs": [
Expand Down
34 changes: 34 additions & 0 deletions ci/prooft_verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Plan PR skips using the verifier and policy checked out from the base."""

import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
PROOFT_SOURCE = (
"git+https://github.com/forge-ci/prooft@d08d58bebcd8592e4526b9bde9ca4717966a8786"
)


def prooft(*args: str) -> list[str]:
return ["uvx", "--from", PROOFT_SOURCE, "prooft", "-C", str(ROOT), *args]


def main(base: str, head: str, title: str) -> int:
subprocess.run(["git", "fetch", "--no-tags", "origin", head], cwd=ROOT, check=True)
return subprocess.run(
prooft(
"plan",
"--base",
base,
"--head",
head,
f"--title={title}",
"--github-output",
),
check=False,
).returncode


if __name__ == "__main__":
raise SystemExit(main(*sys.argv[1:]))
Loading
Loading