Repository navigation
feat: use the GitHub CLI token for custom origins - #218
Merged
Merged
Conversation
When neither `GH_TOKEN` nor `GITHUB_TOKEN` is set, ask the GitHub CLI for a token using `gh auth token --hostname github.com` when accessing origins other than `leanprover/lean4`, so that toolchains from private repositories can be installed from editors and other contexts that do not inherit the shell environment. A missing or logged-out `gh` is the same as no token, and a token that does not work still falls back to the unauthenticated lookup. `gh` is run at most once per invocation and only when such an origin is about to be accessed; in particular the check for elan updates does not run it. It can be disabled using `github_token_source = "none"` in `settings.toml` or `ELAN_GITHUB_TOKEN_SOURCE=none` in the environment, where the environment variable takes precedence. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Kha
enabled auto-merge (squash)
November 30, 2026 09:44
downstream-lean4 Bot
added a commit
to leanprover/downstream-lean4
that referenced
this pull request
Nov 30, 2026
`elan` 4.5.0 reworded the access-token paragraph in the `DISCUSSION` section of `elan toolchain --help`. A token may now also come from the GitHub CLI (`gh auth token`), and `github_token_source` in `settings.toml` or `ELAN_GITHUB_TOKEN_SOURCE` turns that off (leanprover/elan#218). `Manual/BuildTools/Elan.lean` pins that output verbatim in its `elanHelp "toolchain"` block, so the block no longer matched. Update it to the 4.5.0 text, and extend the prose on origins and access tokens, which so far described only the two environment variables. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Kha
pushed a commit
to leanprover/downstream-lean4
that referenced
this pull request
Nov 30, 2026
Fixes the red `reference-manual` build in [run 46401259138](https://github.com/leanprover/downstream-lean4/actions/runs/46401259138). ## `reference-manual` elan v4.5.0, released on 2026-11-30 at 10:00Z, reworded the `DISCUSSION` section of `elan toolchain --help` (leanprover/elan#218). A token for a custom origin can now also come from the GitHub CLI, and `github_token_source` in `settings.toml` or `ELAN_GITHUB_TOKEN_SOURCE` turns that off. `Manual/BuildTools/Elan.lean` pins that output word for word in its `elanHelp "toolchain"` block, so the block stopped matching. This commit updates the block to the v4.5.0 text. It also extends the prose on origins and access tokens, which until now described only the two environment variables. The nightly bump is not the cause. CI installs the latest elan on every run, so [run 46398010865](https://github.com/leanprover/downstream-lean4/actions/runs/46398010865) at 10:13Z already used v4.5.0 and stayed green. That run unpacked `Manual.BuildTools.Elan` from the cache, so the comparison never ran. The toolchain bump changed the cache scope, the module compiled again, and the mismatch appeared. Every new elan release does this at the next cache miss. ## What passed locally `lake build` of `reference-manual` completes with 1689 jobs, the same count as CI, with elan 4.5.0 first on `PATH`. That build replayed the edited module from a local artifact. `Manual.BuildTools.Elan` was therefore also compiled on its own after a source perturbation, which runs the comparison against elan 4.5.0 for real. It passed in 1.8s with no diagnostics. `reference-manual` defines no test and no lint phase, so `build` is the only phase. The build report of the last green run records both of the others as skipped. Nothing was left unfinished. This one module was the whole red set of the run. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- downstream-watch: unattended --> Co-authored-by: downstream-lean4[bot] <downstream-lean4[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes elan use the token of the GitHub CLI (
gh auth token), if it is installed and logged in, for accessing origins other thanleanprover/lean4when neitherGH_TOKENnorGITHUB_TOKENis set.#217 added support for tokens from the environment, which is sufficient in CI but not where elan does not inherit the shell environment. In particular, an editor that starts
leanorlakefor a project using a toolchain from a private repository could not install that toolchain. With this change it works for anyone logged in viagh auth login.This follows the design of Homebrew, which uses its token environment variable if set and otherwise asks
gh auth tokenby default.The environment variables take precedence, so
ghis never run when one of them is set. Otherwise it is run at most once per invocation, and only when a non-default origin is about to be accessed; installingleanprover/lean4toolchains and the check for elan updates do not run it. A missing or logged-outghis the same as no token, and as before, elan falls back to the unauthenticated lookup if the token does not work for an origin.To never ask the GitHub CLI, set
github_token_source = "none"in~/.elan/settings.tomlorELAN_GITHUB_TOKEN_SOURCE=nonein the environment. The environment variable takes precedence over the setting, soELAN_GITHUB_TOKEN_SOURCE=ghre-enables it. There is no subcommand for changing the setting.Error messages for releases that cannot be found now say whether the token used came from the environment or from
gh auth token, and suggestgh auth loginwhen no token was available.