CI / publish (pull_request) Skipped
CI / policy (pull_request) Successful in 12s
CI / build (pull_request) Successful in 32s
CI / validate (pull_request) Successful in 40s
CI / benchmark (pull_request) Successful in 1m17s
CI / test (pull_request) Successful in 3m15s
CI / required (pull_request) Successful in 3s
PRs into main run the commit check (only the PR's own commits, no merge commits), lint, format, type checks, tests, the benchmark and the build, gated by `required`. Editing a PR no longer reruns CI. A push to main builds one image, publishes it as sha-<commit> and beta, and redeploys the Komodo beta stack; a vX.Y.Z tag promotes that image to vX.Y.Z and latest and redeploys production. The deploy goes through the Komodo API and waits for the update, so a failed deployment fails the run. Removes the security scans, PR and branch-* images, the release/hotfix rules and the merge-message template. compose.prod.yml now pulls the registry image. Closes #391 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
2.9 KiB
JavaScript
86 lines
2.9 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const directory = mkdtempSync(join(tmpdir(), 'ci-policy-'));
|
|
const script = fileURLToPath(new URL('./ci-policy.mjs', import.meta.url));
|
|
const git = (...args) => execFileSync('git', args, { cwd: directory, encoding: 'utf8' }).trim();
|
|
const check = (variables = {}, expected = 0) => {
|
|
const commit = git('rev-parse', 'HEAD');
|
|
const eventName = variables.eventName ?? 'push';
|
|
const ref = variables.tag
|
|
? `refs/tags/${variables.tag}`
|
|
: eventName === 'pull_request'
|
|
? 'refs/pull/42/head'
|
|
: 'refs/heads/main';
|
|
const event = { ref };
|
|
if (eventName === 'pull_request') {
|
|
event.pull_request = {
|
|
head: { sha: variables.headSha ?? commit },
|
|
base: { sha: variables.base },
|
|
};
|
|
}
|
|
const eventPath = join(directory, 'event.json');
|
|
writeFileSync(eventPath, JSON.stringify(event));
|
|
const result = spawnSync(process.execPath, [script], {
|
|
cwd: directory,
|
|
encoding: 'utf8',
|
|
env: {
|
|
PATH: process.env.PATH,
|
|
GITHUB_EVENT_NAME: eventName,
|
|
GITHUB_EVENT_PATH: eventPath,
|
|
GITHUB_REF: ref,
|
|
GITHUB_SHA: variables.sha ?? commit,
|
|
},
|
|
});
|
|
assert.equal(result.status, expected, result.stdout + result.stderr);
|
|
};
|
|
|
|
try {
|
|
git('init', '--initial-branch=main');
|
|
git('config', 'user.name', 'CI policy test');
|
|
git('config', 'user.email', 'ci-policy@example.invalid');
|
|
git('remote', 'add', 'origin', directory);
|
|
writeFileSync(join(directory, 'package.json'), '{"version":"1.5.0"}\n');
|
|
git('add', 'package.json');
|
|
git('commit', '-m', 'Legacy history is allowed');
|
|
const main = git('rev-parse', 'HEAD');
|
|
git('switch', '-c', 'feature/test');
|
|
git('commit', '--allow-empty', '-m', 'feat(test)!: add checks');
|
|
const pr = { eventName: 'pull_request', base: main };
|
|
check(pr);
|
|
check({});
|
|
check({ eventName: 'workflow_dispatch' });
|
|
check({ ...pr, base: undefined }, 1);
|
|
check({ ...pr, headSha: '0'.repeat(40) }, 1);
|
|
check({ eventName: 'pull_request_target' }, 1);
|
|
check({ sha: '0'.repeat(40) }, 1);
|
|
|
|
// The range starts at whatever base the PR names.
|
|
git('commit', '--allow-empty', '-m', 'not conventional');
|
|
const stacked = git('rev-parse', 'HEAD');
|
|
git('commit', '--allow-empty', '-m', 'fix: follow up');
|
|
check(pr, 1);
|
|
check({ ...pr, base: stacked });
|
|
|
|
git('switch', 'main');
|
|
git('commit', '--allow-empty', '-m', 'fix: on main');
|
|
git('switch', 'feature/test');
|
|
git('merge', '--no-ff', 'main', '-m', 'chore: merge main');
|
|
check({ ...pr, base: stacked }, 1);
|
|
|
|
check({ tag: 'v1.5.0' }, 1);
|
|
git('switch', 'main');
|
|
check({ tag: 'v1.5.0' });
|
|
check({ tag: 'v1.6.0' }, 1);
|
|
check({ tag: 'v01.5.0' }, 1);
|
|
check({ tag: 'v1.5.0-rc.1' }, 1);
|
|
|
|
console.log('CI policy integration checks passed.');
|
|
} finally {
|
|
rmSync(directory, { recursive: true, force: true });
|
|
}
|