Skip to content

feat: use the GitHub CLI token for custom origins - #218

Merged
Kha merged 4 commits into
masterfrom
gh-token-discovery
Nov 30, 2026
Merged

Kha merged 4 commits into
masterfrom
gh-token-discovery

Conversation

@Kha

@Kha Kha commented Nov 30, 2026

Copy link
Copy Markdown
Member

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 than leanprover/lean4 when neither GH_TOKEN nor GITHUB_TOKEN is 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 lean or lake for a project using a toolchain from a private repository could not install that toolchain. With this change it works for anyone logged in via gh auth login.

This follows the design of Homebrew, which uses its token environment variable if set and otherwise asks gh auth token by default.

The environment variables take precedence, so gh is 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; installing leanprover/lean4 toolchains and the check for elan updates do not run it. A missing or logged-out gh is 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.toml or ELAN_GITHUB_TOKEN_SOURCE=none in the environment. The environment variable takes precedence over the setting, so ELAN_GITHUB_TOKEN_SOURCE=gh re-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 suggest gh auth login when no token was available.

Kha and others added 4 commits November 30, 2026 09:26
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
Kha enabled auto-merge (squash) November 30, 2026 09:44
@Kha
Kha merged commit 1ab5563 into master Nov 30, 2026
5 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant