up
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
const assert = require('node:assert/strict')
|
||||
const { mkdtempSync, readdirSync, writeFileSync, rmSync } = require('node:fs')
|
||||
const { join, basename, resolve } = require('node:path')
|
||||
const { execFileSync } = require('node:child_process')
|
||||
const { fileHash, verifyDirectory } = require('./release.cjs')
|
||||
const metadata = require('../package.json')
|
||||
const output = resolve(__dirname, '..', 'release')
|
||||
async function verifyArchive(artifact) {
|
||||
const temporary = mkdtempSync(join(output, '.verify-'))
|
||||
try {
|
||||
if (artifact.endsWith('.tar.gz')) execFileSync('tar', ['-xzf', artifact, '-C', temporary])
|
||||
else {
|
||||
const sevenZip = await require('app-builder-lib/out/toolsets/7zip').getPath7za()
|
||||
execFileSync(sevenZip, ['x', artifact, `-o${temporary}`, '-y', '-bd'], { stdio: 'pipe' })
|
||||
}
|
||||
let directory = temporary
|
||||
if (!readdirSync(temporary).some((name) => name === 'resources' || name.endsWith('.app'))) {
|
||||
const dirs = readdirSync(temporary, { withFileTypes: true }).filter((d) => d.isDirectory())
|
||||
assert.equal(dirs.length, 1, 'Expected one application directory')
|
||||
directory = join(temporary, dirs[0].name)
|
||||
}
|
||||
return await verifyDirectory(directory)
|
||||
} finally {
|
||||
rmSync(temporary, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
async function finish(context) {
|
||||
const supplied = context?.artifactPaths ?? process.argv.slice(2).map((p) => resolve(p))
|
||||
const artifacts = supplied.filter((path) => /\.(?:zip|tar\.gz)$/.test(path))
|
||||
assert.ok(artifacts.length, 'No artifacts from current build')
|
||||
const sums = []
|
||||
const sidecars = []
|
||||
for (const artifact of artifacts) {
|
||||
assert.ok(
|
||||
basename(artifact).startsWith(`${metadata.name}-${metadata.version}-`),
|
||||
'Wrong release version',
|
||||
)
|
||||
const info = await verifyArchive(artifact)
|
||||
const name = basename(artifact)
|
||||
assert.ok(
|
||||
name.includes(
|
||||
`-${info.platform === 'win32' ? 'win' : info.platform === 'darwin' ? 'mac' : 'linux'}-${info.arch}.`,
|
||||
),
|
||||
'Artifact name/architecture mismatch',
|
||||
)
|
||||
const sha256 = await fileHash(artifact)
|
||||
const sidecar = `${artifact}.build-info.json`
|
||||
writeFileSync(sidecar, JSON.stringify({ ...info, artifact: name, sha256 }, null, 2) + '\n')
|
||||
sidecars.push(sidecar)
|
||||
sums.push(`${sha256} ${name}`)
|
||||
}
|
||||
// Не подмешивать старые файлы из release/: каждый build получает свой manifest.
|
||||
const path = join(
|
||||
output,
|
||||
`SHA256SUMS-${artifacts
|
||||
.map((p) =>
|
||||
basename(p)
|
||||
.split(`${metadata.version}-`)[1]
|
||||
.replace(/\.(zip|tar\.gz)$/, ''),
|
||||
)
|
||||
.sort()
|
||||
.join('_')}`,
|
||||
)
|
||||
writeFileSync(path, sums.sort().join('\n') + '\n')
|
||||
console.log('RELEASE_ARCHIVES_PASS', artifacts.map((path) => basename(path)).join(', '))
|
||||
return [...sidecars, path]
|
||||
}
|
||||
module.exports = finish
|
||||
module.exports.verifyArchive = verifyArchive
|
||||
if (require.main === module)
|
||||
finish().catch((error) => {
|
||||
console.error(error.message)
|
||||
process.exitCode = 1
|
||||
})
|
||||
Reference in New Issue
Block a user