mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-12-15 21:13:56 +00:00
feat(ci): use rust-toolchain.toml (#1406)
* feat(ci): use `rust-toolchain.toml` * test: check toolchain * fix: again * fix: name
This commit is contained in:
parent
1c313e4d7f
commit
208ce3dbad
4 changed files with 63 additions and 56 deletions
|
|
@ -1,39 +1,46 @@
|
|||
import fs from 'fs';
|
||||
import fs from "fs";
|
||||
|
||||
const ciFile = fs.readFileSync('.github/workflows/release-vscode.yml', 'utf-8');
|
||||
const ciFile = fs.readFileSync(".github/workflows/release-vscode.yml", "utf-8");
|
||||
|
||||
const checkMinVersion = ciFile.match(/# region: check-min-version([\s\S]+?)# end-region: check-min-version/mg);
|
||||
if (!checkMinVersion) {
|
||||
console.error('Check minimum version not found');
|
||||
process.exit(1);
|
||||
const toolchainRe = (forWhat) =>
|
||||
new RegExp(/dtolnay\/rust-toolchain@(\d+\.\d+\.\d+)/.source + `\\s*#\\s*${forWhat}`);
|
||||
|
||||
const ciCheckedVersion = ciFile.match(toolchainRe("check-min-version"))?.[1];
|
||||
if (!ciCheckedVersion) {
|
||||
console.error("Check minimum version not found");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const ciCheck = checkMinVersion[0];
|
||||
// dtolnay/rust-toolchain@1.83.0
|
||||
const ciCheckedVersion = ciCheck.match(/dtolnay\/rust-toolchain@(\d+\.\d+\.\d+)/)[1];
|
||||
|
||||
const cargoToml = fs.readFileSync('Cargo.toml', 'utf-8');
|
||||
// rust-version = "1.82"
|
||||
const cargoToml = fs.readFileSync("Cargo.toml", "utf-8");
|
||||
const cargoSpecifiedVersion = cargoToml.match(/rust-version = "(\d+\.\d+)"/)[1];
|
||||
|
||||
function parseVersion(version) {
|
||||
const versions = version.split('.').map(Number);
|
||||
if (versions.length === 2) {
|
||||
versions.push(0);
|
||||
}
|
||||
if (versions.length !== 3) {
|
||||
throw new Error(`Invalid version: ${version}`);
|
||||
}
|
||||
return versions;
|
||||
const versions = version.split(".").map(Number);
|
||||
if (versions.length === 2) {
|
||||
versions.push(0);
|
||||
}
|
||||
if (versions.length !== 3) {
|
||||
throw new Error(`Invalid version: ${version}`);
|
||||
}
|
||||
return versions;
|
||||
}
|
||||
|
||||
function versionLess(a, b) {
|
||||
if (a.length !== 3 || b.length !== 3) {
|
||||
throw new Error("Invalid version to compare");
|
||||
}
|
||||
|
||||
return (
|
||||
a[0] < b[0] || (a[0] === b[0] && a[1] < b[1]) || (a[0] === b[0] && a[1] === b[1] && a[2] < b[2])
|
||||
);
|
||||
}
|
||||
|
||||
const specified = parseVersion(cargoSpecifiedVersion);
|
||||
const checked = parseVersion(ciCheckedVersion);
|
||||
if (
|
||||
specified[0] < checked[0] ||
|
||||
(specified[0] === checked[0] && specified[1] < checked[1]) ||
|
||||
(specified[0] === checked[0] && specified[1] === checked[1] && specified[2] < checked[2])
|
||||
) {
|
||||
console.error(`Specified version ${cargoSpecifiedVersion} is less than checked version ${ciCheckedVersion}`);
|
||||
process.exit(1);
|
||||
|
||||
if (versionLess(specified, checked)) {
|
||||
console.error(
|
||||
`Specified version ${cargoSpecifiedVersion} is less than checked version ${ciCheckedVersion}`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue