Skip to content

Commit 93047a1

Browse files
authored
Merge pull request #2390 from filecoin-project/bp/fix-script-github-action
Lotus version update automation fix
2 parents fe5857c + bbb8a2e commit 93047a1

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

.github/workflows/update-versions.yml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
update-version:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
1314

1415
- name: Setup Node.js
1516
uses: actions/setup-node@v4
@@ -19,25 +20,16 @@ jobs:
1920
- name: Get latest Lotus version
2021
id: get-version
2122
run: |
22-
# Get all releases and find the first one starting with 'v'
23-
RELEASE_INFO=$(curl -s "https://api.github.com/repos/filecoin-project/lotus/releases/latest")
24-
25-
# Find first tag that starts with 'v' but not 'miner'
26-
TAG_NAME=$(echo "$RELEASE_INFO" | jq -r 'select(.tag_name | startswith("v") and (contains("miner") | not)) | .tag_name')
27-
28-
# Extract version number (remove 'v' prefix)
29-
LATEST_VERSION=$(echo $TAG_NAME | sed 's/^v//')
30-
23+
LATEST_VERSION=$(node scripts/get-latest-lotus-version.js)
3124
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
32-
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
3325
3426
- name: Run update script
35-
run: |
36-
node update-versions.js ${{ env.LATEST_VERSION }}
27+
run: node scripts/update-versions.js ${{ env.LATEST_VERSION }}
3728

3829
- name: Create Pull Request
3930
uses: peter-evans/create-pull-request@v5
4031
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
4133
commit-message: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
4234
title: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
4335
body: |

scripts/get-latest-lotus-version.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const https = require('https');
2+
3+
async function getLatestLotusVersion() {
4+
return new Promise((resolve, reject) => {
5+
const options = {
6+
hostname: 'api.github.com',
7+
path: '/repos/filecoin-project/lotus/releases/latest',
8+
headers: {
9+
'User-Agent': 'Node.js'
10+
}
11+
};
12+
13+
https.get(options, (res) => {
14+
let data = '';
15+
16+
res.on('data', (chunk) => {
17+
data += chunk;
18+
});
19+
20+
res.on('end', () => {
21+
try {
22+
const releaseInfo = JSON.parse(data);
23+
const tagName = releaseInfo.tag_name;
24+
25+
if (!tagName || !tagName.startsWith('v') || tagName.includes('miner')) {
26+
throw new Error('Could not find a valid tag in the release info');
27+
}
28+
29+
// Remove 'v' prefix
30+
const version = tagName.substring(1);
31+
resolve(version);
32+
} catch (error) {
33+
reject(new Error(`Failed to parse release info: ${error.message}`));
34+
}
35+
});
36+
}).on('error', (error) => {
37+
reject(new Error(`Failed to fetch release info: ${error.message}`));
38+
});
39+
});
40+
}
41+
42+
if (require.main === module) {
43+
getLatestLotusVersion()
44+
.then(version => console.log(version))
45+
.catch(error => {
46+
console.error(error.message);
47+
process.exit(1);
48+
});
49+
}
50+
51+
module.exports = getLatestLotusVersion;
File renamed without changes.

0 commit comments

Comments
 (0)