|
33 | 33 | # federated credential is scoped to; it must match the writer `cache_application_id`. |
34 | 34 | type: string |
35 | 35 | required: true |
| 36 | + publish_cache: |
| 37 | + # On a successful build, publish this run's `.ltar` set as `cache-snapshot`. |
| 38 | + # Set by callers ONLY for the master-`push` build — the single producer. |
| 39 | + type: boolean |
| 40 | + required: false |
| 41 | + default: false |
36 | 42 |
|
37 | 43 | env: |
38 | 44 | # Disable Lake's automatic fetching of cloud builds. |
|
51 | 57 | archive-outcome: ${{ steps.archive.outcome }} |
52 | 58 | counterexamples-outcome: ${{ steps.counterexamples.outcome }} |
53 | 59 | cache-staging-has-files: ${{ steps.cache_staging_check.outputs.has_files }} |
54 | | - get-cache-outcome: ${{ steps.get.outcome }} |
55 | 60 | lint-outcome: ${{ steps.lint.outcome }} |
56 | 61 | mk_all-outcome: ${{ steps.mk_all.outcome }} |
57 | 62 | noisy-outcome: ${{ steps.noisy.outcome }} |
@@ -313,95 +318,12 @@ jobs: |
313 | 318 | echo "✅ All inputRevs in lake-manifest.json are valid" |
314 | 319 | fi |
315 | 320 |
|
316 | | - - name: get cache (1/3 - setup and initial fetch) |
317 | | - id: get_cache_part1_setup |
318 | | - shell: bash # only runs `cache get` from `tools-branch`, so doesn't need to be inside landrun |
319 | | - run: | |
320 | | - cd pr-branch |
321 | | - echo "Removing old Mathlib build directories prior to cache fetch..." |
322 | | - rm -rf .lake/build/lib/lean/Mathlib |
323 | | -
|
324 | | - # Fail quickly if the cache is completely cold, by checking for Mathlib.Init |
325 | | - echo "Attempting to fetch olean for Mathlib/Init.lean from cache..." |
326 | | - ../tools-branch/.lake/build/bin/cache get Mathlib/Init.lean |
327 | | -
|
328 | | - - name: get cache (2/3 - test Mathlib.Init cache) |
329 | | - id: get_cache_part2_test |
330 | | - continue-on-error: true # Allow workflow to proceed to Part 3 to check outcome |
331 | | - # This step uses the job's default shell, which is landrun-wrapped bash |
332 | | - run: | |
333 | | - cd pr-branch |
334 | | -
|
335 | | - echo "Attempting: lake build --no-build -v Mathlib.Init (this runs under landrun)" |
336 | | - lake build --no-build -v Mathlib.Init |
337 | | -
|
338 | | - - name: get cache (3/3 - finalize cache operation) |
339 | | - id: get |
340 | | - shell: bash # only runs git and `cache get` from `tools-branch`, so doesn't need to be inside landrun |
341 | | - env: |
342 | | - BEFORE_SHA: ${{ github.event.before || '' }} |
343 | | - BASE_SHA: ${{ github.event.pull_request.base.sha || '' }} |
344 | | - CACHE_REPO: ${{ github.event.pull_request.head.repo.full_name || github.repository }} |
345 | | - run: | |
346 | | - cd pr-branch |
347 | | - if [[ "${{ steps.get_cache_part2_test.outcome }}" != "success" ]]; then |
348 | | - echo "WARNING: 'lake build --no-build -v Mathlib.Init' failed." |
349 | | - echo "No cache for 'Mathlib.Init' available or it could not be prepared." |
350 | | - exit 0 |
351 | | - fi |
352 | | -
|
353 | | - ORIG_SHA="$(git rev-parse HEAD)" |
354 | | - PREV_SHA="" |
355 | | - PREV_SHA_SOURCE="" |
356 | | -
|
357 | | - # When a ref is newly created, github.event.before can be all-zero. |
358 | | - if [[ "$BEFORE_SHA" =~ ^0{40}$ ]]; then |
359 | | - BEFORE_SHA="" |
360 | | - fi |
361 | | -
|
362 | | - if [[ -n "$BEFORE_SHA" ]]; then |
363 | | - PREV_SHA="$BEFORE_SHA" |
364 | | - PREV_SHA_SOURCE="github.event.before" |
365 | | - elif [[ -n "$BASE_SHA" ]]; then |
366 | | - PREV_SHA="$BASE_SHA" |
367 | | - PREV_SHA_SOURCE="pull_request.base.sha" |
368 | | - else |
369 | | - PREV_SHA="$(git rev-parse --verify --quiet HEAD^ || true)" |
370 | | - if [[ -n "$PREV_SHA" ]]; then |
371 | | - PREV_SHA_SOURCE="HEAD^" |
372 | | - fi |
373 | | - fi |
374 | | -
|
375 | | - if [[ -n "$PREV_SHA" ]]; then |
376 | | - # cf. https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Mathlib.20has.20moved.20to.20the.20new.20module.20system/near/563452000 |
377 | | - echo "Warming up cache using previous commit: $PREV_SHA (source: $PREV_SHA_SOURCE)" |
378 | | - if git cat-file -e "$PREV_SHA^{commit}" 2>/dev/null || git fetch --no-tags --depth=1 origin "$PREV_SHA"; then |
379 | | - # Skip warmup if the previous commit uses a different toolchain |
380 | | - PREV_TOOLCHAIN=$(git show "$PREV_SHA:lean-toolchain" 2>/dev/null || true) |
381 | | - if [[ "$PREV_TOOLCHAIN" != "$(cat lean-toolchain)" ]]; then |
382 | | - echo "Previous commit $PREV_SHA uses a different toolchain ($PREV_TOOLCHAIN); skipping warmup." |
383 | | - else |
384 | | - git checkout "$PREV_SHA" |
385 | | - ../tools-branch/.lake/build/bin/cache get |
386 | | - # Run again with --repo, to ensure we actually get the oleans. |
387 | | - ../tools-branch/.lake/build/bin/cache --repo="$CACHE_REPO" get |
388 | | -
|
389 | | - echo "Switching back to branch head" |
390 | | - git checkout "$ORIG_SHA" |
391 | | - fi |
392 | | - else |
393 | | - echo "Could not fetch $PREV_SHA; skipping parent warmup cache fetch." |
394 | | - fi |
395 | | - else |
396 | | - echo "No previous commit candidate found; skipping parent warmup cache fetch." |
397 | | - fi |
398 | | -
|
399 | | - echo "Fetching all remaining cache..." |
400 | | -
|
401 | | - ../tools-branch/.lake/build/bin/cache get |
402 | | -
|
403 | | - # Run again with --repo, to ensure we actually get the oleans. |
404 | | - ../tools-branch/.lake/build/bin/cache --repo="$CACHE_REPO" get |
| 321 | + # Get this commit's oleans into the local cache — see the action for the steps. |
| 322 | + - name: Get cache |
| 323 | + uses: ./workflow-actions/.github/actions/get-cache |
| 324 | + with: |
| 325 | + working_directory: pr-branch |
| 326 | + cache_bin: ../tools-branch/.lake/build/bin/cache |
405 | 327 |
|
406 | 328 | - name: update {Mathlib, Tactic, Counterexamples, Archive}.lean |
407 | 329 | id: mk_all |
@@ -522,6 +444,30 @@ jobs: |
522 | 444 | name: cache-staging |
523 | 445 | path: cache-staging/ |
524 | 446 |
|
| 447 | + # Prune to this commit's `.ltar` set so the published snapshot is exactly master's |
| 448 | + # current cache (the local dir also holds the previous snapshot it warmed from). |
| 449 | + - name: prune local cache to this commit's set |
| 450 | + if: ${{ inputs.publish_cache && steps.build.outcome == 'success' }} |
| 451 | + continue-on-error: true # best-effort; never fail the build |
| 452 | + shell: bash # runs the trusted tools-branch `cache` binary, so no landrun needed |
| 453 | + run: | |
| 454 | + cd pr-branch |
| 455 | + ../tools-branch/.lake/build/bin/cache clean |
| 456 | +
|
| 457 | + # Publish this run's pruned `.ltar` set as `cache-snapshot` for other runs to warm |
| 458 | + # from. Already on disk (no Azure egress) and already zstd-compressed (skip |
| 459 | + # recompression); retention covers how far back a PR's merge-base can be matched. |
| 460 | + - name: upload cache snapshot warming artifact |
| 461 | + if: ${{ inputs.publish_cache && steps.build.outcome == 'success' }} |
| 462 | + continue-on-error: true # best-effort; never fail the build |
| 463 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 464 | + with: |
| 465 | + name: cache-snapshot |
| 466 | + path: /home/lean/.cache/mathlib/*.ltar |
| 467 | + compression-level: 0 |
| 468 | + retention-days: 14 |
| 469 | + if-no-files-found: warn |
| 470 | + |
525 | 471 | - name: Check if building Archive or Counterexamples failed |
526 | 472 | if: steps.archive.outcome == 'failure' || steps.counterexamples.outcome == 'failure' |
527 | 473 | run: | |
|
0 commit comments