Skip to content

Commit 1804f89

Browse files
committed
chore: also bump rust-toolchain.toml from update.ts
Previously update.ts only updated `mago-formatter` / `mago-php-version` in Cargo.toml. When upstream mago bumped its declared rust-version (e.g. 1.29.0 -> 1.95.0), CI would silently end up trying to compile the new mago on the old toolchain — that's how this branch hit the bytes-API breakage. Match what dprint-plugin-ruff already does: fetch the new crate version's rust_version from crates.io and bump rust-toolchain.toml to match (only ever upgrading; never downgrading).
1 parent 002c437 commit 1804f89

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

scripts/update.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ if (hasPhpVersionUpdate) {
2727
$.log(` mago-php-version: ${currentVersions.phpVersion} -> ${latestVersions.phpVersion}`);
2828
}
2929

30+
$.logStep("Updating rust-toolchain.toml...");
31+
await updateRustToolchain(latestVersions.formatter);
32+
3033
$.logStep("Updating Cargo.toml...");
3134
const isPatchBump = hasFormatterUpdate
3235
? semver.parse(currentVersions.formatter).major === semver.parse(latestVersions.formatter).major
@@ -118,3 +121,32 @@ async function getLatestCrateVersion(crateName: string): Promise<string> {
118121
$.logLight(`Latest ${crateName} version on crates.io:`, latestVersion);
119122
return latestVersion;
120123
}
124+
125+
async function updateRustToolchain(formatterVersion: string) {
126+
const response = await fetch(`https://crates.io/api/v1/crates/mago-formatter/${formatterVersion}`);
127+
if (!response.ok) {
128+
throw new Error(`Failed to fetch mago-formatter ${formatterVersion} info: ${response.statusText}`);
129+
}
130+
const data = await response.json();
131+
const requiredRustVersion = data.version?.rust_version;
132+
if (requiredRustVersion == null) {
133+
$.log(`mago-formatter ${formatterVersion} does not declare a rust_version; leaving rust-toolchain.toml alone.`);
134+
return;
135+
}
136+
137+
const toolchainPath = rootDirPath.join("rust-toolchain.toml");
138+
const localContent = toolchainPath.readTextSync();
139+
const localMatch = localContent.match(/channel\s*=\s*"([^"]+)"/);
140+
if (localMatch == null) {
141+
throw new Error("Could not find channel in local rust-toolchain.toml.");
142+
}
143+
// only bump up; never downgrade. compare as semver so 1.95.0 > 1.92.0.
144+
const local = semver.parse(localMatch[1]);
145+
const required = semver.parse(requiredRustVersion);
146+
if (semver.greaterThan(required, local)) {
147+
$.log(`Updating Rust toolchain: ${localMatch[1]} -> ${requiredRustVersion}`);
148+
toolchainPath.writeTextSync(localContent.replace(localMatch[0], `channel = "${requiredRustVersion}"`));
149+
} else {
150+
$.log(`Rust toolchain at ${localMatch[1]} already satisfies mago-formatter ${formatterVersion} (needs >= ${requiredRustVersion}).`);
151+
}
152+
}

0 commit comments

Comments
 (0)