mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
fix: freeze release runtime tools and npm consumer artifacts
This commit is contained in:
1 parent
a70ec66fe3
commit
2f359c6bf0
63 files changed
+42562
-8738
No files matched your search
@@ -8,18 +8,21 @@ const yaml = require('js-yaml');
|
||||
const workflow = yaml.load(
|
||||
fs.readFileSync('.github/workflows/build-docker-image.yml', 'utf8'),
|
||||
);
|
||||
const publication = workflow.jobs.publish.steps.find(
|
||||
(step) => step.name === 'Publish npm package with OIDC',
|
||||
).run;
|
||||
const publicationStep = workflow.jobs.publish.steps.find(
|
||||
(step) => step.name === 'Publish the verified npm archive with OIDC',
|
||||
);
|
||||
assert.ok(publicationStep, 'Verified archive publication step must exist');
|
||||
const publication = publicationStep.run;
|
||||
|
||||
test('npm publication waits for every release image, including Python 3.10', () => {
|
||||
for (const name of [
|
||||
test('npm publication waits for the archive gate and every release image, including Python 3.10', () => {
|
||||
assert.deepEqual(workflow.jobs.publish.needs, [
|
||||
'build-alpine',
|
||||
'build-debian',
|
||||
'build-alpine310',
|
||||
'build-debian310',
|
||||
])
|
||||
assert.ok(workflow.jobs.publish.needs.includes(name), name);
|
||||
'npm-package',
|
||||
]);
|
||||
assert.equal(workflow.jobs.publish.permissions['id-token'], 'write');
|
||||
});
|
||||
|
||||
for (const [scenario, expectedStatus, published] of [
|
||||
@@ -28,30 +31,49 @@ for (const [scenario, expectedStatus, published] of [
|
||||
['unauthorized', 1, false],
|
||||
['network', 1, false],
|
||||
['unexpected-version', 1, false],
|
||||
['wrong-npm-version', 1, false],
|
||||
]) {
|
||||
test(`npm publication handles ${scenario} without publishing an unverified version`, (t) => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-npm-publication-'));
|
||||
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
||||
const bin = path.join(root, 'bin');
|
||||
fs.mkdirSync(bin);
|
||||
fs.symlinkSync(process.execPath, path.join(bin, 'node'));
|
||||
const npmCLI = path.join(
|
||||
root,
|
||||
'npm-publisher-tools/lib/node_modules/npm/bin/npm-cli.js',
|
||||
);
|
||||
fs.mkdirSync(path.dirname(npmCLI), { recursive: true });
|
||||
const tarball = path.join(root, 'verified qinglong-2.23.0.tgz');
|
||||
fs.writeFileSync(tarball, 'Fixture only: never install or publish this file.\n');
|
||||
fs.writeFileSync(
|
||||
path.join(root, 'package.json'),
|
||||
JSON.stringify({ name: '@fixture/qinglong', version: '2.22.0' }),
|
||||
JSON.stringify({ name: '@fixture/qinglong', version: '2.23.0' }),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(bin, 'npm'),
|
||||
`#!/usr/bin/env node
|
||||
npmCLI,
|
||||
`
|
||||
const fs = require('node:fs');
|
||||
if (process.argv[2] === 'publish') { fs.writeFileSync('published', 'yes'); process.exit(0); }
|
||||
if (process.argv[2] !== 'view') process.exit(99);
|
||||
const args = process.argv.slice(2);
|
||||
fs.appendFileSync('npm-calls.jsonl', JSON.stringify(args) + '\\n');
|
||||
if (args[0] === '--version') {
|
||||
console.log(process.env.QL_PUBLISH_SCENARIO === 'wrong-npm-version' ? '12.1.0' : '12.2.0');
|
||||
process.exit(0);
|
||||
}
|
||||
if (args[0] === 'publish') { fs.writeFileSync('published', JSON.stringify(args)); process.exit(0); }
|
||||
if (args[0] !== 'view') process.exit(99);
|
||||
switch (process.env.QL_PUBLISH_SCENARIO) {
|
||||
case 'existing': console.log(JSON.stringify('2.22.0')); break;
|
||||
case 'unexpected-version': console.log(JSON.stringify('2.21.0')); break;
|
||||
case 'existing': console.log(JSON.stringify('2.23.0')); break;
|
||||
case 'unexpected-version': console.log(JSON.stringify('2.22.0')); break;
|
||||
case 'missing': console.log(JSON.stringify({error:{code:'E404'}})); process.exit(1);
|
||||
case 'unauthorized': console.log(JSON.stringify({error:{code:'E401'}})); process.exit(1);
|
||||
case 'network': console.log('upstream unavailable'); process.exit(1);
|
||||
}
|
||||
`,
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(bin, 'npm'),
|
||||
'#!/bin/sh\nprintf wrong-client > wrong-path-npm\nexit 97\n',
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
const result = spawnSync('bash', ['-c', publication], {
|
||||
@@ -62,9 +84,41 @@ case 'network': console.log('upstream unavailable'); process.exit(1);
|
||||
PATH: `${bin}${path.delimiter}${process.env.PATH}`,
|
||||
RUNNER_TEMP: root,
|
||||
QL_PUBLISH_SCENARIO: scenario,
|
||||
QINGLONG_PUBLISH_TARBALL: tarball,
|
||||
},
|
||||
});
|
||||
assert.equal(result.status, expectedStatus, result.stdout + result.stderr);
|
||||
assert.equal(fs.existsSync(path.join(root, 'published')), published);
|
||||
assert.equal(fs.existsSync(path.join(root, 'wrong-path-npm')), false);
|
||||
const calls = fs
|
||||
.readFileSync(path.join(root, 'npm-calls.jsonl'), 'utf8')
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map((line) => JSON.parse(line));
|
||||
const expectedCalls = [['--version']];
|
||||
if (scenario !== 'wrong-npm-version')
|
||||
expectedCalls.push([
|
||||
'view',
|
||||
'@fixture/qinglong@2.23.0',
|
||||
'version',
|
||||
'--json',
|
||||
'--registry=https://registry.npmjs.org',
|
||||
]);
|
||||
if (published) {
|
||||
const publishArgs = [
|
||||
'publish',
|
||||
tarball,
|
||||
'--ignore-scripts',
|
||||
'--access',
|
||||
'public',
|
||||
'--registry=https://registry.npmjs.org',
|
||||
];
|
||||
expectedCalls.push(publishArgs);
|
||||
assert.deepEqual(
|
||||
JSON.parse(fs.readFileSync(path.join(root, 'published'))),
|
||||
publishArgs,
|
||||
);
|
||||
}
|
||||
assert.deepEqual(calls, expectedCalls);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user