mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge pull request #10254 from dotCooCoo/fix/ci-drop-prune-watcher
CI: drop the cache prune watcher job; cache-prune.yml prunes after each run
This commit is contained in:
4 files changed
+38
-50
No files matched your search
@@ -1,11 +1,10 @@
|
||||
name: Cache prune
|
||||
|
||||
# A pass of the cache prune after every CI attempt on main. ci.yml's `cache prune` job prunes while
|
||||
# a run's jobs save their entries, but "Re-run failed jobs" re-runs only the failed jobs: a re-run
|
||||
# `cache warm` leg saves a new entry, and the prune job, which succeeded in the first attempt, does
|
||||
# not run again. The entry it replaced would stay until the next main run, and with it the cache
|
||||
# would be over its 10 GB budget, where GitHub evicts entries a run still needs. This runs once
|
||||
# after every attempt, re-runs and canceled runs included (craft-common-actions actions/cache-prune).
|
||||
# Keeps one rolling gate entry on main, so the repository stays within its 10 GB Actions cache
|
||||
# budget, where GitHub evicts entries a run still needs. Each main CI attempt's `cache warm` leg
|
||||
# saves a new rolling entry; this deletes the entry it replaced once the attempt ends. It runs once
|
||||
# after every attempt, re-runs of failed jobs and canceled runs included (craft-common-actions
|
||||
# actions/cache-prune).
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: [CI]
|
||||
|
||||
@@ -50,8 +50,8 @@ jobs:
|
||||
# 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
|
||||
# `cache-prune` below deletes the one it replaced. The nightly run restores nothing and
|
||||
# builds everything from source.
|
||||
# cache-prune.yml deletes the one it replaced after each attempt. The nightly run restores
|
||||
# nothing and builds everything from source.
|
||||
cache-workspace-crates: true
|
||||
cold-build: ${{ github.event_name == 'schedule' }}
|
||||
packages: >-
|
||||
@@ -59,32 +59,6 @@ jobs:
|
||||
libxrandr-dev libxi-dev libfontconfig1-dev libfreetype-dev mesa-vulkan-drivers
|
||||
libgl1-mesa-dev
|
||||
|
||||
# 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.
|
||||
cache-prune:
|
||||
name: cache prune
|
||||
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 170
|
||||
permissions:
|
||||
actions: write
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
- name: Prune replaced cache entries
|
||||
uses: storytold/craft-common-actions/actions/cache-prune@main
|
||||
continue-on-error: true
|
||||
with:
|
||||
watch: true
|
||||
watch-minutes: 160
|
||||
saving-jobs: |
|
||||
^gate( / cache warm \(.*\))?$
|
||||
|
||||
# The nightly cold run never restores the rolling crates entry, so the old entry is only overlap
|
||||
# while the cold run saves its own: two entries of about 4.6 GB, which with the others go over the
|
||||
# 10 GB cache limit and get the corpus, SonarCloud and Windows ARM64 entries evicted. This deletes
|
||||
|
||||
@@ -129,18 +129,26 @@ class Jobs(unittest.TestCase):
|
||||
jobs = [{"name": "gate / test 1/5 (ubuntu-24.04)"}, {"name": "gate / build (${{ matrix.os }})"}, {"name": WARM}]
|
||||
self.assertEqual(clear.warm_job(jobs), jobs[2])
|
||||
|
||||
def test_a_rerun_of_this_job_alone_skips_a_leg_that_succeeded(self):
|
||||
self.assertTrue(clear.not_in_attempt(ME, {1: earlier("success")}))
|
||||
self.assertTrue(clear.not_in_attempt(ME, {1: earlier("success"), 2: [{"name": "cold cache clear"}]}))
|
||||
self.assertTrue(clear.not_in_attempt(ME, {1: earlier("failure"), 2: [{"name": "cold cache clear"}], 3: earlier("success")}))
|
||||
def test_a_rerun_of_failed_jobs_skips_a_leg_that_succeeded(self):
|
||||
grace = clear.RERUN_GRACE_SECONDS
|
||||
failed_shard = [{"name": "gate / test 3/6 (ubuntu-24.04)", "status": "in_progress"}]
|
||||
self.assertTrue(clear.not_in_attempt(ME, {1: earlier("success")}, grace))
|
||||
self.assertTrue(clear.not_in_attempt(ME + failed_shard, {1: earlier("success")}, grace))
|
||||
self.assertTrue(clear.not_in_attempt(ME, {1: earlier("success"), 2: [{"name": "cold cache clear"}]}, grace))
|
||||
self.assertTrue(clear.not_in_attempt(ME, {1: earlier("failure"), 2: [{"name": "cold cache clear"}], 3: earlier("success")}, grace))
|
||||
|
||||
def test_an_attempt_is_watched_for_the_grace_period_first(self):
|
||||
self.assertFalse(clear.not_in_attempt(ME, {1: earlier("success")}, clear.RERUN_GRACE_SECONDS - 1))
|
||||
|
||||
def test_a_leg_that_did_not_succeed_is_waited_for(self):
|
||||
self.assertFalse(clear.not_in_attempt(ME, {1: earlier("cancelled")}))
|
||||
self.assertFalse(clear.not_in_attempt(ME, {}))
|
||||
self.assertFalse(clear.not_in_attempt(ME, {1: earlier("success"), 2: earlier("failure")}))
|
||||
grace = clear.RERUN_GRACE_SECONDS
|
||||
self.assertFalse(clear.not_in_attempt(ME, {1: earlier("cancelled")}, grace))
|
||||
self.assertFalse(clear.not_in_attempt(ME, {}, grace))
|
||||
self.assertFalse(clear.not_in_attempt(ME, {1: earlier("success"), 2: earlier("failure")}, grace))
|
||||
|
||||
def test_a_rerun_of_all_jobs_is_waited_for(self):
|
||||
self.assertFalse(clear.not_in_attempt(ME + [{"name": "cache prune", "status": "in_progress"}], {1: earlier("success")}))
|
||||
select = [{"name": "gate / select legs", "status": "queued"}]
|
||||
self.assertFalse(clear.not_in_attempt(ME + select, {1: earlier("success")}, clear.GIVE_UP_SECONDS))
|
||||
|
||||
def test_a_failed_select_or_build_stops_the_wait(self):
|
||||
done = lambda n, c: {"name": n, "status": "completed", "conclusion": c}
|
||||
|
||||
@@ -18,9 +18,10 @@ were deleted leaves no rolling entry, so the next run starts cold, and this exit
|
||||
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
|
||||
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.
|
||||
when the most recent earlier attempt that lists it reports success and the current attempt still
|
||||
lists no `gate / select legs` job RERUN_GRACE_SECONDS after this script started: "Re-run all
|
||||
jobs" lists that job from its start, and "Re-run failed jobs" after a successful leg does not.
|
||||
Otherwise this keeps polling because reusable-workflow dependencies may still be scheduling it.
|
||||
"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
@@ -36,7 +37,12 @@ WARM_JOB = re.compile(r'^gate / cache warm \(')
|
||||
# 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 \()')
|
||||
PRUNE_JOB = 'cache prune'
|
||||
# The gate's first job. "Re-run all jobs" lists it; "Re-run failed jobs" lists it only when it
|
||||
# failed, and then no warm leg succeeded before.
|
||||
SELECT_JOB = 'gate / select legs'
|
||||
# How long an attempt that does not list SELECT_JOB is watched before the warm leg counts as
|
||||
# finished in an earlier attempt.
|
||||
RERUN_GRACE_SECONDS = 5 * 60
|
||||
ROLLING = '-gate-crates-'
|
||||
# The gate-setup action's post step, which saves the dependency cache (craft-common-actions
|
||||
# actions/gate-setup, under the gate's `Setup` step).
|
||||
@@ -135,9 +141,10 @@ def legs_stopped(jobs):
|
||||
return any(NEEDED_JOBS.match(j['name']) and j['status'] == 'completed' and j.get('conclusion') in STOPPED for j in jobs)
|
||||
|
||||
|
||||
def not_in_attempt(jobs, earlier_jobs):
|
||||
"""True when no prune job is listed and the most recent earlier warm leg succeeded."""
|
||||
if any(j['name'] == PRUNE_JOB for j in jobs):
|
||||
def not_in_attempt(jobs, earlier_jobs, waited):
|
||||
"""True when SELECT_JOB is not listed `waited` seconds after this script started, at least
|
||||
RERUN_GRACE_SECONDS, and the most recent earlier warm leg succeeded."""
|
||||
if waited < RERUN_GRACE_SECONDS or any(j['name'] == SELECT_JOB for j in jobs):
|
||||
return False
|
||||
for attempt in sorted(earlier_jobs, reverse=True):
|
||||
job = warm_job(earlier_jobs[attempt])
|
||||
@@ -185,7 +192,7 @@ def main():
|
||||
earlier_jobs[earlier] = previous.get('jobs', [])
|
||||
if warm_job(earlier_jobs[earlier]) is not None:
|
||||
break
|
||||
if not_in_attempt(jobs.get('jobs', []), earlier_jobs):
|
||||
if not_in_attempt(jobs.get('jobs', []), earlier_jobs, (datetime.now(timezone.utc) - began).total_seconds()):
|
||||
print('the cache warm leg is not part of this attempt (it succeeded in an earlier one); nothing deleted')
|
||||
return
|
||||
if legs_stopped(jobs.get('jobs', [])):
|
||||
|
||||
Reference in new issue
Block a user