Files
vac-optimizer/scripts/ci-policy.mjs
T
nessarandClaude Opus 5.5 40ee34ebd1
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
ci: replace GitFlow with a single main branch, tag releases and Komodo deployment
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>
2026-11-30 23:45:51 +01:00

47 lines
1.7 KiB
JavaScript

import { execFileSync, spawnSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { readCiContext } from './ci-context.mjs';
const git = (...args) => execFileSync('git', args, { encoding: 'utf8' }).trim();
const conventional = /^[a-z]+(?:\([^()\r\n]+\))?!?: \S.*$/i;
const requirePolicy = (condition, message) => {
if (!condition) throw new Error(message);
};
try {
const { commit, tag, pullRequest } = readCiContext();
requirePolicy(commit === git('rev-parse', 'HEAD'), 'CI must validate the checked-out commit.');
if (tag) {
requirePolicy(
/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(tag),
'Release tags must use vMAJOR.MINOR.PATCH without leading zeroes.',
);
const { version } = JSON.parse(readFileSync('package.json', 'utf8'));
requirePolicy(tag === `v${version}`, 'Release tag must match package.json.');
git('fetch', '--no-tags', 'origin', '+refs/heads/main:refs/remotes/origin/main');
requirePolicy(
spawnSync('git', ['merge-base', '--is-ancestor', commit, 'origin/main']).status === 0,
'Release commit must belong to main.',
);
} else if (pullRequest) {
// Only the PR's own commits, so inherited history never blocks a PR.
const range = `${pullRequest.base.sha}..${commit}`;
requirePolicy(
!git('rev-list', '--merges', range),
'Pull requests must not contain merge commits; rebase instead.',
);
const subjects = git('log', '--format=%h %s', range);
for (const line of subjects ? subjects.split('\n') : []) {
requirePolicy(
conventional.test(line.slice(line.indexOf(' ') + 1)),
`Commit must use Conventional Commits: ${line}`,
);
}
}
console.log('Commit and release policy passed.');
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}