feat: enhance tag retrieval and detection for stable and pre-release versions

This commit is contained in:
Tunglies 2025-03-11 01:09:25 +08:00
parent c6dce2d6cb
commit 2d1807cd4d

View File

@ -21,31 +21,56 @@ async function resolveUpdater() {
const options = { owner: context.repo.owner, repo: context.repo.repo }; const options = { owner: context.repo.owner, repo: context.repo.repo };
const github = getOctokit(process.env.GITHUB_TOKEN); const github = getOctokit(process.env.GITHUB_TOKEN);
const { data: tags } = await github.rest.repos.listTags({ // Fetch all tags using pagination
...options, let allTags = [];
per_page: 50, // Increase to have more chances to find alpha tags let page = 1;
page: 1, const perPage = 100;
});
// Get the latest stable tag and alpha tag while (true) {
const stableTag = tags.find( const { data: pageTags } = await github.rest.repos.listTags({
(t) => t.name.startsWith("v") && !t.name.includes("alpha"), ...options,
); per_page: perPage,
const alphaTag = tags.find( page: page,
(t) => t.name.startsWith("alpha") && !t.name.includes("v"), });
);
console.log(tags); allTags = allTags.concat(pageTags);
console.log("Stable tag:", stableTag);
console.log("Alpha tag:", alphaTag); // 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(); console.log();
// Process stable release // Process stable release
await processRelease(github, options, stableTag, false); if (stableTag) {
await processRelease(github, options, stableTag, false);
}
// Process alpha release if found // Process pre-release if found
if (alphaTag) { if (preReleaseTag) {
await processRelease(github, options, alphaTag, true); await processRelease(github, options, preReleaseTag, true);
} }
} }