diff --git a/README.md b/README.md index e3bf7b0..4591989 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,22 @@ GH Archive ──gharchive──▶ gharchive.events ──mojo_repos──▶ m key (morca.toml) with mojo_history, mojo_retool and mojo_versions, so the writers of these tables take turns. `src/refresh.mojo` has the selection; `tests/test_refresh.mojo` tests it. +- **`pipelines/mojo_ci.mojo`**: daily at 09:00 UTC, what each repository's + own CI said of the commits that moved it to another Mojo version. For each + `mojo_version` row of `mojo.migrations` no older than 270 days it asks + GitHub for the workflow runs on that commit (`GET + /repos/{owner}/{repo}/actions/runs?head_sha=…`, one request a commit) and + keeps one row per repository and commit in `mojo.migration_ci`: `passed`, + `failed`, `running` or `none`, with the runs counted. Only the + repository's own workflows count (a run GitHub starts by itself, such as + code scanning's default setup, has a `path` under `dynamic/`), and what a + workflow does isn't looked at. A commit is asked again each day until it + is three days old and nothing is still running, then never again; GitHub + stops listing a commit's runs after some months, so the row is the record. + Newest first, at most `MOJO_CI_MAX_REQUESTS` (1500) a run. The repo pages + show the answer beside each migration, and `/migrations` counts, per Mojo + version, the repositories whose CI passed or failed on the commit that + moved them. `src/ci.mojo` has the rules; `tests/test_ci.mojo` tests them. - **`bin/console.mojo`**: an overview (`/`: repos, commits and lines of Mojo with their change over 30 days, repos per Mojo version family, monthly curves from `mojo.commits`, adoption of the newest version, diff --git a/changes/270-migration-ci.minor.md b/changes/270-migration-ci.minor.md new file mode 100644 index 0000000..9955e80 --- /dev/null +++ b/changes/270-migration-ci.minor.md @@ -0,0 +1 @@ +- **CI on Mojo version moves**: a daily pipeline, `mojo_ci` (09:00 UTC), records in `mojo.migration_ci` what each repo's own GitHub Actions said of the commits that moved it to another Mojo version; repo pages show it beside each migration and `/migrations` counts it per version. Needs the GitHub token secret, as mojo_stats does; the table fills over its first two daily runs. (#270) diff --git a/morca.dev.toml b/morca.dev.toml index ed4e5b0..840cba0 100644 --- a/morca.dev.toml +++ b/morca.dev.toml @@ -90,6 +90,13 @@ env = { MOJO_EMBED_MODEL = "/tmp/mojo-census/models/bge-small-en-v1.5" } memory_gb = "auto" secrets = { GITHUB_TOKEN = "orca/github-token" } +# Daily at 09:00 UTC, an hour after mojo_issues (they share the token's +# hourly limit): the workflow runs on each commit that moved a repository +# to another Mojo version, one request a commit, at most 1,500 a run. +[pipelines.mojo_ci] +memory_gb = "auto" +secrets = { GITHUB_TOKEN = "orca/github-token" } + # The Live page's poller: one run an hour that polls every 3 minutes, over # GitHub's GraphQL API (its own rate limit: about 13 points a poll). [pipelines.mojo_live] diff --git a/morca.toml b/morca.toml index c4d1f44..2abcd12 100644 --- a/morca.toml +++ b/morca.toml @@ -143,6 +143,13 @@ env = { MOJO_EMBED_MODEL = "/tmp/mojo-census/models/bge-small-en-v1.5" } memory_gb = "auto" secrets = { GITHUB_TOKEN = "orca/github-token" } +# Daily at 09:00 UTC, an hour after mojo_issues (they share the token's +# hourly limit): the workflow runs on each commit that moved a repository +# to another Mojo version, one request a commit, at most 1,500 a run. +[pipelines.mojo_ci] +memory_gb = "auto" +secrets = { GITHUB_TOKEN = "orca/github-token" } + # The Live page's poller: one run an hour that polls every 3 minutes, over # GitHub's GraphQL API (its own rate limit: about 13 points a poll). [pipelines.mojo_live] diff --git a/pipelines/mojo_ci.mojo b/pipelines/mojo_ci.mojo new file mode 100644 index 0000000..6eb068b --- /dev/null +++ b/pipelines/mojo_ci.mojo @@ -0,0 +1,149 @@ +"""Asks GitHub what each repository's own CI said of the commits that moved it to another Mojo version, into mojo.migration_ci. + +Daily partitions from 2026-11-30, each filled at 09:00 UTC for that day +(`fire=Current`), an hour after mojo_issues so the two don't share an hour +of GitHub's rate limit. For each `mojo_version` row of `mojo.migrations` +no older than 270 days that has no settled answer yet, the step asks for +the workflow runs on its commit +(`GET /repos/{owner}/{repo}/actions/runs?head_sha=…`): one request a +commit. A commit is asked again each day until it is three days old and +none of its runs is still going, and never after. A day's run merges the +answers into the table and rewrites it (`replace.replace_files`): one row +per repository and commit, as GitHub had it last (`ci.mojo`). + +Newest commits first, at most MOJO_CI_MAX_REQUESTS (1500) a run; what's +left comes the next day, so a first run over a year of migrations takes a +few days. A rate limit is waited out for at most MOJO_CI_MAX_WAIT seconds +(3900) in all. + + GITHUB_TOKEN=... ./build/mojo_ci run --partitions 2026-11-30 +""" + +from std.os import getenv, setenv + +from morca import Cron, Ctx, Current, Daily, Day, Mapped, Pipeline, Step, morca_main +from morca.civil import now +from morca.tables import ensure_table, scan, table + +from ci import CiRow, ci_batch, ci_of, ci_rows, merge_ci, select_due +from cols import col, i64_at, str_at +from lake import MIGRATIONS, MIGRATION_CI, migration_ci_schema +from model import Migration +from replace import replace_files + + +def _migrations(mut ctx: Ctx) raises -> List[Migration]: + """Every row of `mojo.migrations` (at the step's pinned snapshot).""" + var out = List[Migration]() + var t = table(ctx, MIGRATIONS) + for b in scan(ctx, t).to_batches(): + var c_repo = col(b, "repo") + var c_sha = col(b, "sha") + var c_at = col(b, "committed_at") + var c_kind = col(b, "kind") + var c_from = col(b, "from_value") + var c_to = col(b, "to_value") + for r in range(b.num_rows): + out.append( + Migration( + str_at(b.column(c_repo), r), + str_at(b.column(c_sha), r), + i64_at(b.column(c_at), r), + str_at(b.column(c_kind), r), + str_at(b.column(c_from), r), + str_at(b.column(c_to), r), + ) + ) + return out^ + + +def fetch(mut ctx: Ctx, d: Day) raises -> Int: + """Asks GitHub about the commits that are due, merges the answers into + mojo.migration_ci and rewrites the table. Returns the commits answered.""" + var ms = _migrations(ctx) + var t = ensure_table(ctx, MIGRATION_CI, migration_ci_schema()) + var max_wait = Int(getenv("MOJO_CI_MAX_WAIT", "3900")) + var limit = Int(getenv("MOJO_CI_MAX_REQUESTS", "1500")) + + # The current rows, and the files they are in: the commit below removes + # every file, so the rows read must add up to what the files hold. + var old = List[CiRow]() + var files = List[String]() + var file_rows = Int64(0) + if t.metadata.has_current_snapshot: + for task in scan(ctx, t).plan_files(): + files.append(task.data_file.file_path) + file_rows += task.data_file.record_count + for b in scan(ctx, t).to_batches(): + for ref r in ci_rows(b): + old.append(r.copy()) + if Int64(len(old)) != file_rows: + raise Error(MIGRATION_CI, ": read ", len(old), " rows but its files hold ", file_rows) + + var due = select_due(ms, old, now() * 1_000_000, limit) + var fetched = List[CiRow]() + var calls = 0 + var waited = 0 + var remaining = -1 + var states = Dict[String, Int]() + for ref m in due: + var a = ci_of(m, max_wait - waited) + calls += a.calls + waited += a.waited_s + remaining = a.remaining + if not a.row: + states[a.error] = states.get(a.error, 0) + 1 + ctx.log(String(m.repo, " ", m.sha, ": ", a.error)) + continue + var state = a.row.value().state + states[state] = states.get(state, 0) + 1 + fetched.append(a.row.value().copy()) + var summary = String() + for e in states.items(): + summary += String(" ", e.key, "=", e.value) + ctx.log(String( + String(d), ": ", len(due), " commits in ", calls, " requests (", + waited, " s waiting on the rate limit; ", remaining, " left):", summary, + )) + if len(fetched) == 0: + ctx.log("nothing answered; nothing to commit") + return 0 + var before = len(old) + var rows = merge_ci(old^, fetched) + # One `overwrite` snapshot removing `files` and adding `rows`; safe + # because one run writes the table at a time (max_runs 1). + var id = replace_files(ctx, t, files, [ci_batch(rows)]) + ctx.log(String(MIGRATION_CI, " ", before, " -> ", len(rows), " rows; snapshot ", id)) + return len(fetched) + + +# `Mapped`: once per partition, here a `Day`. No dista task: the requests +# are made one at a time by the step itself, within GitHub's rate limit. +comptime Fetch = Step[ + "fetch", + Day, + Int, + fetch, + Mapped, + retries=1, + reads=[MIGRATIONS, MIGRATION_CI], + # replaces=: a rerun rewrites the table (replace.replace_files) rather + # than adding rows again, so `morca backfill --rerun` needs no + # --allow-append. + replaces=[MIGRATION_CI], +] +# A day's run asks about whatever is due, so a missed day needs no catch-up. +comptime MojoCi = Pipeline[ + "mojo_ci", + Fetch, + partitions=Daily["2026-11-30"], + schedule=Cron["0 9 * * *"], + fire=Current, + catchup=False, +] + + +def main() raises: + if not getenv("MORCA_WAREHOUSE"): + _ = setenv("MORCA_WAREHOUSE", "build/warehouse") + morca_main[MojoCi]() diff --git a/pixi.toml b/pixi.toml index 76f0e62..2eb8f44 100644 --- a/pixi.toml +++ b/pixi.toml @@ -23,10 +23,11 @@ build-mojo-stats = "mkdir -p build && rm -f build/mojo_stats && mojo build -I sr build-gharchive-index = "mkdir -p build && rm -f build/gharchive_index && mojo build -I src pipelines/gharchive_index.mojo -o build/gharchive_index" build-mojo-embed = "mkdir -p build && rm -f build/mojo_embed && mojo build -I src pipelines/mojo_embed.mojo -o build/mojo_embed" build-mojo-issues = "mkdir -p build && rm -f build/mojo_issues && mojo build -I src pipelines/mojo_issues.mojo -o build/mojo_issues" +build-mojo-ci = "mkdir -p build && rm -f build/mojo_ci && mojo build -I src pipelines/mojo_ci.mojo -o build/mojo_ci" build-mojo-live = "mkdir -p build && rm -f build/mojo_live && mojo build -I src pipelines/mojo_live.mojo -o build/mojo_live" build-mojo-retool = "mkdir -p build && rm -f build/mojo_retool && mojo build -I src pipelines/mojo_retool.mojo -o build/mojo_retool" build-mojo-refresh = "mkdir -p build && rm -f build/mojo_refresh && mojo build -I src pipelines/mojo_refresh.mojo -o build/mojo_refresh" -build-pipelines = { depends-on = ["build-gharchive", "build-gharchive-index", "build-mojo-repos", "build-mojo-history", "build-mojo-retool", "build-mojo-versions", "build-mojo-activity", "build-mojo-stats", "build-mojo-embed", "build-mojo-issues", "build-mojo-live", "build-mojo-refresh"] } +build-pipelines = { depends-on = ["build-gharchive", "build-gharchive-index", "build-mojo-repos", "build-mojo-history", "build-mojo-retool", "build-mojo-versions", "build-mojo-activity", "build-mojo-stats", "build-mojo-embed", "build-mojo-issues", "build-mojo-ci", "build-mojo-live", "build-mojo-refresh"] } # Every program, as in the image: two multi-call binaries, # build/multicall-apps and build/multicall-pipelines, and build/morca, # build/gharchive... as links to them (scripts/build.sh), so the code they diff --git a/src/ci.mojo b/src/ci.mojo new file mode 100644 index 0000000..d08e4e1 --- /dev/null +++ b/src/ci.mojo @@ -0,0 +1,334 @@ +"""What a repository's own CI said about a commit, for `mojo.migration_ci`. + +A repository that moves to another Mojo version and runs its CI on that +commit has tested the version for the census. `parse_runs` reads GitHub's +workflow runs of a commit (`GET /repos/{owner}/{repo}/actions/runs?head_sha=…`) +into one `CiRow`; `ci_of` asks, waiting out rate limits as mojo_stats does; +`select_due` picks the migrations to ask about; `ci_by_version` counts the +answers per Mojo version, for the Migrations page. + +Only the repository's own workflows count: a run GitHub starts by itself +(code scanning's default setup, Pages, Dependabot) has a `path` under +`dynamic/` and is left out. What a workflow does is not looked at, so a +`passed` says the repository's workflows passed on that commit, not that +they built Mojo. +""" + +from std.time import sleep + +from morca.civil import now +from morca.tables import BatchBuilder +from parquet import RecordBatch + +from cols import col, i64_at, str_at +from fetch import github +from jscan import Range, each, field, text +from lake import migration_ci_schema, try_load +from model import Migration +from overview import DAY_US +from stats import limited, state_of, wait_seconds +from versions import compare_versions + + +comptime MAX_AGE_DAYS = 270 +"""How old a commit can be and still be asked about. GitHub no longer lists +the runs of a commit after some months (bgreni/EmberJson's stop about ten +months back), and a commit with none reads the same as one whose runs are +gone.""" +comptime SETTLE_DAYS = 3 +"""A commit younger than this is asked about again on each run: its CI may +not have started when it was first asked, and a failed run may be run +again.""" + + +@fieldwise_init +struct CiRow(Copyable, Movable): + var repo: String + var sha: String + var committed_at: Int64 + """Microseconds since the epoch, as are `checked_at`.""" + var state: String + """`passed`: a workflow succeeded and none failed. `failed`: one failed. + `running`: none failed and one hasn't finished. `none`: no run of the + repository's own workflows, or only skipped and cancelled ones. `gone` + or `blocked`: GitHub no longer answers for the repository.""" + var runs: Int64 + var passed: Int64 + var failed: Int64 + var checked_at: Int64 + + def settled(self, now_us: Int64) -> Bool: + """Whether the row is final: not `running`, and its commit old enough + that its runs won't change.""" + return self.state != "running" and now_us - self.committed_at >= Int64(SETTLE_DAYS) * DAY_US + + +def _key(repo: String, sha: String) -> String: + return String(repo, " ", sha) + + +def parse_runs(repo: String, sha: String, committed_at: Int64, body: String, checked_at: Int64) -> CiRow: + """The row of a commit from GitHub's list of its workflow runs (the first + 100, which is more than a commit has).""" + var b = body.as_bytes() + var runs = Int64(0) + var passed = Int64(0) + var failed = Int64(0) + var running = Int64(0) + for it in each(b, field(b, Range(0, len(b)), "workflow_runs")): + if text(b, field(b, it, "path")).startswith("dynamic/"): + continue + runs += 1 + if text(b, field(b, it, "status")) != "completed": + running += 1 + continue + var conclusion = text(b, field(b, it, "conclusion")) + if conclusion == "success": + passed += 1 + elif conclusion == "failure" or conclusion == "timed_out" or conclusion == "startup_failure": + failed += 1 + var state = String("none") + if failed > 0: + state = String("failed") + elif running > 0: + state = String("running") + elif passed > 0: + state = String("passed") + return CiRow(repo, sha, committed_at, state^, runs, passed, failed, checked_at) + + +@fieldwise_init +struct Asked(Movable): + """What `ci_of` found: the row, or none for a reply that is neither an + answer nor a missing repository (`error`, which says what it was); the + requests made, the seconds waited and the rate limit left.""" + + var row: Optional[CiRow] + var error: String + var calls: Int + var waited_s: Int + var remaining: Int + + +def ci_of(m: Migration, max_wait_s: Int) raises -> Asked: + """Asks GitHub for the workflow runs on migration `m`'s commit, waiting + out rate limits for at most `max_wait_s` seconds in all; raises when + that isn't enough.""" + var calls = 0 + var waited = 0 + var attempt = 0 + while True: + var r = github(String("/repos/", m.repo, "/actions/runs?head_sha=", m.sha, "&per_page=100")) + calls += 1 + if limited(r): + var w = wait_seconds(r, Int(now()), attempt) + if waited + w > max_wait_s: + raise Error( + m.repo, ": GitHub's rate limit (HTTP ", r.status, + ") would take ", w, " s more after ", waited, " s", + ) + sleep(Float64(w)) + waited += w + attempt += 1 + continue + if r.status >= 500 and attempt < 3: + sleep(Float64(5 * (attempt + 1))) + waited += 5 * (attempt + 1) + attempt += 1 + continue + var at = now() * 1_000_000 + if r.status == 200: + return Asked(parse_runs(m.repo, m.sha, m.at, r.body, at), String(), calls, waited, r.remaining) + var state = state_of(r.status) + if state == "gone" or state == "blocked": + return Asked( + CiRow(m.repo, m.sha, m.at, state^, 0, 0, 0, at), String(), calls, waited, r.remaining + ) + # Anything else is asked again by the next run. + return Asked(None, state^, calls, waited, r.remaining) + + +def select_due(ms: List[Migration], known: List[CiRow], now_us: Int64, limit: Int) -> List[Migration]: + """The migrations to ask GitHub about now, newest first and at most + `limit`: each change of Mojo version (once per repository and commit) + no older than `MAX_AGE_DAYS` whose row isn't `settled`.""" + var final = Dict[String, Bool]() + for ref r in known: + if r.settled(now_us): + final[_key(r.repo, r.sha)] = True + var due = List[Migration]() + var seen = Dict[String, Bool]() + for ref m in ms: + if m.kind != "mojo_version" or m.sha.byte_length() == 0: + continue + if now_us - m.at > Int64(MAX_AGE_DAYS) * DAY_US: + continue + var k = _key(m.repo, m.sha) + if k in final or k in seen: + continue + seen[k] = True + due.append(m.copy()) + for i in range(1, len(due)): + var j = i + while j > 0 and due[j - 1].at < due[j].at: + due.swap_elements(j - 1, j) + j -= 1 + while len(due) > limit: + _ = due.pop() + return due^ + + +def merge_ci(var old: List[CiRow], new: List[CiRow]) -> List[CiRow]: + """`old` with each row of `new` in place of the row of the same + repository and commit (or added).""" + var at = Dict[String, Int]() + for i in range(len(old)): + at[_key(old[i].repo, old[i].sha)] = i + for ref r in new: + var k = _key(r.repo, r.sha) + var i = at.get(k, -1) + if i >= 0: + old[i] = r.copy() + else: + at[k] = len(old) + old.append(r.copy()) + return old^ + + +def ci_rows(b: RecordBatch) raises -> List[CiRow]: + """The rows of a scanned `mojo.migration_ci` batch.""" + var c = List[Int]() + for name in ["repo", "sha", "committed_at", "state", "runs", "passed", "failed", "checked_at"]: + c.append(col(b, name)) + var out = List[CiRow]() + for r in range(b.num_rows): + out.append( + CiRow( + str_at(b.column(c[0]), r), + str_at(b.column(c[1]), r), + i64_at(b.column(c[2]), r), + str_at(b.column(c[3]), r), + i64_at(b.column(c[4]), r), + i64_at(b.column(c[5]), r), + i64_at(b.column(c[6]), r), + i64_at(b.column(c[7]), r), + ) + ) + return out^ + + +def ci_batch(rows: List[CiRow]) raises -> RecordBatch: + """`rows` as a batch of `mojo.migration_ci`.""" + var b = BatchBuilder(migration_ci_schema()) + var cs = b.roots.copy() + for ref r in rows: + b.add_str(cs[0], r.repo) + b.add_str(cs[1], r.sha) + b.add_int(cs[2], r.committed_at) + b.add_str(cs[3], r.state) + b.add_int(cs[4], r.runs) + b.add_int(cs[5], r.passed) + b.add_int(cs[6], r.failed) + b.add_int(cs[7], r.checked_at) + return b^.build() + + +def read_ci() raises -> List[CiRow]: + """mojo.migration_ci's current snapshot; empty when the table doesn't + exist yet.""" + var rows = List[CiRow]() + var t = try_load("mojo", "migration_ci") + if not t or not t.value().metadata.has_current_snapshot: + return rows^ + for b in t.value().scan().to_batches(): + for ref r in ci_rows(b): + rows.append(r.copy()) + return rows^ + + +def by_repo(rows: List[CiRow]) -> Dict[String, List[CiRow]]: + """`rows` by repository, for the repo pages.""" + var out = Dict[String, List[CiRow]]() + for ref r in rows: + if r.repo not in out: + out[r.repo] = List[CiRow]() + try: + out[r.repo].append(r.copy()) + except: + pass + return out^ + + +def ci_at(rows: List[CiRow], sha: String) -> Optional[CiRow]: + """The row of commit `sha` among a repository's, if it has one.""" + for ref r in rows: + if r.sha == sha: + return r.copy() + return None + + +@fieldwise_init +struct VersionCi(Copyable, Movable): + """Of the repositories that moved to a Mojo version, how many ran their + own CI on the commit that moved them, and what it said.""" + + var version: String + var moved: Int + """Repositories with a commit that moved them to the version.""" + var passed: Int + var failed: Int + var failed_repos: List[String] + """Those whose CI failed, by name.""" + + def ran(self) -> Int: + return self.passed + self.failed + + +def ci_by_version(ms: List[Migration], rows: List[CiRow]) -> List[VersionCi]: + """`VersionCi` per Mojo version moved to (`to_value`), newest version + first, for the versions some repository's CI ran on. A repository counts + once per version, by its latest commit that moved it there and has a + `passed` or `failed` row. `ms` is oldest first (`model.migrations`).""" + var state = Dict[String, String]() + for ref r in rows: + if r.state == "passed" or r.state == "failed": + state[_key(r.repo, r.sha)] = r.state + # Per version and repository: what its CI said, or "" for a move with no + # answer. A later move replaces an earlier one only if it has an answer. + var latest = Dict[String, String]() + for ref m in ms: + if m.kind != "mojo_version" or m.to_value.byte_length() == 0: + continue + var k = String(m.to_value, " ", m.repo) + var s = state.get(_key(m.repo, m.sha), String()) + if s.byte_length() > 0 or k not in latest: + latest[k] = s + var at = Dict[String, Int]() + var all = List[VersionCi]() + for e in latest.items(): + var parts = e.key.split(" ") + var version = String(parts[0]) + var i = at.get(version, -1) + if i < 0: + i = len(all) + at[version] = i + all.append(VersionCi(version, 0, 0, 0, List[String]())) + all[i].moved += 1 + if e.value == "passed": + all[i].passed += 1 + elif e.value == "failed": + all[i].failed += 1 + all[i].failed_repos.append(String(parts[1])) + var out = List[VersionCi]() + for ref v in all: + if v.ran() == 0: + continue + var x = v.copy() + sort(x.failed_repos) + out.append(x^) + for i in range(1, len(out)): + var j = i + while j > 0 and compare_versions(out[j - 1].version, out[j].version) < 0: + out.swap_elements(j - 1, j) + j -= 1 + return out^ diff --git a/src/console_api.mojo b/src/console_api.mojo index 52da1ef..849e27d 100644 --- a/src/console_api.mojo +++ b/src/console_api.mojo @@ -21,6 +21,7 @@ from console_list import _matches, meaning_hits from similar import Neighbor from issues import IssueRow from categories import CATEGORIES_VERSION +from ci import CiRow, ci_at def _q(s: String) -> String: @@ -343,6 +344,19 @@ def over_time_json(l: Library, data: RepoData) -> String: return out^ +def _ci_json(ci: List[CiRow], sha: String) -> String: + """A migration's `"ci"`: what the repo's own workflows said of its + commit (mojo.migration_ci), or null before mojo_ci has an answer.""" + var found = ci_at(ci, sha) + if not found: + return String("null") + ref r = found.value() + return String( + '{"state":', _q(r.state), ',"runs":', r.runs, ',"passed":', r.passed, + ',"failed":', r.failed, ',"checked_at":', _q(micros_to_iso(r.checked_at)), "}", + ) + + def repo_json(req: Request, c: Cache) raises -> Response: try: var repo = String(req.param("owner"), "/", req.param("name")) @@ -361,7 +375,8 @@ def repo_json(req: Request, c: Cache) raises -> Response: first = False out.write( '{"at":', _q(micros_to_iso(m.at)), ',"sha":', _q(m.sha), ',"kind":', - _q(m.kind), ',"from":', _q(m.from_value), ',"to":', _q(m.to_value), "}", + _q(m.kind), ',"from":', _q(m.from_value), ',"to":', _q(m.to_value), + ',"ci":', _ci_json(data.ci, m.sha), "}", ) out += '],"commits":[' first = True diff --git a/src/console_cache.mojo b/src/console_cache.mojo index 39df011..47abb1a 100644 --- a/src/console_cache.mojo +++ b/src/console_cache.mojo @@ -40,6 +40,7 @@ from overview import ( unversioned, ) +from ci import CiRow, ci_by_version, read_ci from console_migrations_body import _migrations_body from measures import Measure, latest_measures from issues import RepoIssues, add_issue_months, read_issue_rows, summarize @@ -67,6 +68,8 @@ struct RepoData(Copyable, Movable): var pts: List[Point] """Its commits, oldest first.""" var ms: List[Migration] + var ci: List[CiRow] + """What its CI said of the commits of `ms` (mojo.migration_ci).""" var rels: List[Release] var acts: List[MonthActivity] var issues: RepoIssues @@ -77,6 +80,7 @@ struct RepoData(Copyable, Movable): def __init__(out self): self.pts = List[Point]() self.ms = List[Migration]() + self.ci = List[CiRow]() self.rels = List[Release]() self.acts = List[MonthActivity]() self.issues = RepoIssues() @@ -370,6 +374,17 @@ struct Cache(Movable): if m.repo not in details: details[m.repo] = RepoData() details[m.repo].ms.append(m.copy()) + # mojo.migration_ci's rows under the same keys as the migrations. + var kept_ci = List[CiRow]() + for ref r in read_ci(): + if _duplicate(r.repo, key_of, name_of): + continue + var rr = r.copy() + rr.repo = key_of.get(r.repo, r.repo) + if rr.repo in details: + details[rr.repo].ci.append(rr.copy()) + kept_ci.append(rr^) + var version_ci = ci_by_version(kept_ms, kept_ci) for e in releases_all().items(): var cur = name_of.get(e.key.lower(), e.key) if cur not in details: @@ -399,7 +414,7 @@ struct Cache(Movable): details[cur] = RepoData() details[cur].contributors = e.value.copy() self.loaded = activity_months() - self.migrations_body = _migrations_body(rows) if len(rows) > 0 else String() + self.migrations_body = _migrations_body(rows, version_ci) if len(rows) > 0 else String() self.version_rows = rows^ self.details = details^ self.commits30 = commits30.copy() diff --git a/src/console_migrations_body.mojo b/src/console_migrations_body.mojo index fc37bf5..f18580b 100644 --- a/src/console_migrations_body.mojo +++ b/src/console_migrations_body.mojo @@ -5,6 +5,7 @@ chart uses too.""" from flare.http import html_escape from charts import grid_line +from ci import VersionCi from model import VersionMonth from overview import bucket_color from search import sort_buckets, version_bucket @@ -155,13 +156,66 @@ def _migrations_head() -> String: ) -def _migrations_body(rows: List[VersionMonth]) raises -> String: - """The Migrations page's HTML for `rows` (at least one), rendered once - per cache build.""" +comptime CI_VERSIONS_SHOWN = 20 +"""How many versions the CI table lists, newest first.""" +comptime CI_FAILED_SHOWN = 5 +"""How many of a version's repos with failed CI the table names.""" + + +def _ci_table(ci: List[VersionCi]) -> String: + """What the repos' own CI said of the commit that moved them to each + version (`ci.ci_by_version`), newest version first; nothing before + mojo_ci has an answer.""" + if len(ci) == 0: + return String() + var h = String( + "
| Version | Repos moved | ", + "Ran CI | Passed | Failed | ", + "Failed in |
|---|---|---|---|---|---|
| ", html_escape(v.version), " | ", v.moved, + " | ", v.ran(), " | ", v.passed, + " | ", v.failed, " | ", + ) + if v.failed == 0: + h.write("–") + for k in range(min(len(v.failed_repos), CI_FAILED_SHOWN)): + ref repo = v.failed_repos[k] + h.write( + ", " if k > 0 else "", "", + html_escape(repo), "", + ) + if len(v.failed_repos) > CI_FAILED_SHOWN: + h.write(" and ", len(v.failed_repos) - CI_FAILED_SHOWN, " more") + h.write(" |
The newest ", CI_VERSIONS_SHOWN, " of ", len(ci), " versions with CI results.
") + return h^ + + +def _migrations_body(rows: List[VersionMonth], ci: List[VersionCi]) raises -> String: + """The Migrations page's HTML for `rows` (at least one) and the CI + results per version, rendered once per cache build.""" var h = String( _migrations_head(), ) h.write(_versions_chart(rows)) + h.write(_ci_table(ci)) var late = List[VersionMonth]() var early = List[VersionMonth]() for ref r in rows: diff --git a/src/console_repo.mojo b/src/console_repo.mojo index a2dad83..2585f96 100644 --- a/src/console_repo.mojo +++ b/src/console_repo.mojo @@ -3,6 +3,7 @@ lines of Mojo, commits and issues over time (as tabs, `?chart=`), dependencies, contributors per month, releases and tags, issues and pull requests, migrations and latest commits.""" from flare.http import Request, Response, html_escape, internal_error, not_found, redirect +from ci import CiRow, ci_at from contributors import RepoContributors from days import day_text from deps import other_owners @@ -204,6 +205,37 @@ comptime OVER_TIME_HELP = ( ) +comptime REPO_CI_HELP = ( + "CI: what the repo's own GitHub Actions workflows said of the commit that moved it" + " to that Mojo version, linked to the commit's checks on GitHub. Runs GitHub starts by" + " itself (code scanning's default setup, Pages) are left out, and what a workflow does" + " isn't looked at. Read by mojo_ci while GitHub still lists the commit's runs." +) + + +def _ci_cell(ci: List[CiRow], kind: String, sha: String, gh: String) -> String: + """The CI cell of a migration's row: the state of its commit's row of + mojo.migration_ci, linked to the commit's checks; a dash for a commit + mojo_ci hasn't an answer for, and for a change that isn't of Mojo + version.""" + var dash = String("| Date | What | From | To | ", - "Commit | Commit | ", "CI | " if with_ci else "", "", ) for ref m in ms: h.write( "
|---|---|---|---|---|
| ", day(m.at), " | ", html_escape(m.kind), " | ", _or_dash(m.from_value), " | ", _or_dash(m.to_value), " | ", - html_escape(String(m.sha[byte=:10])), " |