Repository navigation
[Merged by Bors] - ci: upload the master cache to R2 from the upload_cache job - #43648
marcelolynch wants to merge 3 commits into
Conversation
PR summary 3d053b34e1Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
163ac34 to
c67067b
Compare
d2c46a9 to
739eced
Compare
5344d75 to
f2b1cb0
Compare
The upload_cache job uploads the staged set a second time, to the R2 bucket, with credentials the cache broker mints. Only the master container takes this path. The Azure upload runs first and is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
f2b1cb0 to
f96f1f9
Compare
Co-Authored-By: Claude Fable 5.1 <[email protected]>
| MATHLIB_CACHE_S3_REGION: auto | ||
| # The flat write puts `{url}/f/{hash}.ltar` under the bucket's `mathlib4/` | ||
| # prefix, which the cache resolver serves. | ||
| MATHLIB_CACHE_PUT_URL: ${{ secrets.MATHLIB_CACHE_R2_PUT_URL }} |
There was a problem hiding this comment.
Claude points out that a trailing slash here in the secret will cause a failure in s3EndpointSplit since it rejects empty path segments. Possibly worth a comment and hardening later on.
There was a problem hiding this comment.
Yeah I'm aware of this, will fix as a follow up
| exit 1 | ||
| fi | ||
| echo "Uploading cache to R2 (the bucket's master prefix)..." | ||
| if ! lake env "$CACHE_BIN" put-staged --backend=s3 --staging-dir="cache-staging" --repo="$REPO"; then |
There was a problem hiding this comment.
A warning from Claude:
--repo="$REPO" is load-bearing here in a way it isn't on the Azure leg. With MATHLIB_CACHE_PUT_URL set there's no container, so fileDirPath keys the layout on the repo (flat = repo == MATHLIBREPO) instead of on flatPath .master, which is repo-independent. Correct today, since MATHLIB_CACHE_PRIMARY == 'master' implies REPO == leanprover-community/mathlib4 — but any other repo would write f/{repo}/.ltar, which nothing reads, and the upload would still exit 0. That's a silent success rather than the tolerated warning this step knows how to emit.
runPut already defaults it (repo?.getD MATHLIBREPO), so dropping --repo pins the flat layout unconditionally and lets REPO come out of the step's env: too.
There was a problem hiding this comment.
Yep, this is a bit awkward but my next step here is to completely separate "developer cache" from "master cache" and then this will become cleaner
|
Thanks! |
This PR adds a second upload to the `upload_cache` job. After the Azure upload, the job uploads the same staged `.ltar` set to the R2 bucket behind the public cache service. The Azure upload is unchanged.
The R2 upload runs only for the `master` container: master pushes, bors `staging` builds, and `v4.*` release tags. Fork builds, dev-branch builds, and nightly-repository builds write other containers, so they skip it.
How the upload works:
1. A mint step runs the mathlib-ci action `mint-s3-credentials`. The action returns short-lived S3 credentials as masked step outputs.
2. An upload step runs `put-staged --backend=s3` on the same staging directory. The step maps the credentials into the cache tool's variables, so only that step holds them. It signs in the region `auto`, which R2 expects. It sets `MATHLIB_CACHE_PUT_URL` from the secret `MATHLIB_CACHE_R2_PUT_URL`, and the tool writes `{url}/f/{hash}.ltar`. With the secret set to `https://<account endpoint>/mathlib4-cache/mathlib4`, the files land under the bucket prefix `mathlib4/`, which the cache resolver serves for the `mathlib4` and `mathlib4-master` URL segments.
The job already declares the `cache-upload-master` environment for the Azure upload. The environment fixes the OIDC `sub` claim, and its branch policy admits only `master`, `staging`, and the `v4.*` tags. The mint step sends the same token, so the same policy gates it.
The Azure upload is the upload of record. When the mint fails, only the mint step fails (`continue-on-error`), and the upload step is skipped because the action's `success` output is unset. When the R2 upload fails, the step warns and the job succeeds (`continue-on-error`). A skipped or failed R2 upload leaves this run's files out of the bucket until a backfill adds them.
The repository variable `MATHLIB_CACHE_BROKER_URL` is the switch. It holds the credential endpoint that the action calls. When it is empty, the job runs the Azure upload only. The secret `MATHLIB_CACHE_R2_PUT_URL` names the destination. When it is unset, the upload step warns and exits without an upload.
Out of scope: a backfill of the files the bucket lacks, a verification of bucket reads, and a completeness marker. Uploads to `master` carry no scope, so the tool writes no marker.
Fork PRs run master's `build_template.yml`, so the CI of this PR does not exercise the change. `actionlint` reports one pre-existing item on the file, the `deployment: false` key, which master also has. #43378 validated the tool's S3 path, with the flat `MATHLIB_CACHE_PUT_URL` write, live against R2.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
Pull request successfully merged into master. Build succeeded: |
This PR adds a second upload to the
upload_cachejob. After the Azure upload, the job uploads the same staged.ltarset to the R2 bucket behind the public cache service. The Azure upload is unchanged.The R2 upload runs only for the
mastercontainer: master pushes, borsstagingbuilds, andv4.*release tags. Fork builds, dev-branch builds, and nightly-repository builds write other containers, so they skip it.How the upload works:
mint-s3-credentials. The action returns short-lived S3 credentials as masked step outputs.put-staged --backend=s3on the same staging directory. The step maps the credentials into the cache tool's variables, so only that step holds them. It signs in the regionauto, which R2 expects. It setsMATHLIB_CACHE_PUT_URLfrom the secretMATHLIB_CACHE_R2_PUT_URL, and the tool writes{url}/f/{hash}.ltar. With the secret set tohttps://<account endpoint>/mathlib4-cache/mathlib4, the files land under the bucket prefixmathlib4/, which the cache resolver serves for themathlib4andmathlib4-masterURL segments.The job already declares the
cache-upload-masterenvironment for the Azure upload. The environment fixes the OIDCsubclaim, and its branch policy admits onlymaster,staging, and thev4.*tags. The mint step sends the same token, so the same policy gates it.The Azure upload is the upload of record. When the mint fails, only the mint step fails (
continue-on-error), and the upload step is skipped because the action'ssuccessoutput is unset. When the R2 upload fails, the step warns and the job succeeds (continue-on-error). A skipped or failed R2 upload leaves this run's files out of the bucket until a backfill adds them.The repository variable
MATHLIB_CACHE_BROKER_URLis the switch. It holds the credential endpoint that the action calls. When it is empty, the job runs the Azure upload only. The secretMATHLIB_CACHE_R2_PUT_URLnames the destination. When it is unset, the upload step warns and exits without an upload.Out of scope: a backfill of the files the bucket lacks, a verification of bucket reads, and a completeness marker. Uploads to
mastercarry no scope, so the tool writes no marker.Fork PRs run master's
build_template.yml, so the CI of this PR does not exercise the change.actionlintreports one pre-existing item on the file, thedeployment: falsekey, which master also has. #43378 validated the tool's S3 path, with the flatMATHLIB_CACHE_PUT_URLwrite, live against R2.🤖 Generated with Claude Code