From 2d1807cd4d7de400306e8e0b1db8779ee34ea40e Mon Sep 17 00:00:00 2001 From: Tunglies Date: Tue, 11 Mar 2025 01:09:25 +0800 Subject: [PATCH] feat: enhance tag retrieval and detection for stable and pre-release versions --- scripts/updater.mjs | 63 +++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/scripts/updater.mjs b/scripts/updater.mjs index ef5f0255..fa9a9f15 100644 --- a/scripts/updater.mjs +++ b/scripts/updater.mjs @@ -21,31 +21,56 @@ async function resolveUpdater() { const options = { owner: context.repo.owner, repo: context.repo.repo }; const github = getOctokit(process.env.GITHUB_TOKEN); - const { data: tags } = await github.rest.repos.listTags({ - ...options, - per_page: 50, // Increase to have more chances to find alpha tags - page: 1, - }); + // Fetch all tags using pagination + let allTags = []; + let page = 1; + const perPage = 100; - // Get the latest stable tag and alpha tag - const stableTag = tags.find( - (t) => t.name.startsWith("v") && !t.name.includes("alpha"), - ); - const alphaTag = tags.find( - (t) => t.name.startsWith("alpha") && !t.name.includes("v"), - ); + while (true) { + const { data: pageTags } = await github.rest.repos.listTags({ + ...options, + per_page: perPage, + page: page, + }); - console.log(tags); - console.log("Stable tag:", stableTag); - console.log("Alpha tag:", alphaTag); + allTags = allTags.concat(pageTags); + + // Break if we received fewer tags than requested (last page) + if (pageTags.length < perPage) { + break; + } + + page++; + } + + const tags = allTags; + console.log(`Retrieved ${tags.length} tags in total`); + + // More flexible tag detection with regex patterns + const stableTagRegex = /^v\d+\.\d+\.\d+$/; // Matches vX.Y.Z format + // const preReleaseRegex = /^v\d+\.\d+\.\d+-(alpha|beta|rc|pre)/i; // Matches vX.Y.Z-alpha/beta/rc format + const preReleaseRegex = /^v(alpha|beta|rc|pre)/i; // Matches alpha/beta/rc format + + // Get the latest stable tag and pre-release tag + const stableTag = tags.find((t) => stableTagRegex.test(t.name)); + const preReleaseTag = tags.find((t) => preReleaseRegex.test(t.name)); + + console.log("All tags:", tags.map((t) => t.name).join(", ")); + console.log("Stable tag:", stableTag ? stableTag.name : "None found"); + console.log( + "Pre-release tag:", + preReleaseTag ? preReleaseTag.name : "None found", + ); console.log(); // Process stable release - await processRelease(github, options, stableTag, false); + if (stableTag) { + await processRelease(github, options, stableTag, false); + } - // Process alpha release if found - if (alphaTag) { - await processRelease(github, options, alphaTag, true); + // Process pre-release if found + if (preReleaseTag) { + await processRelease(github, options, preReleaseTag, true); } }