From ebebd1aed0e8c4c1403c8869a9955538f596948e Mon Sep 17 00:00:00 2001 From: "MK (fengmk2)" Date: Thu, 18 Jun 2026 22:51:41 +0800 Subject: [PATCH] chore(upgrade-deps): prevent Vite beta upgrades --- .github/scripts/upgrade-deps.ts | 35 +++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/scripts/upgrade-deps.ts b/.github/scripts/upgrade-deps.ts index f5d0b819c7..301771390b 100644 --- a/.github/scripts/upgrade-deps.ts +++ b/.github/scripts/upgrade-deps.ts @@ -22,6 +22,10 @@ type LatestTag = { tag: string; }; +type LatestTagOptions = { + stableOnly?: boolean; +}; + type NpmLatestResponse = { version?: unknown; }; @@ -62,6 +66,8 @@ type PackageJson = { peerDependencies?: Record; }; +const STABLE_SEMVER_TAG_RE = /^v?\d+\.\d+\.\d+$/; + const isFullSha = (s: string): boolean => /^[0-9a-f]{40}$/.test(s); const changes = new Map(); @@ -89,13 +95,21 @@ function recordChange( } // ============ GitHub API ============ -async function getLatestTag(owner: string, repo: string): Promise { - const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/tags?per_page=1`, { - headers: { - Authorization: `token ${process.env.GITHUB_TOKEN}`, - Accept: 'application/vnd.github.v3+json', +async function getLatestTag( + owner: string, + repo: string, + options: LatestTagOptions = {}, +): Promise { + const perPage = options.stableOnly ? 100 : 1; + const res = await fetch( + `https://api.github.com/repos/${owner}/${repo}/tags?per_page=${perPage}`, + { + headers: { + Authorization: `token ${process.env.GITHUB_TOKEN}`, + Accept: 'application/vnd.github.v3+json', + }, }, - }); + ); if (!res.ok) { throw new Error(`Failed to fetch tags for ${owner}/${repo}: ${res.status} ${res.statusText}`); } @@ -103,7 +117,12 @@ async function getLatestTag(owner: string, repo: string): Promise { if (!Array.isArray(tags) || !tags.length) { throw new Error(`No tags found for ${owner}/${repo}`); } - const [latest] = tags; + const latest = options.stableOnly + ? tags.find((tag) => typeof tag.name === 'string' && STABLE_SEMVER_TAG_RE.test(tag.name)) + : tags[0]; + if (!latest) { + throw new Error(`No stable semver tags found for ${owner}/${repo}`); + } if (typeof latest?.commit?.sha !== 'string' || typeof latest.name !== 'string') { throw new Error(`Invalid tag structure for ${owner}/${repo}: missing SHA or name`); } @@ -135,7 +154,7 @@ async function updateUpstreamVersions(): Promise { const oldViteHash = data.vite.hash; const [rolldown, vite] = await Promise.all([ getLatestTag('rolldown', 'rolldown'), - getLatestTag('vitejs', 'vite'), + getLatestTag('vitejs', 'vite', { stableOnly: true }), ]); data.rolldown.hash = rolldown.sha; data.vite.hash = vite.sha;