Skip to content

Commit fd5043d

Browse files
authored
Merge pull request #22 from Seasawher/develop
rewrite `getLatest.ps1` in JavaScript
2 parents 2e93dd9 + bdf0f84 commit fd5043d

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ runs:
6868
- name: Update lean-toolchain
6969
run: |
7070
cd ${{ inputs.lake-package-directory }}
71-
${{ github.action_path }}/scripts/getLatest.ps1
71+
node ${{ github.action_path }}/scripts/getLatest.js
7272
env:
7373
GH_TOKEN: ${{ github.token }}
74-
shell: pwsh
74+
shell: bash
7575

7676
- name: Install elan
7777
run: |

scripts/getLatest.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { execSync } = require('child_process');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
/**
6+
* Get the latest Lean version and update the lean-toolchain file
7+
*/
8+
try {
9+
// Get all release tags from leanprover/lean4
10+
console.log('Fetching release tags from leanprover/lean4...');
11+
const releasesJson = execSync('gh release list --repo leanprover/lean4 --json tagName', { encoding: 'utf8' });
12+
const releases = JSON.parse(releasesJson);
13+
14+
// Filter out tags that are not in the form of "v*"
15+
const versionTags = releases
16+
.map(release => release.tagName)
17+
.filter(tag => tag.startsWith('v'));
18+
19+
// Parse version tags as semver (removing the 'v' prefix)
20+
const semvers = versionTags
21+
.map(tag => tag.substring(1)) // Remove 'v' prefix
22+
.map(ver => {
23+
const parts = ver.split('.');
24+
return {
25+
major: parseInt(parts[0]),
26+
minor: parseInt(parts[1]),
27+
patch: parseInt(parts[2] || 0),
28+
original: ver
29+
};
30+
});
31+
32+
// Sort versions and get the latest one
33+
semvers.sort((a, b) => {
34+
if (a.major !== b.major) return a.major - b.major;
35+
if (a.minor !== b.minor) return a.minor - b.minor;
36+
return a.patch - b.patch;
37+
});
38+
39+
const latest = semvers[semvers.length - 1];
40+
console.log(`Latest Lean release is: v${latest.original}`);
41+
42+
// Update lean-toolchain file
43+
const leanStyleVersion = `leanprover/lean4:v${latest.original}`;
44+
fs.writeFileSync('lean-toolchain', leanStyleVersion);
45+
console.log(`Updated lean-toolchain to: ${leanStyleVersion}`);
46+
47+
} catch (error) {
48+
console.error('Error updating Lean version:', error.message);
49+
process.exit(1);
50+
}

scripts/getLatest.ps1

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)