Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions ci/update-rustup-init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import re
import subprocess
import sys
import tomllib
from pathlib import Path

if len(sys.argv) != 2:
sys.exit("usage: python3 ci/update-rustup-init.py <remote>/<main|release/X.Y>")

release_branch = sys.argv[1]
if not re.fullmatch(r"[^/]+/(main|release/[0-9]+\.[0-9]+)", release_branch):
sys.exit("expected a remote-tracking main or release/X.Y branch")

try:
# Resolve the source once so all metadata comes from the same commit, not HEAD.
commit, commit_date = subprocess.check_output(
["git", "show", "--no-patch", "--format=%H %cs", f"refs/remotes/{release_branch}", "--"],
text=True,
).split()
manifest = subprocess.check_output(
["git", "show", f"{commit}:Cargo.toml"], text=True
)
version = tomllib.loads(manifest)["package"]["version"]
except (subprocess.CalledProcessError, tomllib.TOMLDecodeError, KeyError) as error:
sys.exit(f"cannot read release metadata from {release_branch}: {error}")
if not isinstance(version, str) or not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", version):
sys.exit("expected package.version in the release source to be X.Y.Z")

installer = Path("rustup-init.sh")
contents = installer.read_bytes()
metadata_lines = list(re.finditer(rb"^rustup-init .*$", contents, re.MULTILINE))
if len(metadata_lines) != 1 or not re.fullmatch(
rb"rustup-init [0-9]+\.[0-9]+\.[0-9]+ \([0-9a-f]{7,40} [0-9]{4}-[0-9]{2}-[0-9]{2}\)",
metadata_lines[0].group(),
):
sys.exit("expected exactly one rustup-init version/SHA/date line in rustup-init.sh")

metadata = f"rustup-init {version} ({commit[:9]} {commit_date})"
metadata_line = metadata_lines[0]
updated = contents[:metadata_line.start()] + metadata.encode() + contents[metadata_line.end():]
if updated != contents:
installer.write_bytes(updated)
print(f"{release_branch} ({commit}): {metadata}")
12 changes: 9 additions & 3 deletions doc/dev-guide/src/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,15 @@ new [b]eta release or an official [r]elease:
`$VER_NUM` already exists in `$BRANCH`'s `Cargo.toml` file. Then in a new PR
targeting `$BRANCH`:
1. Update `CHANGELOG.md` accordingly if necessary.
2. Update `rustup-init.sh` so that:
- The version number matches `$VER_NUM`.
- The commit shasum matches the latest commit on `$BRANCH`.
2. From the repository root, update `rustup-init.sh` using Python 3.11 or newer
and a freshly fetched remote-tracking `$BRANCH` (replace `upstream` with
your remote for `rust-lang/rustup`):
```console
$ git fetch upstream
$ python3 ci/update-rustup-init.py upstream/$BRANCH
```
This reads the version from that commit's `Cargo.toml` and its SHA and
commit date, even when the current branch contains release preparation changes.
3. Update the test snapshot of `rustup-init.sh --help`.
At the moment of writing, this is done by running:
```console
Expand Down
Loading