From 91263f8581bd317149069dbf22014cc1031ee4f2 Mon Sep 17 00:00:00 2001 From: Kaileshwar16 Date: Sun, 8 Nov 2026 19:34:57 +0530 Subject: [PATCH] feat(dist): add installer release metadata updater --- ci/update-rustup-init.py | 43 ++++++++++++++++++++++++++++ doc/dev-guide/src/release-process.md | 12 ++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 ci/update-rustup-init.py diff --git a/ci/update-rustup-init.py b/ci/update-rustup-init.py new file mode 100644 index 0000000000..098634cd02 --- /dev/null +++ b/ci/update-rustup-init.py @@ -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 /") + +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}") diff --git a/doc/dev-guide/src/release-process.md b/doc/dev-guide/src/release-process.md index adec1c0f41..6dcdeceed4 100644 --- a/doc/dev-guide/src/release-process.md +++ b/doc/dev-guide/src/release-process.md @@ -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