34 lines
1.8 KiB
JavaScript
34 lines
1.8 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const {spawnSync} = require('node:child_process');
|
|
|
|
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'qfs-release-gate-'));
|
|
try {
|
|
fs.copyFileSync('Makefile', path.join(directory, 'Makefile'));
|
|
fs.copyFileSync('scripts/release.sh', path.join(directory, 'release.sh'));
|
|
const tools = path.join(directory, 'tools');
|
|
fs.mkdirSync(tools);
|
|
fs.writeFileSync(path.join(tools, 'go'), '#!/bin/sh\nprintf "%s\\n" "$*" >> "$QFS_TEST_GO_CALLS"\nexit 23\n', {mode: 0o755});
|
|
const callsPath = path.join(directory, 'calls');
|
|
const env = {...process.env, PATH: tools + path.delimiter + process.env.PATH, QFS_TEST_GO_CALLS: callsPath};
|
|
const cases = [
|
|
...['build-release', 'build-linux', 'build-macos', 'build-windows', 'build-all'].map(target => ['make', [target]]),
|
|
['bash', ['release.sh']],
|
|
];
|
|
for (const [cmd, args] of cases) {
|
|
fs.writeFileSync(callsPath, '');
|
|
const result = spawnSync(cmd, args, {cwd: directory, env, encoding: 'utf8', timeout: 10000});
|
|
assert.ifError(result.error);
|
|
assert.notEqual(result.status, 0, `${cmd} ${args}: scanner failure was ignored`);
|
|
const calls = fs.readFileSync(callsPath, 'utf8').trim().split('\n');
|
|
assert.deepEqual(calls, ['run golang.org/x/vuln/cmd/govulncheck@v1.9.0 ./...']);
|
|
assert(!fs.existsSync(path.join(directory, 'bin')), 'Build artifacts created after failed scan');
|
|
assert(!fs.existsSync(path.join(directory, 'releases')), 'Release artifacts created after failed scan');
|
|
}
|
|
console.log('Release security failure checks passed');
|
|
} finally {
|
|
fs.rmSync(directory, {recursive: true, force: true});
|
|
}
|