Skip to content

Commit b101a72

Browse files
committed
fix: Lotus version update automation
1 parent 8fed72b commit b101a72

File tree

2 files changed

+91
-12
lines changed

2 files changed

+91
-12
lines changed

.github/workflows/update-versions.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Update Lotus Version
33
on:
44
workflow_dispatch:
55
pull_request:
6-
types: [opened, reopened]
6+
types: [opened, reopened, synchronize]
77

88
jobs:
99
update-version:
@@ -19,25 +19,32 @@ jobs:
1919
- name: Get latest Lotus version
2020
id: get-version
2121
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-
22+
LATEST_VERSION=$(node scripts/get-latest-lotus-version.js)
3123
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
32-
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
24+
echo "TAG_NAME=v$LATEST_VERSION" >> $GITHUB_ENV
3325
3426
- name: Run update script
3527
run: |
36-
node update-versions.js ${{ env.LATEST_VERSION }}
28+
node scripts/update-versions.js ${{ env.LATEST_VERSION }}
3729
30+
- name: Ensure branch exists
31+
run: |
32+
git fetch origin
33+
if ! git show-ref --verify --quiet refs/heads/update-lotus-version; then
34+
git checkout -b update-lotus-version
35+
else
36+
git checkout update-lotus-version
37+
fi
38+
39+
- name: Configure Git
40+
run: |
41+
git config user.name "GitHub Actions Bot"
42+
git config user.email "github-actions[bot]@users.noreply.github.com"
43+
3844
- name: Create Pull Request
3945
uses: peter-evans/create-pull-request@v5
4046
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
4148
commit-message: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
4249
title: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
4350
body: |

scripts/get-latest-lotus-version.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const https = require('https');
2+
3+
/**
4+
* Fetches the latest Lotus version from GitHub releases
5+
* @returns {Promise<string>} The latest version number without the 'v' prefix
6+
* @throws {Error} If the version cannot be fetched or parsed
7+
*/
8+
async function getLatestLotusVersion() {
9+
return new Promise((resolve, reject) => {
10+
const options = {
11+
hostname: 'api.github.com',
12+
path: '/repos/filecoin-project/lotus/releases/latest',
13+
headers: {
14+
'User-Agent': 'Node.js'
15+
}
16+
};
17+
18+
https.get(options, (res) => {
19+
let data = '';
20+
21+
res.on('data', (chunk) => {
22+
data += chunk;
23+
});
24+
25+
res.on('end', () => {
26+
try {
27+
const releaseInfo = JSON.parse(data);
28+
const tagName = releaseInfo.tag_name;
29+
30+
if (!tagName || !tagName.startsWith('v') || tagName.includes('miner')) {
31+
throw new Error('Could not find a valid tag in the release info');
32+
}
33+
34+
// Remove 'v' prefix
35+
const version = tagName.substring(1);
36+
resolve(version);
37+
} catch (error) {
38+
reject(new Error(`Failed to parse release info: ${error.message}`));
39+
}
40+
});
41+
}).on('error', (error) => {
42+
reject(new Error(`Failed to fetch release info: ${error.message}`));
43+
});
44+
});
45+
}
46+
47+
// If this file is run directly (not imported)
48+
if (require.main === module) {
49+
// Test mode
50+
if (process.argv[2] === '--test') {
51+
console.log('Testing getLatestLotusVersion function...');
52+
getLatestLotusVersion()
53+
.then(version => {
54+
console.log('Success! Latest version:', version);
55+
})
56+
.catch(error => {
57+
console.error('Test failed:', error.message);
58+
process.exit(1);
59+
});
60+
} else {
61+
// Normal mode - just output the version
62+
getLatestLotusVersion()
63+
.then(version => console.log(version))
64+
.catch(error => {
65+
console.error(error.message);
66+
process.exit(1);
67+
});
68+
}
69+
}
70+
71+
// Export the function for use in other files
72+
module.exports = getLatestLotusVersion;

0 commit comments

Comments
 (0)