diff --git a/.github/workflows/update-versions.yml b/.github/workflows/update-versions.yml index 376f56e35..ecae6f3bd 100644 --- a/.github/workflows/update-versions.yml +++ b/.github/workflows/update-versions.yml @@ -9,7 +9,8 @@ jobs: update-version: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 @@ -19,25 +20,16 @@ jobs: - name: Get latest Lotus version id: get-version run: | - # Get all releases and find the first one starting with 'v' - RELEASE_INFO=$(curl -s "https://api.github.com/repos/filecoin-project/lotus/releases/latest") - - # Find first tag that starts with 'v' but not 'miner' - TAG_NAME=$(echo "$RELEASE_INFO" | jq -r 'select(.tag_name | startswith("v") and (contains("miner") | not)) | .tag_name') - - # Extract version number (remove 'v' prefix) - LATEST_VERSION=$(echo $TAG_NAME | sed 's/^v//') - + LATEST_VERSION=$(node scripts/get-latest-lotus-version.js) echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV - echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV - name: Run update script - run: | - node update-versions.js ${{ env.LATEST_VERSION }} + run: node scripts/update-versions.js ${{ env.LATEST_VERSION }} - name: Create Pull Request uses: peter-evans/create-pull-request@v5 with: + token: ${{ secrets.GITHUB_TOKEN }} commit-message: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}' title: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}' body: | diff --git a/scripts/get-latest-lotus-version.js b/scripts/get-latest-lotus-version.js new file mode 100644 index 000000000..95f719546 --- /dev/null +++ b/scripts/get-latest-lotus-version.js @@ -0,0 +1,51 @@ +const https = require('https'); + +async function getLatestLotusVersion() { + return new Promise((resolve, reject) => { + const options = { + hostname: 'api.github.com', + path: '/repos/filecoin-project/lotus/releases/latest', + headers: { + 'User-Agent': 'Node.js' + } + }; + + https.get(options, (res) => { + let data = ''; + + res.on('data', (chunk) => { + data += chunk; + }); + + res.on('end', () => { + try { + const releaseInfo = JSON.parse(data); + const tagName = releaseInfo.tag_name; + + if (!tagName || !tagName.startsWith('v') || tagName.includes('miner')) { + throw new Error('Could not find a valid tag in the release info'); + } + + // Remove 'v' prefix + const version = tagName.substring(1); + resolve(version); + } catch (error) { + reject(new Error(`Failed to parse release info: ${error.message}`)); + } + }); + }).on('error', (error) => { + reject(new Error(`Failed to fetch release info: ${error.message}`)); + }); + }); +} + +if (require.main === module) { + getLatestLotusVersion() + .then(version => console.log(version)) + .catch(error => { + console.error(error.message); + process.exit(1); + }); +} + +module.exports = getLatestLotusVersion; \ No newline at end of file diff --git a/update-versions.js b/scripts/update-versions.js similarity index 100% rename from update-versions.js rename to scripts/update-versions.js