mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 10:51:11 +01:00
CI: the cache warm on main builds its five shards in parallel
`cargo xtask ci warm` builds only shard GATE_SHARD of GATE_SHARDS when the gate sets them, and every shard when neither is set; one set without the other, a non-number, a count other than the shard count, or a shard out of range is an error. ci.yml turns on the gate's `warm-split`, so main's warm runs as five `cache warm <k>/5` legs and a `cache warm` leg that saves the entry. The cold-cache cleanup waits for the split legs before it times the saving leg's start, and fails when a split leg fails. The cache-prune watch and both jobs' timeouts cover a split leg followed by the saving leg.
This commit is contained in:
1 parent
d4d8da4544
commit
3a617b1324
5 files changed
+222
-31
No files matched your search
@@ -46,6 +46,9 @@ jobs:
|
||||
test-shards: 5
|
||||
shard-command: cargo xtask ci shard
|
||||
warm-command: cargo xtask ci warm
|
||||
# The warm build runs as one `cache warm <k>/5` leg per shard, in parallel (each builds what
|
||||
# its shard builds), and `cache warm` puts their files into the one entry it saves.
|
||||
warm-split: true
|
||||
# The dependency cache also keeps the compiled workspace crates and test executables, so a
|
||||
# pull request's shards rebuild only the crates its changes reach. Each main run's `cache
|
||||
# warm` leg saves a rolling entry of its own, every leg restores the newest one, and
|
||||
@@ -61,13 +64,14 @@ jobs:
|
||||
# Keeps one rolling gate entry on main, so the repository stays within its 10 GB Actions cache
|
||||
# budget. It runs beside the gate and prunes each time the `cache warm` leg finishes saving. A
|
||||
# failed prune warns instead of failing the run, and cache-prune.yml prunes again after every
|
||||
# attempt, re-runs of failed jobs included. `watch-minutes` is longer than the gate's
|
||||
# `timeout-minutes`, so the watch outlasts a cold `cache warm` leg.
|
||||
# attempt, re-runs of failed jobs included. `watch-minutes` is longer than twice the gate's
|
||||
# `timeout-minutes`, so the watch outlasts a cold `cache warm <k>/5` leg followed by a
|
||||
# `cache warm` leg.
|
||||
cache-prune:
|
||||
name: cache prune
|
||||
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 170
|
||||
timeout-minutes: 320
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
@@ -80,7 +84,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
with:
|
||||
watch: true
|
||||
watch-minutes: 160
|
||||
watch-minutes: 310
|
||||
saving-jobs: |
|
||||
^gate( / cache warm \(.*\))?$
|
||||
|
||||
@@ -90,14 +94,17 @@ jobs:
|
||||
# the old entries when the `cache warm` leg starts saving (scripts/ci-clear-rolling-cache.py).
|
||||
# When the leg fails or is canceled, before its save or during it, this job fails too, so "Re-run
|
||||
# failed jobs" runs it again beside the re-run leg. The leg starts after `gate / select legs` and a
|
||||
# free runner: the script fails when the leg has not started within 120 minutes, and then waits
|
||||
# up to 160 minutes from the leg's start. This job's timeout is longer than both together, so the
|
||||
# script reports a leg that starts late with its own error before the job times out.
|
||||
# free runner, and with `warm-split` after every `cache warm <k>/5` leg. The script suspends its
|
||||
# start deadline while any split leg is queued or running, then allows 180 minutes from the last
|
||||
# split completion for the saving leg to start. Without split legs, it allows 180 minutes from
|
||||
# the script's start. A failed split leg fails this job too. The script then waits up to 160
|
||||
# minutes from the saving leg's start. GitHub's 360-minute job limit can end this job before the
|
||||
# script's deadlines expire when split builds or runner waits take too long.
|
||||
cold-cache-clear:
|
||||
name: cold cache clear
|
||||
if: github.event_name == 'schedule'
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 290
|
||||
timeout-minutes: 360
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
|
||||
@@ -36,6 +36,11 @@ def earlier(conclusion):
|
||||
return [{"name": WARM, "conclusion": conclusion}, {"name": "cold cache clear", "conclusion": "failure"}]
|
||||
|
||||
|
||||
def split_job(shard, status, completed_at=None):
|
||||
return {"name": f"gate / cache warm {shard}/5 (ubuntu-24.04)", "status": status,
|
||||
"conclusion": "success" if status == "completed" else None, "completed_at": completed_at}
|
||||
|
||||
|
||||
class SaveStep(unittest.TestCase):
|
||||
def test_the_leg_is_saving_once_its_save_step_starts(self):
|
||||
self.assertFalse(clear.saving(warm_job("in_progress", steps=[("Setup", "completed", "success"), ("Gate", "in_progress", None)])))
|
||||
@@ -99,6 +104,34 @@ class Deadline(unittest.TestCase):
|
||||
self.assertFalse(clear.started_late(warm_job("queued"), self.began))
|
||||
self.assertFalse(clear.started_late(None, self.began))
|
||||
|
||||
def test_split_progress_suspends_the_start_deadline(self):
|
||||
for status in ("queued", "in_progress"):
|
||||
with self.subTest(status=status):
|
||||
jobs = [split_job(1, "completed", "2026-11-28T06:00:00Z"), split_job(2, status)]
|
||||
ready = clear.start_wait_began(jobs, self.began)
|
||||
self.assertIsNone(ready)
|
||||
now = self.began + timedelta(seconds=clear.START_SECONDS + 60)
|
||||
self.assertFalse(clear.start_overdue(None, now, ready))
|
||||
self.assertFalse(clear.started_late(warm_job("in_progress", started_at=now.isoformat()), ready))
|
||||
|
||||
def test_the_last_split_completion_starts_the_wait(self):
|
||||
jobs = [split_job(1, "completed", "2026-11-28T08:00:00Z"),
|
||||
split_job(2, "completed", "2026-11-28T07:00:00Z")]
|
||||
ready = clear.start_wait_began(jobs, self.began)
|
||||
self.assertEqual(ready, clear.parse_time("2026-11-28T08:00:00Z"))
|
||||
self.assertFalse(clear.start_overdue(None, ready + timedelta(seconds=clear.START_SECONDS), ready))
|
||||
self.assertTrue(clear.start_overdue(None, ready + timedelta(seconds=clear.START_SECONDS + 1), ready))
|
||||
self.assertFalse(clear.started_late(warm_job("in_progress", started_at="2026-11-28T08:01:00Z"), ready))
|
||||
late = warm_job("in_progress", started_at=(ready + timedelta(seconds=clear.START_SECONDS + 1)).isoformat())
|
||||
self.assertTrue(clear.started_late(late, ready))
|
||||
|
||||
def test_without_split_legs_the_script_start_starts_the_wait(self):
|
||||
self.assertEqual(clear.start_wait_began([], self.began), self.began)
|
||||
self.assertEqual(clear.start_wait_began(ME + [warm_job("queued")], self.began), self.began)
|
||||
|
||||
def test_a_split_completion_without_a_timestamp_does_not_start_the_wait(self):
|
||||
self.assertIsNone(clear.start_wait_began([split_job(1, "completed")], self.began))
|
||||
|
||||
|
||||
class Workflow(unittest.TestCase):
|
||||
ci = (Path(__file__).resolve().parent.parent / ".github" / "workflows" / "ci.yml").read_text()
|
||||
@@ -116,10 +149,17 @@ class Workflow(unittest.TestCase):
|
||||
self.fail(f"no timeout-minutes under {job}")
|
||||
|
||||
def test_the_job_outlasts_the_start_wait_and_the_save_wait(self):
|
||||
# Five minutes are left for the steps before the script and for the deletion.
|
||||
# Without split legs, five minutes remain for setup and deletion.
|
||||
spare = self.timeout_minutes("cold-cache-clear") * 60 - clear.START_SECONDS - clear.GIVE_UP_SECONDS
|
||||
self.assertGreaterEqual(spare, 5 * 60)
|
||||
|
||||
def test_the_job_allows_both_warm_builds_within_the_hosted_job_limit(self):
|
||||
# Runner waits and the full start allowance may exceed the 360-minute job limit.
|
||||
timeout = self.timeout_minutes("cold-cache-clear")
|
||||
spare = timeout * 60 - self.timeout_minutes("gate") * 60 - clear.GIVE_UP_SECONDS
|
||||
self.assertGreaterEqual(spare, 5 * 60)
|
||||
self.assertEqual(timeout, 360)
|
||||
|
||||
def test_the_save_wait_outlasts_the_gate(self):
|
||||
self.assertGreater(clear.GIVE_UP_SECONDS, self.timeout_minutes("gate") * 60)
|
||||
|
||||
@@ -148,6 +188,9 @@ class Jobs(unittest.TestCase):
|
||||
self.assertTrue(clear.legs_stopped([done("gate / select legs", "success"), done("gate / build (ubuntu-24.04)", "cancelled")]))
|
||||
self.assertFalse(clear.legs_stopped([done("gate / select legs", "success"), done("gate / build (${{ matrix.os }})", "skipped")]))
|
||||
self.assertFalse(clear.legs_stopped([done("gate / test 1/5 (ubuntu-24.04)", "failure")]))
|
||||
# With warm-split, the saving `cache warm (<os>)` leg also needs every `cache warm <k>/<N>` leg.
|
||||
self.assertTrue(clear.legs_stopped([done("gate / cache warm 2/5 (ubuntu-24.04)", "failure")]))
|
||||
self.assertFalse(clear.legs_stopped([done("gate / cache warm 2/5 (ubuntu-24.04)", "success")]))
|
||||
|
||||
|
||||
class Caches(unittest.TestCase):
|
||||
@@ -184,6 +227,60 @@ class Clock(datetime):
|
||||
return datetime(2026, 11, 28, 4, 0, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
class BeforeSaving(unittest.TestCase):
|
||||
def run_main(self, polls):
|
||||
began = Clock.now()
|
||||
current = began
|
||||
remaining = iter(polls)
|
||||
|
||||
class PollClock(datetime):
|
||||
@classmethod
|
||||
def now(cls, tz=None):
|
||||
return current
|
||||
|
||||
def gh(url):
|
||||
nonlocal current
|
||||
if "/jobs?" in url:
|
||||
minutes, jobs = next(remaining)
|
||||
current = began + timedelta(minutes=minutes)
|
||||
return {"jobs": ME + jobs}
|
||||
if "/caches?" in url:
|
||||
return {"actions_caches": []}
|
||||
return {"run_started_at": began.isoformat()}
|
||||
|
||||
env = {"GITHUB_REPOSITORY": "storytold/vectorcraft", "GITHUB_RUN_ID": "1", "GITHUB_RUN_ATTEMPT": "1"}
|
||||
with mock.patch.object(clear, "gh", gh), mock.patch.object(clear.time, "sleep"), \
|
||||
mock.patch.object(clear, "datetime", PollClock), mock.patch.dict(os.environ, env), \
|
||||
mock.patch.object(clear.subprocess, "run") as delete, contextlib.redirect_stdout(io.StringIO()):
|
||||
status = clear.main()
|
||||
delete.assert_not_called()
|
||||
return status
|
||||
|
||||
def test_queued_and_running_split_legs_can_outlast_the_original_start_deadline(self):
|
||||
done = split_job(1, "completed", "2026-11-28T07:40:00Z")
|
||||
saved = warm_job("completed", "success", [("Post Setup", "completed", "success")],
|
||||
started_at="2026-11-28T07:50:00Z")
|
||||
self.assertFalse(self.run_main([
|
||||
(181, [split_job(1, "queued")]),
|
||||
(201, [split_job(1, "in_progress"), warm_job("queued")]),
|
||||
(220, [done, warm_job("queued")]),
|
||||
(230, [done, saved]),
|
||||
]))
|
||||
|
||||
def test_a_saving_leg_that_never_starts_expires_after_the_last_split_completion(self):
|
||||
done = split_job(1, "completed", "2026-11-28T07:40:00Z")
|
||||
self.assertEqual(self.run_main([
|
||||
(220, [done, warm_job("queued")]),
|
||||
(401, [done, warm_job("queued")]),
|
||||
]), 1)
|
||||
|
||||
def test_a_late_start_after_split_completion_is_rejected_even_if_already_saving(self):
|
||||
done = split_job(1, "completed", "2026-11-28T07:40:00Z")
|
||||
late = warm_job("in_progress", steps=[("Post Setup", "in_progress", None)],
|
||||
started_at="2026-11-28T10:40:01Z")
|
||||
self.assertEqual(self.run_main([(401, [done, late])]), 1)
|
||||
|
||||
|
||||
class AfterDeletion(unittest.TestCase):
|
||||
SAVING = [("Gate", "completed", "success"), ("Post Setup", "in_progress", None)]
|
||||
|
||||
@@ -222,9 +319,17 @@ class AfterDeletion(unittest.TestCase):
|
||||
canceled = warm_job("completed", "cancelled", [("Gate", "completed", "success"), ("Post Setup", "completed", "cancelled")])
|
||||
self.assertEqual(self.run_main(canceled), 1)
|
||||
|
||||
def test_a_saving_leg_skipped_after_a_failed_split_warm_leg_fails_this_job(self):
|
||||
skipped = warm_job("completed", conclusion="skipped")
|
||||
failed = {"name": "gate / cache warm 2/5 (ubuntu-24.04)", "status": "completed", "conclusion": "failure"}
|
||||
env = {"GITHUB_REPOSITORY": "storytold/vectorcraft", "GITHUB_RUN_ID": "1", "GITHUB_RUN_ATTEMPT": "1"}
|
||||
with mock.patch.object(clear, "gh", lambda url: {"jobs": ME + [failed, skipped]}), mock.patch.object(clear.time, "sleep"), \
|
||||
mock.patch.object(clear, "datetime", Clock), mock.patch.dict(os.environ, env), contextlib.redirect_stdout(io.StringIO()):
|
||||
self.assertEqual(clear.main(), 1)
|
||||
|
||||
def test_a_leg_that_starts_late_and_saves_deletes_nothing(self):
|
||||
# Clock.now() is 04:00, so the leg starts 120 minutes 5 seconds after the script.
|
||||
late = warm_job("in_progress", steps=self.SAVING, started_at="2026-11-28T06:00:05Z")
|
||||
# Clock.now() is 04:00, so the leg starts 180 minutes 5 seconds after the script.
|
||||
late = warm_job("in_progress", steps=self.SAVING, started_at="2026-11-28T07:00:05Z")
|
||||
deleted = []
|
||||
|
||||
def run(args, **kwargs):
|
||||
|
||||
@@ -16,8 +16,10 @@ save step started saves nothing: its old entries stay, and this exits 1, so "Re-
|
||||
runs it again beside the re-run leg. A save step that is canceled or fails after the old entries
|
||||
were deleted leaves no rolling entry, so the next run starts cold, and this exits 1 too. A failure
|
||||
in a later post step does not count once the save step has succeeded. This also exits 1 when the
|
||||
leg has not started START_SECONDS after this script started, and when the leg has not reached its
|
||||
save, or its save has not finished, GIVE_UP_SECONDS after the leg started. An absent warm leg is treated as finished only
|
||||
leg has not started START_SECONDS after the last split warm leg completed (or after this script
|
||||
started when there are no split legs). The start deadline does not expire while a split leg is
|
||||
queued or running. This exits 1 when the leg has not reached its save, or its save has not finished,
|
||||
GIVE_UP_SECONDS after the leg started. An absent warm leg is treated as finished only
|
||||
when the most recent earlier attempt that lists it reports success and the current attempt lists
|
||||
no `cache prune` job, which runs from the start of "Re-run all jobs". Otherwise this keeps polling
|
||||
because reusable-workflow dependencies may still be scheduling it.
|
||||
@@ -33,9 +35,11 @@ import time
|
||||
|
||||
REF = 'refs/heads/main'
|
||||
WARM_JOB = re.compile(r'^gate / cache warm \(')
|
||||
SPLIT_WARM_JOB = re.compile(r'^gate / cache warm \d+/\d+ \(')
|
||||
# The jobs the gate's legs need (craft-common-actions .github/workflows/gate.yml): when one of
|
||||
# them fails or is canceled, the legs are skipped and no warm leg is listed.
|
||||
NEEDED_JOBS = re.compile(r'^gate / (select legs$|build \()')
|
||||
# them fails or is canceled, the legs are skipped and no warm leg is listed. With `warm-split` the
|
||||
# saving leg also needs every `cache warm <k>/<N>` leg.
|
||||
NEEDED_JOBS = re.compile(r'^gate / (select legs$|build \(|cache warm \d+/\d+ \()')
|
||||
PRUNE_JOB = 'cache prune'
|
||||
ROLLING = '-gate-crates-'
|
||||
# The gate-setup action's post step, which saves the dependency cache (craft-common-actions
|
||||
@@ -46,12 +50,11 @@ PAGE_SIZE = 100
|
||||
# Longer than the gate's `timeout-minutes` in ci.yml and timed from the leg's own start, so a cold
|
||||
# leg that starts late and runs to its limit still reaches its save before this gives up.
|
||||
GIVE_UP_SECONDS = 160 * 60
|
||||
# How long the leg may take to start, timed from this script's start: the leg waits for
|
||||
# `gate / select legs` and then for a runner, which took 44 minutes on a push to main on
|
||||
# 2026-11-28. The `cold-cache-clear` job's `timeout-minutes` in ci.yml is longer than
|
||||
# START_SECONDS and GIVE_UP_SECONDS together, so this exits with its own error before the job
|
||||
# times out.
|
||||
START_SECONDS = 120 * 60
|
||||
# How long the saving leg may take to start after the last split warm leg completed, or after
|
||||
# this script started when there are no split legs. Queued or running split legs suspend this
|
||||
# deadline. The `cold-cache-clear` job's 360-minute timeout in ci.yml can end the wait before
|
||||
# this deadline or GIVE_UP_SECONDS expires when split builds or runner waits take too long.
|
||||
START_SECONDS = 180 * 60
|
||||
STOPPED = ('failure', 'cancelled', 'timed_out')
|
||||
# Steps with continue-on-error in craft-common-actions .github/workflows/gate.yml.
|
||||
TOLERATED_FAILURES = ('Trim the cache entry to this build',)
|
||||
@@ -97,16 +100,25 @@ def started_at(job):
|
||||
return parse_time(started) if started else None
|
||||
|
||||
|
||||
def start_wait_began(jobs, began):
|
||||
"""The last split warm completion, the script's start without splits, or None while waiting."""
|
||||
splits = [j for j in jobs if SPLIT_WARM_JOB.match(j['name'])]
|
||||
if not splits:
|
||||
return began
|
||||
if any(j['status'] != 'completed' or not j.get('completed_at') for j in splits):
|
||||
return None
|
||||
return max(parse_time(j['completed_at']) for j in splits)
|
||||
|
||||
|
||||
def start_overdue(job, now, began):
|
||||
"""True once START_SECONDS have passed since `began` (this script's start) and the warm leg
|
||||
has not started."""
|
||||
return started_at(job) is None and (now - began).total_seconds() > START_SECONDS
|
||||
"""True once START_SECONDS have passed since the start wait began and the leg has not started."""
|
||||
return began is not None and started_at(job) is None and (now - began).total_seconds() > START_SECONDS
|
||||
|
||||
|
||||
def started_late(job, began):
|
||||
"""True when the warm leg started more than START_SECONDS after `began` (this script's start)."""
|
||||
"""True when the warm leg started more than START_SECONDS after the start wait began."""
|
||||
started = started_at(job)
|
||||
return started is not None and (started - began).total_seconds() > START_SECONDS
|
||||
return began is not None and started is not None and (started - began).total_seconds() > START_SECONDS
|
||||
|
||||
|
||||
def gave_up(job, now):
|
||||
@@ -173,7 +185,8 @@ def main():
|
||||
while True:
|
||||
jobs = gh(jobs_url) or {}
|
||||
job = warm_job(jobs.get('jobs', []))
|
||||
if started_late(job, began):
|
||||
ready = start_wait_began(jobs.get('jobs', []), began)
|
||||
if started_late(job, ready):
|
||||
print(f'::error::the cache warm leg did not start within {START_SECONDS // 60} minutes; nothing deleted')
|
||||
return 1
|
||||
if job and saving(job):
|
||||
@@ -192,13 +205,14 @@ def main():
|
||||
print('::error::the gate stopped before its cache warm leg started; nothing deleted')
|
||||
return 1
|
||||
if job and job['status'] == 'completed':
|
||||
if job.get('conclusion') in STOPPED:
|
||||
# A saving leg skipped because a leg it needs failed (a `cache warm <k>/<N>` leg).
|
||||
if job.get('conclusion') in STOPPED or job.get('conclusion') == 'skipped' and legs_stopped(jobs.get('jobs', [])):
|
||||
print(f'::error::{NO_SAVE}')
|
||||
return 1
|
||||
print('the cache warm leg finished without a save step; nothing deleted')
|
||||
return
|
||||
now = datetime.now(timezone.utc)
|
||||
if start_overdue(job, now, began):
|
||||
if start_overdue(job, now, ready):
|
||||
print(f'::error::the cache warm leg did not start within {START_SECONDS // 60} minutes; nothing deleted')
|
||||
return 1
|
||||
if gave_up(job, now):
|
||||
|
||||
+28
-2
@@ -43,6 +43,7 @@ commands:
|
||||
ci shard shard $GATE_SHARD of $GATE_SHARDS of ci (xtask/src/shards.rs): a test shard runs
|
||||
the tests and doctests of its crates, the last shard the other steps
|
||||
ci warm build what every shard builds, without running it (fills the gate's cache); with
|
||||
GATE_SHARD of GATE_SHARDS set, only what that shard builds; with
|
||||
CRAFT_CACHE_UNITS set, appends Cargo's JSON messages for each build to that file
|
||||
shards list the crates each shard tests; fails when a member is in no shard or in two,
|
||||
or builds with other features in its shard than in the whole workspace
|
||||
@@ -354,13 +355,31 @@ fn cmd_ci_shard() -> Result<(), String> {
|
||||
/// features over the packages each command selects). The integration tests are left out: they
|
||||
/// build no dependency that the library tests do not, since both take the crate's dev-dependencies.
|
||||
///
|
||||
/// With `GATE_SHARD` and `GATE_SHARDS` set (the gate's split warm legs), it builds only what that
|
||||
/// shard builds: a test shard's tests, or the checks shard's builds.
|
||||
///
|
||||
/// In a leg that saves the cache, every build records its units in `CRAFT_CACHE_UNITS`
|
||||
/// (xtask/src/cache_units.rs), xtask's own build included.
|
||||
fn cmd_ci_warm() -> Result<(), String> {
|
||||
let var = |key: &str| match std::env::var(key) {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(std::env::VarError::NotPresent) => Ok(None),
|
||||
Err(std::env::VarError::NotUnicode(_)) => Err(format!("ci warm: {key} is not valid Unicode")),
|
||||
};
|
||||
let (shard, count) = (var("GATE_SHARD")?, var("GATE_SHARDS")?);
|
||||
let only = shards::warm_only(shard.as_deref(), count.as_deref())?;
|
||||
cache_units::record_xtask()?;
|
||||
let checked = shards::run()?;
|
||||
let builds = |i: usize| only.is_none_or(|k| k == i);
|
||||
let mut steps: Vec<Step> = Vec::new();
|
||||
for shard in checked {
|
||||
let mut checks = only.is_none();
|
||||
for (i, shard) in checked.into_iter().enumerate() {
|
||||
if !builds(i) {
|
||||
continue;
|
||||
}
|
||||
if shard == shards::Shard::Checks {
|
||||
checks = true;
|
||||
}
|
||||
if let shards::Shard::Tests(crates) = shard {
|
||||
steps.push((
|
||||
"build tests",
|
||||
@@ -372,6 +391,14 @@ fn cmd_ci_warm() -> Result<(), String> {
|
||||
));
|
||||
}
|
||||
}
|
||||
if checks {
|
||||
push_warm_checks(&mut steps);
|
||||
}
|
||||
run_steps(&steps)
|
||||
}
|
||||
|
||||
/// The builds of the checks shard that [`cmd_ci_warm`] runs.
|
||||
fn push_warm_checks(steps: &mut Vec<Step>) {
|
||||
steps.push((
|
||||
"clippy",
|
||||
Box::new(|| {
|
||||
@@ -395,7 +422,6 @@ fn cmd_ci_warm() -> Result<(), String> {
|
||||
}),
|
||||
));
|
||||
steps.push(("wasm", Box::new(cmd_wasm)));
|
||||
run_steps(&steps)
|
||||
}
|
||||
|
||||
/// Runs `steps` in turn, stopping at the first that fails; the summary names the steps that passed
|
||||
|
||||
@@ -214,10 +214,49 @@ pub fn run() -> Result<Vec<Shard>, String> {
|
||||
Ok(shards)
|
||||
}
|
||||
|
||||
/// The shard `cargo xtask ci warm` builds alone, as an index into [`GROUPS`], from the gate's
|
||||
/// `GATE_SHARD` and `GATE_SHARDS`: `None` (every shard) when neither is set. Setting only one,
|
||||
/// a value that is not a number, a count other than the number of shards, or a shard out of range
|
||||
/// is an error.
|
||||
pub fn warm_only(shard: Option<&str>, count: Option<&str>) -> Result<Option<usize>, String> {
|
||||
let (shard, count) = match (shard, count) {
|
||||
(None, None) => return Ok(None),
|
||||
(Some(shard), Some(count)) => (shard, count),
|
||||
_ => return Err("ci warm: GATE_SHARD and GATE_SHARDS are set together or not at all".into()),
|
||||
};
|
||||
let number =
|
||||
|key: &str, value: &str| -> Result<usize, String> { value.trim().parse().map_err(|_| format!("ci warm: {key} is `{value}`, not a number")) };
|
||||
let (shard, count) = (number("GATE_SHARD", shard)?, number("GATE_SHARDS", count)?);
|
||||
if count != GROUPS.len() {
|
||||
return Err(format!(
|
||||
"ci warm: GATE_SHARDS is {count}, and xtask/src/shards.rs has {} shards (test-shards in .github/workflows/ci.yml)",
|
||||
GROUPS.len()
|
||||
));
|
||||
}
|
||||
if !(1..=count).contains(&shard) {
|
||||
return Err(format!("ci warm: GATE_SHARD is {shard}, not 1 to {count}"));
|
||||
}
|
||||
Ok(Some(shard - 1))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn warm_builds_every_shard_unless_the_gate_names_one() {
|
||||
let n = GROUPS.len().to_string();
|
||||
assert_eq!(warm_only(None, None), Ok(None));
|
||||
assert_eq!(warm_only(Some("1"), Some(&n)), Ok(Some(0)));
|
||||
assert_eq!(warm_only(Some(&n), Some(&n)), Ok(Some(GROUPS.len() - 1)));
|
||||
for (shard, count) in [(Some("1"), None), (None, Some(n.as_str())), (Some("0"), Some(n.as_str())), (Some("x"), Some(n.as_str()))] {
|
||||
assert!(warm_only(shard, count).is_err(), "{shard:?} of {count:?}");
|
||||
}
|
||||
let past = (GROUPS.len() + 1).to_string();
|
||||
assert!(warm_only(Some(&past), Some(&n)).is_err());
|
||||
assert!(warm_only(Some("1"), Some(&past)).is_err());
|
||||
}
|
||||
|
||||
fn m(name: &str) -> Member {
|
||||
Member { name: name.into(), id: format!("path+file:///w/{name}#0.1.0"), version: "0.1.0".into() }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user