diff --git a/.gitea/workflows/ci-badge.yml b/.gitea/workflows/ci-badge.yml index d1e854e..d8680fb 100644 --- a/.gitea/workflows/ci-badge.yml +++ b/.gitea/workflows/ci-badge.yml @@ -1,9 +1,9 @@ name: completed-ci-badge on: - workflow_run: - workflows: [main-release-gate, next-build] - types: [completed] + schedule: + - cron: '*/15 * * * *' + workflow_dispatch: concurrency: group: alkane-os-completed-ci-badge @@ -17,7 +17,7 @@ jobs: contents: write steps: - uses: actions/checkout@v4 - - name: Publish last completed attempt + - name: Publish last completed attempts env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: python3 ci/last-attempt-badge.py diff --git a/README.md b/README.md index eefe35d..3b6a009 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ increment the minor version for mining protocol, HAL, tuning policy, or API changes, and the patch version for compatible fixes. Badges measure host code only. The CI badge shows the last completed branch -attempt, and benchmark deltas compare results from the same CPU class. They +attempt and refreshes every 15 minutes when the runner is available. +Benchmark deltas compare results from the same CPU class. They do not certify board images or the pairing matrix. ## Local checks diff --git a/ci/last-attempt-badge.py b/ci/last-attempt-badge.py index c7eca28..118d610 100644 --- a/ci/last-attempt-badge.py +++ b/ci/last-attempt-badge.py @@ -2,9 +2,7 @@ # SPDX-License-Identifier: MIT """Publish the last completed main/next CI result to a private badge branch.""" -import json import os -from pathlib import Path from urllib.parse import quote, urlencode from badge_store import publish_file, request_json @@ -57,22 +55,18 @@ def publish(api: str, repo: str, branch: str, data: bytes, token: str) -> None: def main() -> None: - event = json.loads(Path(os.environ["GITHUB_EVENT_PATH"]).read_text()) - if event.get("action") != "completed": - raise RuntimeError("expected a completed workflow_run event") - run = event["workflow_run"] - workflow = run["path"].split("@", 1)[0].rsplit("/", 1)[-1] - expected_branch = WORKFLOWS.get(workflow) - if expected_branch is None or run.get("head_branch") != expected_branch: - raise RuntimeError("unexpected workflow or branch") + if os.environ["GITHUB_EVENT_NAME"] not in ("schedule", "workflow_dispatch"): + raise RuntimeError("badge publisher must run on a timer or manual dispatch") + if os.environ["GITHUB_REF"] != "refs/heads/main": + raise RuntimeError("badge publisher must use the main branch") repo = os.environ["GITHUB_REPOSITORY"] - if event["repository"]["full_name"] != repo: - raise RuntimeError("repository mismatch") api = os.environ["GITHUB_API_URL"].rstrip("/") token = os.environ["GITEA_TOKEN"] - run_id, conclusion = latest_completed(api, repo, workflow, expected_branch, token) - publish(api, repo, expected_branch, badge(expected_branch, conclusion, run_id), token) - print(f"{expected_branch} badge records completed run {run_id}: {conclusion}") + completed = {branch: latest_completed(api, repo, workflow, branch, token) + for workflow, branch in WORKFLOWS.items()} + for branch, (run_id, conclusion) in completed.items(): + publish(api, repo, branch, badge(branch, conclusion, run_id), token) + print(f"{branch} badge records completed run {run_id}: {conclusion}") if __name__ == "__main__": diff --git a/ci/test-last-attempt-badge.py b/ci/test-last-attempt-badge.py index 6af6767..c051984 100644 --- a/ci/test-last-attempt-badge.py +++ b/ci/test-last-attempt-badge.py @@ -3,6 +3,7 @@ """Check that queued CI runs do not displace the last completed result.""" import importlib.util +import os from pathlib import Path from unittest.mock import patch import xml.etree.ElementTree as ET @@ -34,6 +35,27 @@ assert root.attrib["aria-label"] == "CI main: last completed attempt fail (run 1 assert b">fail" in svg assert b"#d1242f" in svg assert b">pass" in module.badge("next", "success", 108) +environment = { + "GITHUB_EVENT_NAME": "schedule", + "GITHUB_REF": "refs/heads/main", + "GITHUB_REPOSITORY": "owner/repo", + "GITHUB_API_URL": "https://example.invalid/api/v1", + "GITEA_TOKEN": "test-token", +} +with patch.dict(os.environ, environment), \ + patch.object(module, "latest_completed", side_effect=[(201, "success"), + (202, "failure")]) as latest, \ + patch.object(module, "publish") as published: + module.main() + assert latest.call_count == 2 + assert [call.args[2] for call in published.call_args_list] == ["main", "next"] +with patch.dict(os.environ, {**environment, "GITHUB_EVENT_NAME": "workflow_run"}): + try: + module.main() + except RuntimeError as error: + assert "timer or manual dispatch" in str(error) + else: + raise AssertionError("workflow_run event entered badge publisher") for invalid in ("", "/main.svg", "../main.svg", "badges//main.svg"): try: publish_file("https://example.invalid/api/v1", "owner/repo", invalid,