Schedule CI badge refresh without workflow recursion
next-build / build (push) Successful in 18s

This commit is contained in:
2026-10-16 07:03:17 -06:00
parent 52e6093011
commit 8d19cdeae6
4 changed files with 37 additions and 20 deletions
+4 -4
View File
@@ -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
+2 -1
View File
@@ -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
+9 -15
View File
@@ -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__":
+22
View File
@@ -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</text>" in svg
assert b"#d1242f" in svg
assert b">pass</text>" 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,