feat: publish multi-version releases list and verify GitHub asset digest
This commit is contained in:
1 parent
1be15e1ab6
commit
8a8118fa5f
1 file changed
+96
-11
+96
-11
@@ -219,6 +219,23 @@ function summarizeReleaseBody(body) {
|
|||||||
return { 'zh-CN': clipped, 'en-US': clipped }
|
return { 'zh-CN': clipped, 'en-US': clipped }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseDigestSha256(digest) {
|
||||||
|
if (typeof digest !== 'string') return ''
|
||||||
|
const s = digest.trim().toLowerCase()
|
||||||
|
if (!s.startsWith('sha256:')) return ''
|
||||||
|
const hex = s.slice('sha256:'.length)
|
||||||
|
return RE_SHA256.test(hex) ? hex : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function inferVersionFromTag(tagName, tagPrefix) {
|
||||||
|
let s = String(tagName || '').trim()
|
||||||
|
if (tagPrefix && s.startsWith(tagPrefix)) {
|
||||||
|
s = s.slice(tagPrefix.length)
|
||||||
|
}
|
||||||
|
s = s.replace(/^v/i, '').trim()
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
async function resolveLatestReleaseCandidates(entry, channel) {
|
async function resolveLatestReleaseCandidates(entry, channel) {
|
||||||
if (!entry.repo) {
|
if (!entry.repo) {
|
||||||
throw new Error('auto-tracked plugin entry must specify repo (owner/name)')
|
throw new Error('auto-tracked plugin entry must specify repo (owner/name)')
|
||||||
@@ -226,6 +243,7 @@ async function resolveLatestReleaseCandidates(entry, channel) {
|
|||||||
const releases = await fetchGitHubReleases(entry.repo)
|
const releases = await fetchGitHubReleases(entry.repo)
|
||||||
const tagPrefix = typeof entry.tag_prefix === 'string' ? entry.tag_prefix : ''
|
const tagPrefix = typeof entry.tag_prefix === 'string' ? entry.tag_prefix : ''
|
||||||
const candidates = []
|
const candidates = []
|
||||||
|
const allReleases = []
|
||||||
let totalDownloads = 0
|
let totalDownloads = 0
|
||||||
for (const rel of releases) {
|
for (const rel of releases) {
|
||||||
if (!rel || rel.draft) continue
|
if (!rel || rel.draft) continue
|
||||||
@@ -233,18 +251,32 @@ async function resolveLatestReleaseCandidates(entry, channel) {
|
|||||||
const asset = selectReleaseAsset(rel, entry)
|
const asset = selectReleaseAsset(rel, entry)
|
||||||
if (!asset || !asset.browser_download_url) continue
|
if (!asset || !asset.browser_download_url) continue
|
||||||
if (Number.isFinite(asset.download_count)) totalDownloads += asset.download_count
|
if (Number.isFinite(asset.download_count)) totalDownloads += asset.download_count
|
||||||
if (channel === 'stable' && rel.prerelease) continue
|
const relChannel = rel.prerelease ? 'alpha' : 'stable'
|
||||||
candidates.push({
|
const digestSha256 = parseDigestSha256(asset.digest)
|
||||||
|
const publishedAt = rel.published_at || rel.created_at || new Date().toISOString()
|
||||||
|
const cand = {
|
||||||
tag: rel.tag_name,
|
tag: rel.tag_name,
|
||||||
|
version: inferVersionFromTag(rel.tag_name, tagPrefix),
|
||||||
|
channel: relChannel,
|
||||||
downloadURL: asset.browser_download_url,
|
downloadURL: asset.browser_download_url,
|
||||||
publishedAt: rel.published_at || rel.created_at || new Date().toISOString(),
|
digestSha256,
|
||||||
|
sizeBytes: Number.isFinite(asset.size) ? asset.size : 0,
|
||||||
|
publishedAt,
|
||||||
body: rel.body || '',
|
body: rel.body || '',
|
||||||
})
|
}
|
||||||
|
allReleases.push(cand)
|
||||||
|
if (channel === 'stable' && rel.prerelease) continue
|
||||||
|
candidates.push(cand)
|
||||||
}
|
}
|
||||||
if (candidates.length === 0) {
|
if (candidates.length === 0) {
|
||||||
throw new Error(`no matching ${channel} GitHub Release with a .zip plugin asset found in ${entry.repo}`)
|
// Fall back to all matching releases (e.g. if repo only has prereleases).
|
||||||
|
if (allReleases.length > 0) {
|
||||||
|
candidates.push(...allReleases)
|
||||||
|
} else {
|
||||||
|
throw new Error(`no matching ${channel} GitHub Release with a .zip plugin asset found in ${entry.repo}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { candidates, totalDownloads }
|
return { candidates, allReleases, totalDownloads }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadBuffer(url) {
|
async function downloadBuffer(url) {
|
||||||
@@ -310,7 +342,7 @@ function validateWithdrawn(withdrawnDoc) {
|
|||||||
return { ids, list: out }
|
return { ids, list: out }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function verifyAndBuildCandidate({ entry, channel, kind, trust, candidate, pinnedVersion, pinnedSHA256, stats, opts, tmpRoot }) {
|
async function verifyAndBuildCandidate({ entry, channel, kind, trust, candidate, allReleases, pinnedVersion, pinnedSHA256, stats, opts, tmpRoot }) {
|
||||||
const parsedURL = new URL(candidate.downloadURL)
|
const parsedURL = new URL(candidate.downloadURL)
|
||||||
if (parsedURL.protocol !== 'https:') {
|
if (parsedURL.protocol !== 'https:') {
|
||||||
throw new Error(`download_url must use https:// (got ${candidate.downloadURL})`)
|
throw new Error(`download_url must use https:// (got ${candidate.downloadURL})`)
|
||||||
@@ -321,6 +353,9 @@ async function verifyAndBuildCandidate({ entry, channel, kind, trust, candidate,
|
|||||||
if (pinnedSHA256 && gotSum !== pinnedSHA256) {
|
if (pinnedSHA256 && gotSum !== pinnedSHA256) {
|
||||||
throw new Error(`SHA-256 mismatch: registry=${pinnedSHA256}, actual=${gotSum}`)
|
throw new Error(`SHA-256 mismatch: registry=${pinnedSHA256}, actual=${gotSum}`)
|
||||||
}
|
}
|
||||||
|
if (candidate.digestSha256 && gotSum !== candidate.digestSha256) {
|
||||||
|
throw new Error(`SHA-256 mismatch: github_digest=${candidate.digestSha256}, actual=${gotSum}`)
|
||||||
|
}
|
||||||
|
|
||||||
const manifestRaw = readFileFromZipBuffer(buf, 'plugin.json')
|
const manifestRaw = readFileFromZipBuffer(buf, 'plugin.json')
|
||||||
const manifest = JSON.parse(manifestRaw.toString('utf8'))
|
const manifest = JSON.parse(manifestRaw.toString('utf8'))
|
||||||
@@ -352,6 +387,54 @@ async function verifyAndBuildCandidate({ entry, channel, kind, trust, candidate,
|
|||||||
const tier = scanReport?.tier || (manifest.entry?.sidecar ? 'L3' : manifest.entry?.panelDir ? 'L4' : 'L1')
|
const tier = scanReport?.tier || (manifest.entry?.sidecar ? 'L3' : manifest.entry?.panelDir ? 'L4' : 'L1')
|
||||||
const effectiveTrust = trust === 'official' || trust === 'verified' ? trust : 'community'
|
const effectiveTrust = trust === 'official' || trust === 'verified' ? trust : 'community'
|
||||||
const icon = extractPluginIcon(buf, manifest)
|
const icon = extractPluginIcon(buf, manifest)
|
||||||
|
const primaryChannel = candidate.channel || channel
|
||||||
|
const primaryChangelog = normalizeLocalized(entry.changelog) || summarizeReleaseBody(candidate.body)
|
||||||
|
const primaryPublished = entry.updated_at || candidate.publishedAt || new Date().toISOString()
|
||||||
|
|
||||||
|
const releaseList = []
|
||||||
|
const seenVersions = new Set()
|
||||||
|
const addRelease = (r) => {
|
||||||
|
if (!r.version || !RE_SHA256.test(r.sha256) || seenVersions.has(r.version)) return
|
||||||
|
seenVersions.add(r.version)
|
||||||
|
const clean = {
|
||||||
|
version: r.version,
|
||||||
|
channel: r.channel || 'stable',
|
||||||
|
download_url: r.download_url,
|
||||||
|
sha256: r.sha256,
|
||||||
|
size_bytes: r.size_bytes > 0 ? r.size_bytes : undefined,
|
||||||
|
published_at: r.published_at || undefined,
|
||||||
|
changelog: r.changelog || undefined,
|
||||||
|
}
|
||||||
|
for (const k of Object.keys(clean)) {
|
||||||
|
if (clean[k] === undefined) delete clean[k]
|
||||||
|
}
|
||||||
|
releaseList.push(clean)
|
||||||
|
}
|
||||||
|
addRelease({
|
||||||
|
version,
|
||||||
|
channel: primaryChannel,
|
||||||
|
download_url: candidate.downloadURL,
|
||||||
|
sha256: gotSum,
|
||||||
|
size_bytes: buf.length,
|
||||||
|
published_at: primaryPublished,
|
||||||
|
changelog: primaryChangelog,
|
||||||
|
})
|
||||||
|
if (Array.isArray(allReleases)) {
|
||||||
|
for (const rel of allReleases) {
|
||||||
|
if (releaseList.length >= 10) break
|
||||||
|
if (!rel.version || !rel.digestSha256) continue
|
||||||
|
addRelease({
|
||||||
|
version: rel.version,
|
||||||
|
channel: rel.channel,
|
||||||
|
download_url: rel.downloadURL,
|
||||||
|
sha256: rel.digestSha256,
|
||||||
|
size_bytes: rel.sizeBytes,
|
||||||
|
published_at: rel.publishedAt,
|
||||||
|
changelog: summarizeReleaseBody(rel.body),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const marketItem = {
|
const marketItem = {
|
||||||
id: manifest.id,
|
id: manifest.id,
|
||||||
version,
|
version,
|
||||||
@@ -359,7 +442,7 @@ async function verifyAndBuildCandidate({ entry, channel, kind, trust, candidate,
|
|||||||
description: normalizeLocalized(manifest.description) || { 'en-US': '' },
|
description: normalizeLocalized(manifest.description) || { 'en-US': '' },
|
||||||
publisher: manifest.publisher || (entry.repo ? entry.repo.split('/')[0] : 'community'),
|
publisher: manifest.publisher || (entry.repo ? entry.repo.split('/')[0] : 'community'),
|
||||||
license: manifest.license || '',
|
license: manifest.license || '',
|
||||||
channel,
|
channel: primaryChannel,
|
||||||
trust: effectiveTrust,
|
trust: effectiveTrust,
|
||||||
kind,
|
kind,
|
||||||
tier,
|
tier,
|
||||||
@@ -372,11 +455,12 @@ async function verifyAndBuildCandidate({ entry, channel, kind, trust, candidate,
|
|||||||
download_url: candidate.downloadURL,
|
download_url: candidate.downloadURL,
|
||||||
sha256: gotSum,
|
sha256: gotSum,
|
||||||
size_bytes: buf.length,
|
size_bytes: buf.length,
|
||||||
changelog: normalizeLocalized(entry.changelog) || summarizeReleaseBody(candidate.body),
|
changelog: primaryChangelog,
|
||||||
|
releases: releaseList.length > 0 ? releaseList : undefined,
|
||||||
tags: Array.isArray(entry.tags) ? entry.tags : undefined,
|
tags: Array.isArray(entry.tags) ? entry.tags : undefined,
|
||||||
stars: stats?.stars > 0 ? stats.stars : undefined,
|
stars: stats?.stars > 0 ? stats.stars : undefined,
|
||||||
downloads: stats?.downloads > 0 ? stats.downloads : undefined,
|
downloads: stats?.downloads > 0 ? stats.downloads : undefined,
|
||||||
updated_at: entry.updated_at || candidate.publishedAt || new Date().toISOString(),
|
updated_at: primaryPublished,
|
||||||
}
|
}
|
||||||
for (const k of Object.keys(marketItem)) {
|
for (const k of Object.keys(marketItem)) {
|
||||||
if (marketItem[k] === undefined) delete marketItem[k]
|
if (marketItem[k] === undefined) delete marketItem[k]
|
||||||
@@ -469,7 +553,7 @@ async function main() {
|
|||||||
marketPlugins.push(built.marketItem)
|
marketPlugins.push(built.marketItem)
|
||||||
reportRows.push(built.reportRow)
|
reportRows.push(built.reportRow)
|
||||||
} else {
|
} else {
|
||||||
const { candidates, totalDownloads } = await resolveLatestReleaseCandidates(entry, channel)
|
const { candidates, allReleases, totalDownloads } = await resolveLatestReleaseCandidates(entry, channel)
|
||||||
let built = null
|
let built = null
|
||||||
let lastErr = null
|
let lastErr = null
|
||||||
// In PR --check mode, only accept the latest release; in scheduled publish mode,
|
// In PR --check mode, only accept the latest release; in scheduled publish mode,
|
||||||
@@ -483,6 +567,7 @@ async function main() {
|
|||||||
kind,
|
kind,
|
||||||
trust,
|
trust,
|
||||||
candidate: candidates[i],
|
candidate: candidates[i],
|
||||||
|
allReleases,
|
||||||
pinnedVersion: '',
|
pinnedVersion: '',
|
||||||
pinnedSHA256: '',
|
pinnedSHA256: '',
|
||||||
stats: { stars: repoStats.stars, downloads: totalDownloads },
|
stats: { stars: repoStats.stars, downloads: totalDownloads },
|
||||||
|
|||||||
Reference in new issue
Block a user