Skip to content

Commit

Permalink
ci: check that the specified msrv is tested correctly (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Dec 16, 2024
1 parent 3cdd9f2 commit 9d93e3b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,22 @@ jobs:
- run: cargo fmt --check --all
- run: cargo doc --workspace --no-deps

# region: check-min-version
min-version:
name: Check minimum Rust version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/[email protected]
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Check MSRV
run: yarn check-msrv
- uses: dtolnay/[email protected]
- uses: Swatinem/rust-cache@v2
- run: cargo check --workspace
# end-region: check-min-version

build:
strategy:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"docs:rs": "cargo doc --workspace --no-deps",
"test:grammar": "cd syntaxes/textmate && yarn run test",
"build:typlite": "cargo build --bin typlite",
"typlite": "target/debug/typlite"
"typlite": "target/debug/typlite",
"check-msrv": "node scripts/check-msrv.mjs"
},
"dependencies": {},
"devDependencies": {
Expand Down
39 changes: 39 additions & 0 deletions scripts/check-msrv.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import fs from 'fs';

const ciFile = fs.readFileSync('.github/workflows/release.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 ciCheck = checkMinVersion[0];
// dtolnay/[email protected]
const ciCheckedVersion = ciCheck.match(/dtolnay\/rust-toolchain@(\d+\.\d+\.\d+)/)[1];

const cargoToml = fs.readFileSync('Cargo.toml', 'utf-8');
// rust-version = "1.82"
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 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);
}

0 comments on commit 9d93e3b

Please sign in to comment.