fix: handle verified package metadata
This commit is contained in:
+14
-27
@@ -127,20 +127,6 @@ function expectedFormatForFile(name, target) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAllowedAuxiliaryFile(name, target, manifestNames) {
|
|
||||||
if (name === 'builder-debug.yml') {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if (!name.endsWith('.blockmap')) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const packageName = name.slice(0, -'.blockmap'.length)
|
|
||||||
return (
|
|
||||||
manifestNames.has(packageName) &&
|
|
||||||
expectedFormatForFile(packageName, target) !== undefined
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function listTargetDirectories(inputDirectory) {
|
function listTargetDirectories(inputDirectory) {
|
||||||
if (lstatSync(inputDirectory).isSymbolicLink()) {
|
if (lstatSync(inputDirectory).isSymbolicLink()) {
|
||||||
throw new Error(`拒绝符号链接:${inputDirectory}`)
|
throw new Error(`拒绝符号链接:${inputDirectory}`)
|
||||||
@@ -224,9 +210,6 @@ async function aggregateRelease(inputDirectory, outputDirectory) {
|
|||||||
|
|
||||||
const seenFormats = new Set()
|
const seenFormats = new Set()
|
||||||
const files = []
|
const files = []
|
||||||
const manifestNames = new Set(
|
|
||||||
item.manifest.files.map((file) => file?.name)
|
|
||||||
)
|
|
||||||
for (const file of item.manifest.files) {
|
for (const file of item.manifest.files) {
|
||||||
assertSafeName(file?.name, '发布文件名')
|
assertSafeName(file?.name, '发布文件名')
|
||||||
if (
|
if (
|
||||||
@@ -237,16 +220,8 @@ async function aggregateRelease(inputDirectory, outputDirectory) {
|
|||||||
) {
|
) {
|
||||||
throw new Error(`发布文件元数据错误:${file?.name ?? key}`)
|
throw new Error(`发布文件元数据错误:${file?.name ?? key}`)
|
||||||
}
|
}
|
||||||
if (fileNames.has(file.name)) {
|
|
||||||
throw new Error(`发布文件名全局重复:${file.name}`)
|
|
||||||
}
|
|
||||||
const format = expectedFormatForFile(file.name, expected)
|
const format = expectedFormatForFile(file.name, expected)
|
||||||
const auxiliary = isAllowedAuxiliaryFile(
|
if (format && seenFormats.has(format)) {
|
||||||
file.name,
|
|
||||||
expected,
|
|
||||||
manifestNames
|
|
||||||
)
|
|
||||||
if ((!format && !auxiliary) || (format && seenFormats.has(format))) {
|
|
||||||
throw new Error(`发布文件格式或数量错误:${file.name}`)
|
throw new Error(`发布文件格式或数量错误:${file.name}`)
|
||||||
}
|
}
|
||||||
const source = join(directory, file.name)
|
const source = join(directory, file.name)
|
||||||
@@ -256,9 +231,12 @@ async function aggregateRelease(inputDirectory, outputDirectory) {
|
|||||||
if (actualSize !== file.size || actualHash !== file.sha256) {
|
if (actualSize !== file.size || actualHash !== file.sha256) {
|
||||||
throw new Error(`发布文件完整性校验失败:${file.name}`)
|
throw new Error(`发布文件完整性校验失败:${file.name}`)
|
||||||
}
|
}
|
||||||
if (auxiliary) {
|
if (!format) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if (fileNames.has(file.name)) {
|
||||||
|
throw new Error(`发布文件名全局重复:${file.name}`)
|
||||||
|
}
|
||||||
assertPlainFile(source, '发布文件')
|
assertPlainFile(source, '发布文件')
|
||||||
copyFileSync(source, join(outputDirectory, file.name))
|
copyFileSync(source, join(outputDirectory, file.name))
|
||||||
fileNames.add(file.name)
|
fileNames.add(file.name)
|
||||||
@@ -348,6 +326,15 @@ module.exports = {
|
|||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
main().catch((error) => {
|
main().catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
if (process.env.GITHUB_ACTIONS === 'true') {
|
||||||
|
const message = String(error?.message ?? error)
|
||||||
|
.replaceAll('%', '%25')
|
||||||
|
.replaceAll('\r', '%0D')
|
||||||
|
.replaceAll('\n', '%0A')
|
||||||
|
console.error(
|
||||||
|
`::error title=Release aggregation failed::${message}`
|
||||||
|
)
|
||||||
|
}
|
||||||
process.exitCode = 1
|
process.exitCode = 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,17 @@ function createDownloadedArtifacts(parent: string): string {
|
|||||||
size: Buffer.byteLength(debugContent),
|
size: Buffer.byteLength(debugContent),
|
||||||
sha256: sha256(debugContent)
|
sha256: sha256(debugContent)
|
||||||
})
|
})
|
||||||
|
const metadataName = `metadata-${key}.json`
|
||||||
|
const metadataContent = `${key}:metadata`
|
||||||
|
writeFileSync(
|
||||||
|
join(directory, metadataName),
|
||||||
|
metadataContent
|
||||||
|
)
|
||||||
|
files.push({
|
||||||
|
name: metadataName,
|
||||||
|
size: Buffer.byteLength(metadataContent),
|
||||||
|
sha256: sha256(metadataContent)
|
||||||
|
})
|
||||||
if (target.platform === 'windows') {
|
if (target.platform === 'windows') {
|
||||||
const setupName = artifactName(target, 'nsis')
|
const setupName = artifactName(target, 'nsis')
|
||||||
const blockmapName = `${setupName}.blockmap`
|
const blockmapName = `${setupName}.blockmap`
|
||||||
@@ -149,6 +160,9 @@ describe('release asset aggregation', () => {
|
|||||||
expect(outputNames).toContain('release-manifest.json')
|
expect(outputNames).toContain('release-manifest.json')
|
||||||
expect(outputNames).toContain('SHA256SUMS')
|
expect(outputNames).toContain('SHA256SUMS')
|
||||||
expect(outputNames).not.toContain('builder-debug.yml')
|
expect(outputNames).not.toContain('builder-debug.yml')
|
||||||
|
expect(
|
||||||
|
outputNames.some((name) => name.startsWith('metadata-'))
|
||||||
|
).toBe(false)
|
||||||
expect(
|
expect(
|
||||||
outputNames.some((name) => name.endsWith('.blockmap'))
|
outputNames.some((name) => name.endsWith('.blockmap'))
|
||||||
).toBe(false)
|
).toBe(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user