Skip to content
Open
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions changes/270-migration-ci.minor.md
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions morca.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions morca.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
149 changes: 149 additions & 0 deletions pipelines/mojo_ci.mojo
Original file line number Diff line number Diff line change
@@ -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]()
3 changes: 2 additions & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading