The Lean Github ecosystem #
Documentation of the branches, tags, and CI workflows relevant for making pull requests to Lean, Batteries, and Mathlib.
- Things you need to know is relevant for everyone
- Tags and branches is for "experts only" who are making or fixing breaking changes in Lean, or who want to understand the inner workings of Mathlib CI.
Things you need to know #
-
If you are making a pull request to
leanprover/lean4which may involve breaking changes, please rebase your PR ontodownstream-greenand label itdownstream. This will create an adaptation PR inleanprover/downstream-lean4. -
If you are making a pull request to
leanprover-community/mathlib4, please make it from a fork. Mathlib's.oleancache now works with PRs from forks.
Tags and branches #
leanprover/lean4 #
- Development occurs on the
masterbranch. - Stable releases and release candidates have tags, e.g.
v4.2.0orv4.3.0-rc1.- To use one of these releases in a project, your
lean-toolchainfile should contain e.g.leanprover/lean4:v4.2.0.
- To use one of these releases in a project, your
- Stable releases usually arrive near the middle of the month, and are often identical to the last release candidate.
- The first release candidate of the next version is released immediately after the stable release.
- Each version has a
releases/v4.X.0feature branch, which may contain cherry-picked or backported commits frommaster. Release candidates are cut from this branch. - We cut a regular nightly release from
master, which has a tag likenightly-2023-11-01on theleanprover/lean4-nightlyrepository.- To use a nightly release in a project, your
lean-toolchainfile should contain e.g.leanprover/lean4:nightly-2023-11-01. (Note that it should not beleanprover/lean4-nightly:nightly-2023-11-01, becauseelanapplies some magic wisdom here.) - A nightly may be revised by manually triggering the release workflow. Revised nightlies
have tags of the form
nightly-YYYY-MM-DD-revK(with K starting at 1) onleanprover/lean4-nightly. To use a revised nightly in a project, yourlean-toolchainfile should contain e.g.leanprover/lean4:nightly-2023-11-01-rev1. Revised nightlies are ordered after the base nightly: base < rev1 < rev2 < next day's nightly. The Mathlib nightly testing infrastructure handles revised nightlies automatically.
- To use a nightly release in a project, your
- There is a
nightlybranch onleanprover/lean4which follows the most recent commit which was used to construct a nightly release. - Every PR automatically receives a toolchain after it builds successfully.
The PR will then have label
toolchain-available. To use PR #NNNN in a project, yourlean-toolchainfile should containleanprover/lean4-pr-releases:pr-release-NNNN. - For any PR that potentially breaks packages like Batteries or Mathlib, use a
downstream-lean4adaptation PR.- Base your PR off of the
downstream-greenbranch and label itdownstream. This creates an adaptation PR for your PR inleanprover/downstream-lean4where you can check for and fix breakages before your PR is merged. - If you have write access to
leanprover/downstream-lean4but have insufficient permissions to edit labels in your original PR, you can commentdownstreamon your original PR instead and CI will add the label. - If you don't have write access to
leanprover/downstream-lean4, you can request access on zulip in theecosystem infrastructurechannel.
- Base your PR off of the
leanprover-community/batteries (aka 'Batteries') #
- Development occurs on
main. - Batteries uses the latest stable release or release candidate in its
lean-toolchain.- Because we release
v4.X+1.0-rc1immediately after releasingv4.X.0, Batteries is only very briefly on stable releases.
- Because we release
- The first commit on
mainwhich uses a new toolchain is tagged with the version number of that toolchain (e.g.v4.2.0). - There is a branch
stablewhich follows thev4.X.Ytags. - Batteries has a branch
bump/v4.X.0for the upcoming stable release of Lean,- which contains adaptations for breaking changes that have been approved by the maintainers
- and which will be using a
leanprover-lean4:nightly-YYYY-MM-DDtoolchain.
- Batteries has a branch
nightly-testingwhich- uses a recent nightly release (this is updated automatically)
- has all commits from
mainmerged into it automatically - may have any changes from
bump/v4.X.0merged into it manually - may have any other commits, including unreviewed ones, required to keep the
nightly-testingbranch working against recent nightly releases.
- Failures in CI on the
nightly-testingbranch are reported by a bot to zulip in thenightly-testing-batterieschannel. - Success in CI on the
nightly-testingbranch results in the creation of a tagnightly-testing-YYYY-MM-DDto match that commit, if this tag does not already exist.- Thus if
nightly-testing-YYYY-MM-DDexists, we know that on it:- the
lean-toolchainisleanprover/lean4:nightly-YYYY-MM-DD, and - CI succeeds.
- the
- Thus if
- It is always allowed to merge
bump/v4.X.0intonightly-testing, but not conversely. (Changes tobump/v4.X.0have been reviewed, but changes tonightly-testingmay not have been.) - When it is time to update Batteries to a new Lean rc1,
hopefully all that is required is to make a new PR
consisting of squash merging
bump/v4.X.0tomain.
leanprover-community/mathlib4 (aka 'Mathlib') #
- Everything said above about Batteries applies to Mathlib, except:
- Development occurs on
master. nightly-testingstatus updates are posted in this thread in#nightly-testing-mathlib.- PRs to Mathlib should be made from forks. Mathlib's
.oleancache now works with PRs from forks.
- Development occurs on
- The
nightly-testing,nightly-testing-*tags, andbump/v4*branches all live atleanprover-community/mathlib4-nightly-testing, which is a fork of mathlib4. If you will regularly need write access to these branches, you can ask in thenightly-testing-mathlibchannel on Zulip to be added to thenightly-testingGitHub team. - Note that the
nightly-testingbranch of Mathlib may use thenightly-testingbranch of Batteries as required. - Similarly a
bump/v4.X.0branch of Mathlib may use thebump/v4.X.0branch of Batteries as required.
Mathlib nightly and bump branches #
Every month there is a new Lean release, and Mathlib aims to migrate to the new Lean release as soon as possible. To make this process as smooth as possible, we follow the following procedure:
- The
nightly-testingbranch lives atleanprover-community/mathlib4-nightly-testingand uses nightly toolchain releases of Lean. In other words, thelean-toolchainfile on that branch contains something likeleanprover/lean4:nightly-2024-09-26.- This branch is not guaranteed to build without errors.
- Changes to this branch are not reviewed by the Mathlib maintainer team.
- This branch is not protected: members of the
nightly-testingGitHub team can push fixes to it. - The purpose of this branch is to adapt Mathlib to changes in the nightly toolchain releases of Lean.
- Adaptations made in
leanprover/downstream-lean4will automatically be pushed here. - If CI fails on this branch, then it posts a message to "nightly-testing-mathlib > Mathlib status updates" on Zulip, indicating the failure.
- If CI passes on this branch, then a message is posted to the same thread, indicating success, and giving instructions to create a PR to review the adaptations. (See below.)
- The
nightly-testing-greenbranch inleanprover-community/mathlib4-nightly-testingtracks the last commit ofnightly-testingwhich built successfully. Tooling for builds ofnightly-testingis fetched from this branch. - The
bump/v4.X.Ybranches also live atleanprover-community/mathlib4-nightly-testingand use nightly toolchain releases of Lean.- This branch should always build without errors.
- Changes to this branch are reviewed by the Mathlib maintainer team.
- This branch is protected: only Mathlib maintainers and certain bots can push to it.
- The purpose of this branch is to prepare a parallel version of Mathlib's
masterbranch that builds on the upcoming version of Lean. Once that version is released, thebump/v4.X.Ybranch is merged intomaster. This merge is essentially atomic, since the diff has already been reviewed via all the daily adaptation PRs. (See below.)
- When
nightly-testingpasses CI, a bot posts to Zulip with instructions to create an "adaptation PR" to merge changes onnightly-testingintobump/v4.X.Y.- This PR can be prepared using
scripts/create-adaptation-pr.shas indicated in the Zulip message. - This PR should be reviewed by the Mathlib maintainer team.
- This PR can be prepared using
- Over the course of the Lean release cycle (i.e., a month),
bump/v4.X.Yaccumulates adaptations to the future Lean release.- But
masteralso accumulates thousands of lines of changes. - Hence
mastershould be merged intobump/v4.X.Yon a regular basis. - At the time of writing, this step is combined into the
scripts/create-adaptation-pr.shprocess. - Occasionally, merge conflicts occur. These ought to be reviewed by the Mathlib maintainer team, although that currently does not happen.
- But
The following image is slightly outdated as it still contains references to the now obsolete lean-pr-testing-NNNN branches.
Their role has been replaced by the leanprover/downstream-lean4 repository,
which automatically pushes adaptations developed inside itself to the nightly-testing branch as plain commits
(similar to any other contributor).
