mirror of
https://github.com/LamGC/wp-asciiplayer.git
synced 2026-11-26 20:55:48 +00:00
ci: prepare draft releases from validated SemVer tags
This commit is contained in:
@@ -0,0 +1,246 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createReleaseDraft, prepareAssets, previousRelease, main } from '../../scripts/release-draft.mjs';
|
||||
|
||||
const commit = 'a'.repeat(40);
|
||||
const zip = Buffer.from('504b0304000102030405', 'hex');
|
||||
const options = { repository: 'owner/repo', tag: 'v1.2.0', version: '1.2.0', commit, token: 'test-only', zip };
|
||||
const release = (tag, extra = {}) => ({ tag_name: tag, draft: false, prerelease: false, ...extra });
|
||||
|
||||
function fixture({ releases = [], annotated = false, moveAt = Infinity, uploadConflict = false, comparisons = {} } = {}) {
|
||||
const calls = [];
|
||||
const assets = [];
|
||||
let refs = 0;
|
||||
let created;
|
||||
let failedUpload = false;
|
||||
const predecessorShas = new Map();
|
||||
const fetchImpl = async (input, init) => {
|
||||
const url = new URL(input);
|
||||
const body = init.headers['Content-Type'] === 'application/json' ? JSON.parse(init.body) : init.body;
|
||||
calls.push({ url, ...init, body });
|
||||
const response = (value, status = 200) => ({ ok: status < 400, status, json: async () => value });
|
||||
if (url.pathname.endsWith('/git/ref/tags/v1.2.0')) {
|
||||
refs++;
|
||||
return response({ ref: 'refs/tags/v1.2.0', object: { type: annotated ? 'tag' : 'commit',
|
||||
sha: refs >= moveAt ? 'b'.repeat(40) : commit } });
|
||||
}
|
||||
if (url.pathname.includes('/git/ref/tags/')) {
|
||||
const tag = decodeURIComponent(url.pathname.split('/git/ref/tags/')[1]);
|
||||
if (comparisons[tag] === 'missing') return response({}, 404);
|
||||
const sha = String(predecessorShas.size + 1).padStart(40, '0');
|
||||
predecessorShas.set(sha, tag);
|
||||
return response({ ref: `refs/tags/${tag}`, object: { type: 'commit', sha } });
|
||||
}
|
||||
if (url.pathname.includes('/git/tags/')) return response({ object: { type: 'commit', sha: commit } });
|
||||
if (url.pathname.endsWith('/commits')) return response([{ sha: commit, commit: { message: 'Initial implementation' } }]);
|
||||
if (url.pathname.includes('/compare/')) {
|
||||
const sha = url.pathname.split('/compare/')[1].split('...')[0];
|
||||
assert.match(sha, /^[a-f0-9]{40}$/);
|
||||
const tag = predecessorShas.get(sha);
|
||||
assert.ok(tag, 'comparison must use an explicitly resolved predecessor tag SHA');
|
||||
const status = comparisons[tag] ?? 'ahead';
|
||||
return status === 'missing' ? response({}, 404) : response({ status });
|
||||
}
|
||||
if (url.pathname.endsWith('/releases/generate-notes')) return response({ body: 'Generated notes' });
|
||||
if (url.pathname.endsWith('/releases') && init.method === 'GET') return response(releases);
|
||||
if (url.pathname.endsWith('/releases') && init.method === 'POST') {
|
||||
created = { id: 123, ...body };
|
||||
releases.push(created);
|
||||
return response(created, 201);
|
||||
}
|
||||
if (url.pathname.endsWith('/releases/123')) return response(created ?? releases.find((r) => r.id === 123));
|
||||
if (url.pathname.endsWith('/releases/123/assets') && init.method === 'GET') return response(assets);
|
||||
if (url.hostname === 'uploads.github.com') {
|
||||
const name = url.searchParams.get('name');
|
||||
const expected = prepareAssets(zip).find((a) => a.name === name);
|
||||
const uploaded = { name, state: 'uploaded', size: body.length, digest: `sha256:${expected.sha256}` };
|
||||
assets.push(uploaded);
|
||||
if (uploadConflict && !failedUpload) { failedUpload = true; return response({}, 422); }
|
||||
return response(uploaded, 201);
|
||||
}
|
||||
throw new Error(`Unexpected mock request: ${init.method} ${input}`);
|
||||
};
|
||||
return { fetchImpl, calls, assets, releases, get created() { return created; } };
|
||||
}
|
||||
|
||||
test('stable notes select highest lower published stable SemVer, never drafts or prereleases', () => {
|
||||
const releases = [release('v1.1.0'), release('v1.1.9-rc.1', { prerelease: true }), release('v1.2.0'),
|
||||
release('v1.1.5', { draft: true }), release('v1.1.3'), release('bad'), release('v2.0.0')];
|
||||
assert.equal(previousRelease(releases, 'v1.2.0').tag_name, 'v1.1.3');
|
||||
});
|
||||
|
||||
test('prerelease notes can use lower published prereleases with numeric SemVer ordering', () => {
|
||||
const releases = ['v1.2.0-rc.2', 'v1.2.0-rc.10', 'v1.1.0', 'v1.2.0'].map((tag) => release(tag));
|
||||
assert.equal(previousRelease(releases, 'v1.2.0-rc.11').tag_name, 'v1.2.0-rc.10');
|
||||
assert.equal(previousRelease([], 'v1.0.0'), undefined);
|
||||
});
|
||||
|
||||
test('creates draft only with generated notes, provenance, ZIP and checksum', async () => {
|
||||
const f = fixture({ releases: [release('v1.1.0')] });
|
||||
const result = await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.equal(result.draft, true);
|
||||
assert.equal(f.created.draft, true);
|
||||
assert.equal(f.created.prerelease, false);
|
||||
assert.equal(f.created.make_latest, 'false');
|
||||
assert.equal(f.created.target_commitish, commit);
|
||||
assert.match(f.created.body, /Generated notes\n\n<!-- wp-asciiplayer-release/);
|
||||
const notes = f.calls.find((c) => c.url.pathname.endsWith('generate-notes'));
|
||||
assert.equal(notes.body.previous_tag_name, 'v1.1.0');
|
||||
assert.deepEqual(f.assets.map((a) => a.name), ['wp-asciiplayer.zip', 'wp-asciiplayer.zip.sha256']);
|
||||
assert.equal(f.calls.filter((c) => c.method === 'POST').length, 4);
|
||||
assert.ok(f.calls.every((c) => c.headers.Authorization === 'Bearer test-only'));
|
||||
assert.ok(f.calls.every((c) => c.redirect === 'error'));
|
||||
assert.ok(!f.calls.some((c) => /\/git\/(refs|tags)$/.test(c.url.pathname) && c.method === 'POST'));
|
||||
});
|
||||
|
||||
test('rerun verifies provenance and bytes without changing draft or duplicating assets', async () => {
|
||||
const f = fixture();
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
const writes = f.calls.filter((c) => c.method === 'POST').length;
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.equal(f.calls.filter((c) => c.method === 'POST').length, writes);
|
||||
assert.equal(f.releases.length, 1);
|
||||
assert.equal(f.assets.length, 2);
|
||||
});
|
||||
|
||||
test('rerun recovers missing asset after interrupted upload', async () => {
|
||||
const f = fixture();
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
f.assets.pop();
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.equal(f.assets.length, 2);
|
||||
assert.equal(f.releases.length, 1);
|
||||
});
|
||||
|
||||
test('never modifies a published release', async () => {
|
||||
const f = fixture({ releases: [release('v1.2.0')] });
|
||||
await assert.rejects(createReleaseDraft({ ...options, fetchImpl: f.fetchImpl }), /published release/);
|
||||
assert.ok(f.calls.every((c) => c.method === 'GET'));
|
||||
});
|
||||
|
||||
test('refuses unrelated existing draft or duplicate releases', async () => {
|
||||
for (const releases of [[release('v1.2.0', { draft: true })], [release('v1.2.0'), release('v1.2.0')]]) {
|
||||
const f = fixture({ releases });
|
||||
await assert.rejects(createReleaseDraft({ ...options, fetchImpl: f.fetchImpl }), /provenance|Multiple releases/);
|
||||
assert.ok(f.calls.every((c) => c.method === 'GET'));
|
||||
}
|
||||
});
|
||||
|
||||
test('fails closed on missing, wrong or changed asset digest without replacing anything', async () => {
|
||||
for (const digest of [undefined, `sha256:${'0'.repeat(64)}`]) {
|
||||
const f = fixture();
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
f.assets[0].digest = digest;
|
||||
const count = f.calls.length;
|
||||
await assert.rejects(createReleaseDraft({ ...options, fetchImpl: f.fetchImpl }), /digest/);
|
||||
assert.ok(f.calls.slice(count).every((c) => c.method === 'GET'));
|
||||
}
|
||||
});
|
||||
|
||||
test('refuses changed local bytes before uploading or editing draft', async () => {
|
||||
const f = fixture();
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
await assert.rejects(createReleaseDraft({ ...options, zip: Buffer.concat([zip, Buffer.from('changed')]),
|
||||
fetchImpl: f.fetchImpl }), /provenance/);
|
||||
assert.equal(f.assets.length, 2);
|
||||
});
|
||||
|
||||
test('peels annotated tags to commit', async () => {
|
||||
const f = fixture({ annotated: true });
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.ok(f.calls.some((c) => c.url.pathname.includes('/git/tags/')));
|
||||
});
|
||||
|
||||
test('moved tag fails before creation or upload', async () => {
|
||||
for (const moveAt of [1, 2, 3]) {
|
||||
const f = fixture({ moveAt });
|
||||
await assert.rejects(createReleaseDraft({ ...options, fetchImpl: f.fetchImpl }), /no longer resolves/);
|
||||
assert.equal(f.assets.length, 0);
|
||||
if (moveAt < 3) assert.equal(f.created, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
test('upload conflict only succeeds when concurrently uploaded asset has matching digest', async () => {
|
||||
const f = fixture({ uploadConflict: true });
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.equal(f.assets.length, 2);
|
||||
});
|
||||
|
||||
test('validates every input before API access', async () => {
|
||||
const fetchImpl = () => { throw new Error('Unexpected network access'); };
|
||||
for (const patch of [{ tag: 'main' }, { version: '9.9.9' }, { commit: 'short' },
|
||||
{ repository: '../owner/repo' }, { token: '' }, { zip: Buffer.from('not zip') }, { zipName: '../bad.zip' }]) {
|
||||
await assert.rejects(createReleaseDraft({ ...options, ...patch, fetchImpl }),
|
||||
(error) => !error.message.includes('Unexpected network'));
|
||||
}
|
||||
});
|
||||
|
||||
test('checksum is deterministic and CLI rejects unknown and duplicate flags', async () => {
|
||||
const assets = prepareAssets(zip);
|
||||
assert.equal(assets[1].bytes.toString(), `${assets[0].sha256} wp-asciiplayer.zip\n`);
|
||||
await assert.rejects(main(['--publish', 'true'], {}), /Usage/);
|
||||
await assert.rejects(main(['--tag', 'a', '--tag', 'b'], {}), /Usage/);
|
||||
});
|
||||
|
||||
test('notes skip missing tags and unrelated branches in favor of a lower released ancestor', async () => {
|
||||
const f = fixture({ releases: ['v1.1.9', 'v1.1.8', 'v1.1.7'].map((tag) => release(tag)),
|
||||
comparisons: { 'v1.1.9': 'missing', 'v1.1.8': 'diverged' } });
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.equal(f.calls.find((c) => c.url.pathname.endsWith('generate-notes')).body.previous_tag_name, 'v1.1.7');
|
||||
});
|
||||
|
||||
test('no eligible predecessor uses explicit commit history instead of GitHub auto-selection', async () => {
|
||||
const f = fixture({ releases: [release('v1.1.0-rc.1', { prerelease: true })] });
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.ok(!f.calls.some((c) => c.url.pathname.endsWith('generate-notes')));
|
||||
assert.match(f.created.body, /Initial implementation/);
|
||||
assert.match(f.created.body, /No earlier eligible published release/);
|
||||
assert.equal(f.calls.find((c) => c.url.pathname.endsWith('/commits')).url.searchParams.get('sha'), commit);
|
||||
});
|
||||
|
||||
test('prerelease drafts set prerelease flag while remaining unpublished', async () => {
|
||||
const f = fixture();
|
||||
const tag = 'v1.2.0-rc.1';
|
||||
const fetchImpl = (input, init) => {
|
||||
if (input.includes('/git/ref/tags/')) {
|
||||
return Promise.resolve({ ok: true, status: 200,
|
||||
json: async () => ({ ref: `refs/tags/${tag}`, object: { type: 'commit', sha: commit } }) });
|
||||
}
|
||||
return f.fetchImpl(input, init);
|
||||
};
|
||||
await createReleaseDraft({ ...options, tag, version: '1.2.0-rc.1', fetchImpl });
|
||||
assert.equal(f.created.draft, true);
|
||||
assert.equal(f.created.prerelease, true);
|
||||
});
|
||||
|
||||
test('release and first-release history pagination includes later pages', async () => {
|
||||
const f = fixture();
|
||||
const fetchImpl = (input, init) => {
|
||||
const url = new URL(input);
|
||||
if (init.method === 'GET' && url.pathname.endsWith('/releases')) {
|
||||
const filler = Array.from({ length: 100 }, (_, i) => release(`v0.0.${i}`, { draft: true }));
|
||||
const page = url.searchParams.get('page');
|
||||
return Promise.resolve({ ok: true, status: 200,
|
||||
json: async () => page === '1' ? filler : f.releases });
|
||||
}
|
||||
if (url.pathname.endsWith('/commits')) {
|
||||
const page = url.searchParams.get('page');
|
||||
return Promise.resolve({ ok: true, status: 200, json: async () => page === '1'
|
||||
? Array.from({ length: 100 }, () => ({ sha: commit, commit: { message: 'Earlier change' } }))
|
||||
: [{ sha: 'b'.repeat(40), commit: { message: 'Oldest change on second page' } }] });
|
||||
}
|
||||
return f.fetchImpl(input, init);
|
||||
};
|
||||
await createReleaseDraft({ ...options, fetchImpl });
|
||||
assert.match(f.created.body, /Oldest change on second page/);
|
||||
await createReleaseDraft({ ...options, fetchImpl });
|
||||
assert.equal(f.releases.length, 1);
|
||||
});
|
||||
|
||||
test('deleted predecessor tag cannot resolve a same-named branch through compare API', async () => {
|
||||
const f = fixture({ releases: [release('v1.1.0')], comparisons: { 'v1.1.0': 'missing' } });
|
||||
await createReleaseDraft({ ...options, fetchImpl: f.fetchImpl });
|
||||
assert.ok(f.calls.some((c) => c.url.pathname.endsWith('/git/ref/tags/v1.1.0')));
|
||||
assert.ok(!f.calls.some((c) => c.url.pathname.includes('/compare/')));
|
||||
assert.ok(!f.calls.some((c) => c.url.pathname.endsWith('generate-notes')));
|
||||
});
|
||||
@@ -0,0 +1,118 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtemp, mkdir, writeFile, readFile, copyFile, rm } from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { parseTag, compareVersions, validateReleaseVersion } from '../../scripts/release-version.mjs';
|
||||
|
||||
const root = fileURLToPath(new URL('../../', import.meta.url));
|
||||
|
||||
test('strict SemVer accepts complete versions, optional v, prereleases and builds', () => {
|
||||
assert.deepEqual(parseTag('v1.2.3-rc.1+build.001'), {
|
||||
version: '1.2.3-rc.1+build.001', major: '1', minor: '2', patch: '3', prerelease: 'rc.1', build: 'build.001',
|
||||
});
|
||||
for (const version of ['0.0.0', '1.2.3', '1.2.3-dev', '1.2.3-0', '1.2.3-01a', '1.2.3--', '1.2.3+001', '999999999999999999999.0.0']) {
|
||||
assert.equal(parseTag(version)?.version, version);
|
||||
assert.equal(parseTag(`v${version}`)?.version, version);
|
||||
}
|
||||
});
|
||||
|
||||
test('strict SemVer rejects malformed and output-injection tags', () => {
|
||||
for (const version of [undefined, null, 123, '', '1', '1.2', 'V1.2.3', 'vv1.2.3', '01.2.3', '1.02.3', '1.2.03',
|
||||
'1.2.3-01', '1.2.3-a.01', '1.2.3-', '1.2.3+', '1.2.3-a..b', '1.2.3+abc..def', '1.2.3+abc+def',
|
||||
'1.2.3-a_b', '1.2.3+ä', ' 1.2.3', '1.2.3 ', '1.2.3\n', '1.2.3\r', '1.2.3\nvalid=true', 'refs/tags/v1.2.3']) {
|
||||
assert.equal(parseTag(version), null, JSON.stringify(version));
|
||||
}
|
||||
});
|
||||
|
||||
test('SemVer precedence handles numeric identifiers, releases, and large integers', () => {
|
||||
const ordered = ['1.0.0-alpha', '1.0.0-alpha.1', '1.0.0-alpha.beta', '1.0.0-beta', '1.0.0-beta.2', '1.0.0-beta.11', '1.0.0-rc.1', '1.0.0', '1.0.1', '1.1.0', '2.0.0'];
|
||||
for (let i = 1; i < ordered.length; i++) {
|
||||
assert.equal(compareVersions(ordered[i - 1], ordered[i]), -1);
|
||||
assert.equal(compareVersions(parseTag(ordered[i]), parseTag(ordered[i - 1])), 1);
|
||||
}
|
||||
assert.equal(compareVersions('1.2.3+aaa', 'v1.2.3+bbb'), 0);
|
||||
assert.equal(compareVersions('1.2.3-rc.1+aaa', '1.2.3-rc.1+bbb'), 0);
|
||||
assert.equal(compareVersions('9007199254740992.0.0', '9007199254740993.0.0'), -1);
|
||||
assert.equal(compareVersions('1.0.0-9007199254740992', '1.0.0-9007199254740993'), -1);
|
||||
assert.throws(() => compareVersions('nope', '1.0.0'), /invalid/);
|
||||
});
|
||||
|
||||
async function fixture(t, version = '1.2.3') {
|
||||
const dir = await mkdtemp(path.join(os.tmpdir(), 'release-version-test-'));
|
||||
t.after(() => rm(dir, { recursive: true, force: true }));
|
||||
await mkdir(path.join(dir, 'scripts'));
|
||||
await copyFile(path.join(root, 'scripts/release-version.mjs'), path.join(dir, 'scripts/release-version.mjs'));
|
||||
await Promise.all([
|
||||
writeFile(path.join(dir, 'package.json'), JSON.stringify({ version })),
|
||||
writeFile(path.join(dir, 'package-lock.json'), JSON.stringify({ version, packages: { '': { version } } })),
|
||||
writeFile(path.join(dir, 'block.json'), JSON.stringify({ version })),
|
||||
writeFile(path.join(dir, 'asciicast-player.php'), `<?php\n/**\n * Version: ${version}\n */\nconst VERSION = '${version}';\n`),
|
||||
writeFile(path.join(dir, 'readme.txt'), `=== Plugin ===\nStable tag: ${version}\n`),
|
||||
]);
|
||||
return dir;
|
||||
}
|
||||
|
||||
test('metadata validation accepts exact stable and prerelease/build metadata', async (t) => {
|
||||
for (const version of ['1.2.3', '1.2.3-rc.1+build.001']) {
|
||||
const dir = await fixture(t, version);
|
||||
assert.equal((await validateReleaseVersion(`v${version}`, dir)).version, version);
|
||||
}
|
||||
});
|
||||
|
||||
test('metadata validation accepts CRLF text files', async (t) => {
|
||||
const dir = await fixture(t);
|
||||
for (const file of ['asciicast-player.php', 'readme.txt']) {
|
||||
const source = await readFile(path.join(dir, file), 'utf8');
|
||||
await writeFile(path.join(dir, file), source.replaceAll('\n', '\r\n'));
|
||||
}
|
||||
assert.equal((await validateReleaseVersion('1.2.3', dir)).version, '1.2.3');
|
||||
});
|
||||
|
||||
test('every release metadata surface is required and compared exactly', async (t) => {
|
||||
const mutations = [
|
||||
['package.json', '{"version":"1.2.4"}', 'package.json version'],
|
||||
['package-lock.json', '{"version":"1.2.4","packages":{"":{"version":"1.2.3"}}}', 'package-lock.json version'],
|
||||
['package-lock.json', '{"version":"1.2.3","packages":{"":{"version":"1.2.4"}}}', 'packages[""] version'],
|
||||
['package-lock.json', '{"version":"1.2.3"}', 'missing'],
|
||||
['block.json', '{"version":"1.2.4"}', 'block.json version'],
|
||||
['asciicast-player.php', " * Version: 1.2.4\nconst VERSION = '1.2.3';\n", 'Version header'],
|
||||
['asciicast-player.php', " * Version: 1.2.3\nconst VERSION = '1.2.4';\n", 'VERSION constant'],
|
||||
['readme.txt', 'Stable tag: trunk\n', 'readme.txt Stable tag'],
|
||||
['readme.txt', 'Stable tag: v1.2.3\n', 'readme.txt Stable tag'],
|
||||
['readme.txt', 'Stable tag: 1.2.3\nStable tag: 1.2.3\n', 'exactly one'],
|
||||
['asciicast-player.php', ' * Version: 1.2.3\n', 'exactly one'],
|
||||
];
|
||||
for (const [file, content, error] of mutations) {
|
||||
const dir = await fixture(t);
|
||||
await writeFile(path.join(dir, file), content);
|
||||
await assert.rejects(validateReleaseVersion('v1.2.3', dir), (e) => e.message.includes(error));
|
||||
assert.equal(await readFile(path.join(dir, file), 'utf8'), content, 'validator must not rewrite files');
|
||||
}
|
||||
});
|
||||
|
||||
test('current development metadata cannot accidentally become a stable release', async (t) => {
|
||||
const dir = await fixture(t, '1.1.0-dev');
|
||||
await assert.rejects(validateReleaseVersion('v1.1.0', dir), /must exactly match 1.1.0/);
|
||||
assert.equal((await validateReleaseVersion('v1.1.0-dev', dir)).prerelease, 'dev');
|
||||
});
|
||||
|
||||
test('CLI writes trusted outputs only after successful validation', async (t) => {
|
||||
const dir = await fixture(t, '1.2.3-rc.1+001');
|
||||
const output = path.join(dir, 'output');
|
||||
const run = (tag) => spawnSync(process.execPath, ['scripts/release-version.mjs'], {
|
||||
cwd: dir, encoding: 'utf8', env: { ...process.env, RELEASE_TAG: tag, GITHUB_OUTPUT: output },
|
||||
});
|
||||
const success = run('v1.2.3-rc.1+001');
|
||||
assert.equal(success.status, 0, success.stderr);
|
||||
const expected = 'valid=true\nversion=1.2.3-rc.1+001\nprerelease=true\n';
|
||||
assert.equal(await readFile(output, 'utf8'), expected);
|
||||
for (const tag of ['v1.2.3', '', 'v1.2.3\nvalid=true']) {
|
||||
const failure = run(tag);
|
||||
assert.equal(failure.status, 1);
|
||||
assert.match(failure.stderr, /Release validation failed:/);
|
||||
assert.equal(await readFile(output, 'utf8'), expected);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const workflow = readFileSync(new URL('../../.github/workflows/ci.yml', import.meta.url), 'utf8');
|
||||
const job = (name) => workflow.match(new RegExp(`^ ${name}:\\n([\\s\\S]*?)(?=^ [a-z][a-z-]*:|$(?![\\s\\S]))`, 'm'))?.[1];
|
||||
|
||||
test('release writes are confined to a tag-only job after the full test graph', () => {
|
||||
assert.match(workflow, /permissions:\n contents: read/);
|
||||
assert.equal((workflow.match(/contents: write/g) || []).length, 1);
|
||||
assert.match(job('release-draft'), /if: github.event_name == 'push' && github.ref_type == 'tag'/);
|
||||
assert.match(job('release-draft'), /needs: \[release-validation, build, php-compatibility, wordpress, plugin-check\]/);
|
||||
assert.match(job('release-validation'), /git merge-base --is-ancestor HEAD origin\/main/);
|
||||
assert.match(job('release-validation'), /run: node scripts\/release-version.mjs/);
|
||||
for (const name of ['build', 'php-compatibility']) assert.match(job(name), /needs: release-validation/);
|
||||
assert.doesNotMatch(job('release-draft'), /npm (?:ci|install)|continue-on-error|pull_request_target/);
|
||||
});
|
||||
|
||||
test('release downloads the pristine producer ID and never a consumer artifact', () => {
|
||||
const release = job('release-draft');
|
||||
assert.match(release, /artifact-ids: \$\{\{ needs.build.outputs.package-artifact-id \}\}/);
|
||||
assert.doesNotMatch(release, /pattern:|run-id:|overwrite:/);
|
||||
assert.match(job('build'), /path: dist\/wp-asciiplayer.zip/);
|
||||
for (const name of ['wordpress', 'plugin-check']) {
|
||||
const upload = job(name).split('actions/upload-artifact@')[1];
|
||||
assert.ok(upload);
|
||||
assert.doesNotMatch(upload, /dist\/|\.zip/);
|
||||
}
|
||||
assert.match(release, /persist-credentials: false/);
|
||||
assert.match(release, /--tag "\$RELEASE_TAG" --version "\$RELEASE_VERSION"/);
|
||||
});
|
||||
|
||||
test('tag reruns serialize without cancelling an in-progress draft upload', () => {
|
||||
assert.match(workflow, /group: \$\{\{ github.workflow \}\}-\$\{\{ github.ref \}\}/);
|
||||
assert.match(workflow, /cancel-in-progress: \$\{\{ github.ref_type != 'tag' \}\}/);
|
||||
assert.match(workflow, /tags: \['\*\*'\]/);
|
||||
});
|
||||
Reference in New Issue
Block a user