@jakobm/peacekeeper 0.29.0 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -48
- package/dist/cmdabra.yaml +5 -5
- package/dist/package.json +5 -5
- package/dist/src/container.js +4 -2
- package/dist/src/modules/implementations/+module-cli/cli-public.js +2 -0
- package/dist/src/modules/{cli → implementations/+module-cli}/legacy-commands.js +0 -5
- package/dist/src/modules/{cli → implementations/+module-cli}/service.js +2 -2
- package/dist/src/modules/{configuration/facade.js → implementations/+module-configuration/configuration-public.js} +2 -1
- package/dist/src/modules/{configuration → implementations/+module-configuration}/project-config-defaults.json +2 -1
- package/dist/src/modules/{configuration → implementations/+module-configuration}/project-config.js +7 -1
- package/dist/src/modules/{lifecycle/facade.js → implementations/+module-lifecycle/lifecycle-public.js} +2 -1
- package/dist/src/modules/{maintenance/facade.js → implementations/+module-maintenance/maintenance-public.js} +2 -1
- package/dist/src/modules/{projects → implementations/+module-projects}/check-project-requirements.txt +36 -13
- package/dist/src/modules/{projects → implementations/+module-projects}/check-project.js +3 -3
- package/dist/src/modules/{projects → implementations/+module-projects}/create-project-core.js +1 -1
- package/dist/src/modules/{projects/facade.js → implementations/+module-projects/projects-public.js} +2 -1
- package/dist/src/modules/{releases → implementations/+module-releases}/assess-release-core.js +6 -5
- package/dist/src/modules/implementations/+module-releases/check-github.js +27 -0
- package/dist/src/modules/{releases → implementations/+module-releases}/github-policy.js +1 -1
- package/dist/src/modules/{releases → implementations/+module-releases}/release-core.js +63 -14
- package/dist/src/modules/{releases → implementations/+module-releases}/release.js +2 -1
- package/dist/src/modules/{releases/facade.js → implementations/+module-releases/releases-public.js} +3 -2
- package/dist/src/modules/{releases → implementations/+module-releases}/reusable-workflows.js +1 -1
- package/dist/src/modules/{releases → implementations/+module-releases}/reusable-workflows.json +1 -1
- package/dist/src/modules/{releases → implementations/+module-releases}/verify-release-core.js +4 -4
- package/dist/src/modules/implementations/+module-releases/version-history.js +27 -0
- package/dist/src/modules/{testing/facade.js → implementations/+module-testing/testing-public.js} +2 -1
- package/dist/src/modules/{external.js → implementations/external.js} +6 -6
- package/package.json +5 -5
- package/dist/src/modules/cli/facade.js +0 -1
- package/dist/src/modules/releases/verify-release-protection.js +0 -25
- /package/dist/src/modules/{cli → implementations/+module-cli}/types.js +0 -0
- /package/dist/src/modules/{configuration → implementations/+module-configuration}/convention-rules.js +0 -0
- /package/dist/src/modules/{configuration → implementations/+module-configuration}/update-config.js +0 -0
- /package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/checkpoint-codex-changes.js +0 -0
- /package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/checkpoint-codex-session-start.js +0 -0
- /package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/checkpoint-codex-stop.js +0 -0
- /package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/checkpoint-instructions.js +0 -0
- /package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/cleanup-ended-session.js +0 -0
- /package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/log-script-invocation.js +0 -0
- /package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/queue-merged-worktree-cleanup.js +0 -0
- /package/dist/src/modules/{maintenance → implementations/+module-maintenance}/cleanup-merged-branches.js +0 -0
- /package/dist/src/modules/{maintenance → implementations/+module-maintenance}/initialize-codex-worktree.js +0 -0
- /package/dist/src/modules/{maintenance → implementations/+module-maintenance}/remove-empty-directories.js +0 -0
- /package/dist/src/modules/{projects → implementations/+module-projects}/create-project.js +0 -0
- /package/dist/src/modules/{projects → implementations/+module-projects}/generate-github-setup.js +0 -0
- /package/dist/src/modules/{projects → implementations/+module-projects}/github-setup-prefix.sh +0 -0
- /package/dist/src/modules/{projects → implementations/+module-projects}/github-setup-repository-template.sh +0 -0
- /package/dist/src/modules/{projects → implementations/+module-projects}/github-setup-suffix-template.sh +0 -0
- /package/dist/src/modules/{projects → implementations/+module-projects}/install-hooks.js +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/assess-release-schema.json +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/assess-release.js +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/configure-github.js +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/github-base-protection-policy.json +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/github-configuration.js +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/github-owner-approval-policy.json +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/github-remote.js +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/release-protection.js +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/verify-release-version.js +0 -0
- /package/dist/src/modules/{releases → implementations/+module-releases}/verify-release.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/check-conventions.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/check-test-receipt.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/conventions.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/prepare-tests.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/receipt-state.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/record-test-receipt.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/run-tests.js +0 -0
- /package/dist/src/modules/{testing → implementations/+module-testing}/types.js +0 -0
- /package/dist/src/modules/{cli/interface.js → interfaces/cli.js} +0 -0
- /package/dist/src/modules/{configuration/interface.js → interfaces/configuration.js} +0 -0
- /package/dist/src/modules/{dependencies.yaml → interfaces/dependencies.yaml} +0 -0
- /package/dist/src/modules/{lifecycle/interface.js → interfaces/lifecycle.js} +0 -0
- /package/dist/src/modules/{maintenance/interface.js → interfaces/maintenance.js} +0 -0
- /package/dist/src/modules/{projects/interface.js → interfaces/projects.js} +0 -0
- /package/dist/src/modules/{releases/interface.js → interfaces/releases.js} +0 -0
- /package/dist/src/modules/{testing/interface.js → interfaces/testing.js} +0 -0
|
@@ -252,7 +252,7 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
252
252
|
const steps = job.steps || [];
|
|
253
253
|
const installed = steps.findIndex(step => directCommand(step, installCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
254
254
|
const tested = steps.findIndex(step => directCommand(step, testCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
255
|
-
const policy = steps.findIndex(step => directCommand(step, /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js)
|
|
255
|
+
const policy = steps.findIndex(step => directCommand(step, /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) github check$/u)
|
|
256
256
|
&& unconditional(step.if) && !step['continue-on-error'] && step.env?.GH_TOKEN);
|
|
257
257
|
if (policy > installed && installed >= 0 && policy < tested && config.git.releaseRequiredChecks.includes(job.name || id))
|
|
258
258
|
policyJobs += 1;
|
|
@@ -267,7 +267,7 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
267
267
|
checked.clear();
|
|
268
268
|
requiredJob(...matching[0], true);
|
|
269
269
|
}
|
|
270
|
-
requireThat(policyJobs > 0, `${filename}: a job in git.releaseRequiredChecks must run unconditional
|
|
270
|
+
requireThat(policyJobs > 0, `${filename}: a job in git.releaseRequiredChecks must run unconditional github check with GH_TOKEN after npm ci and before tests.`);
|
|
271
271
|
});
|
|
272
272
|
if (published)
|
|
273
273
|
check('publication', () => {
|
|
@@ -311,7 +311,7 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
311
311
|
}
|
|
312
312
|
function main({ explain = false } = {}) {
|
|
313
313
|
if (explain) {
|
|
314
|
-
runtime.stdout.write(fs.readFileSync(path.join(modulesRoot, 'projects/check-project-requirements.txt'), 'utf8'));
|
|
314
|
+
runtime.stdout.write(fs.readFileSync(path.join(modulesRoot, 'implementations/+module-projects/check-project-requirements.txt'), 'utf8'));
|
|
315
315
|
return;
|
|
316
316
|
}
|
|
317
317
|
output.log('Run peacekeeper project check --explain for the complete expected project architecture and requirements.');
|
package/dist/src/modules/{projects → implementations/+module-projects}/create-project-core.js
RENAMED
|
@@ -74,7 +74,7 @@ export default ({ releases, external: { fs, modulesRoot, packageVersion, path, p
|
|
|
74
74
|
}, { lineWidth: 0 });
|
|
75
75
|
}
|
|
76
76
|
function renderTemplate(filename, replacements) {
|
|
77
|
-
let template = fs.readFileSync(path.join(modulesRoot, `projects/${filename}`), 'utf8');
|
|
77
|
+
let template = fs.readFileSync(path.join(modulesRoot, `implementations/+module-projects/${filename}`), 'utf8');
|
|
78
78
|
const placeholders = [...template.matchAll(/\{\{([A-Z_]+)\}\}/gu)].map(match => match[1]);
|
|
79
79
|
const unknown = placeholders.find(name => !Object.hasOwn(replacements, name));
|
|
80
80
|
if (unknown)
|
package/dist/src/modules/{projects/facade.js → implementations/+module-projects/projects-public.js}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export const createPorticoModule = ({ checkProject, createProject, generateGithubSetup, installHooks }) => ({
|
|
2
3
|
checkProject: checkProject.run,
|
|
3
4
|
createProject: createProject.run,
|
|
4
5
|
generateGithubSetup: generateGithubSetup.run,
|
package/dist/src/modules/{releases → implementations/+module-releases}/assess-release-core.js
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export default ({ configuration, releaseCore, external: { assessReleaseSchema: schema, fs, modulesRoot, os, path, runtime, semver, spawnSync: defaultSpawnSync, } }) => {
|
|
2
2
|
const { projectConfig } = configuration;
|
|
3
3
|
const { originRepository } = releaseCore;
|
|
4
|
-
function assessmentPrompt({ name, version, previousReleaseSha, releaseSha }) {
|
|
4
|
+
function assessmentPrompt({ name, version, targetVersion, previousReleaseSha, releaseSha }) {
|
|
5
5
|
return `Assess whether ${JSON.stringify(name)} needs a new npm release. This is an assessment only.
|
|
6
6
|
The last published stable version is ${version}, at commit ${previousReleaseSha}.
|
|
7
|
+
The target package version is ${targetVersion}; an existing version bump is not evidence of the required release level.
|
|
7
8
|
The target is commit ${releaseSha}, the fetched default branch. Assess ONLY ${previousReleaseSha}..${releaseSha}.
|
|
8
9
|
Inspect the complete changes with git diff, git log and git show. Read relevant source files,
|
|
9
10
|
README, package metadata and tests to understand the public API, CLI and user-visible behavior.
|
|
@@ -94,8 +95,8 @@ Do not delegate or launch other agents. Only read and assess; do not execute the
|
|
|
94
95
|
const candidateSha = run('git', ['rev-parse', '--verify', `${ref}^{commit}`]);
|
|
95
96
|
run('git', ['merge-base', '--is-ancestor', candidateSha, releaseSha]);
|
|
96
97
|
const baseline = JSON.parse(run('git', ['show', `${candidateSha}:package.json`]));
|
|
97
|
-
if (baseline.name !== name || baseline.version !== version
|
|
98
|
-
throw new Error('Published version
|
|
98
|
+
if (baseline.name !== name || baseline.version !== version) {
|
|
99
|
+
throw new Error('Published version and release tag package metadata disagree.');
|
|
99
100
|
}
|
|
100
101
|
const metadata = JSON.parse(run('npm', ['view', `${name}@${version}`, '--json',
|
|
101
102
|
'--registry', 'https://registry.npmjs.org/', '--prefer-online']));
|
|
@@ -109,9 +110,9 @@ Do not delegate or launch other agents. Only read and assess; do not execute the
|
|
|
109
110
|
const output = path.join(temporary, 'assessment.json');
|
|
110
111
|
run('codex', ['exec', '--sandbox', 'read-only', '-c', 'approval_policy="never"',
|
|
111
112
|
'-c', 'model_reasoning_effort="low"', '-c', 'model_verbosity="low"',
|
|
112
|
-
'--ephemeral', '--output-schema', path.join(modulesRoot, 'releases/assess-release-schema.json'),
|
|
113
|
+
'--ephemeral', '--output-schema', path.join(modulesRoot, 'implementations/+module-releases/assess-release-schema.json'),
|
|
113
114
|
'--output-last-message', output, '-'], worktree, {
|
|
114
|
-
input: assessmentPrompt({ name, version, previousReleaseSha, releaseSha }), timeout: 20 * 60_000,
|
|
115
|
+
input: assessmentPrompt({ name, version, targetVersion: manifest.version, previousReleaseSha, releaseSha }), timeout: 20 * 60_000,
|
|
115
116
|
});
|
|
116
117
|
const { recommendation, motivation } = validateAssessment(JSON.parse(fs.readFileSync(output, 'utf8')));
|
|
117
118
|
return { recommendation, model, releaseSha, previousReleaseSha, motivation };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ configuration, releaseCore, releaseProtection, versionHistory, external: { output, runtime, spawnSync, } }) => {
|
|
3
|
+
function check(cwd = runtime.cwd()) {
|
|
4
|
+
const config = configuration.projectConfig(cwd);
|
|
5
|
+
const remote = spawnSync('git', ['remote', 'get-url', config.git.remote], { cwd, encoding: 'utf8' });
|
|
6
|
+
if (remote.status !== 0)
|
|
7
|
+
throw new Error(remote.stderr);
|
|
8
|
+
const { host, slug } = releaseCore.originRepository(remote.stdout.trim());
|
|
9
|
+
const api = releaseProtection.githubApi((command, args, options) => spawnSync(command, args, { ...options, encoding: 'utf8' }), cwd, host);
|
|
10
|
+
const branch = api(`repos/${slug}`).default_branch;
|
|
11
|
+
releaseProtection.verifyProtection({ api, slug, branch,
|
|
12
|
+
...releaseProtection.requiredPolicy(cwd), warn: message => output.warn(message) });
|
|
13
|
+
if (config.strictVersionHistory) {
|
|
14
|
+
versionHistory.verifyVersionHistory({ api, slug, branch, root: config.root });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function run() {
|
|
18
|
+
try {
|
|
19
|
+
check();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
output.error(error instanceof Error ? error.message : String(error));
|
|
23
|
+
runtime.exitCode = 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { run };
|
|
27
|
+
};
|
|
@@ -2,7 +2,7 @@ export default ({ external: { fs, modulesRoot, path, structuredClone } }) => {
|
|
|
2
2
|
const ownerIdMarker = '__PEACEKEEPER_OWNER_ID__';
|
|
3
3
|
const directive = '$peacekeeper';
|
|
4
4
|
function readDocument(filename) {
|
|
5
|
-
const file = path.join(modulesRoot, `releases/${filename}`);
|
|
5
|
+
const file = path.join(modulesRoot, `implementations/+module-releases/${filename}`);
|
|
6
6
|
try {
|
|
7
7
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
8
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default ({ configuration, releaseProtection, reusableWorkflows, external: { clock, fs, os, path, runtime, url: Url, YAML: yaml, } }) => {
|
|
1
|
+
export default ({ configuration, releaseProtection, reusableWorkflows, verifyReleaseCore, external: { clock, fs, os, path, runtime, url: Url, YAML: yaml, } }) => {
|
|
2
2
|
const { bypassWarning, githubApi, requiredPolicy, verifyProtection } = releaseProtection;
|
|
3
3
|
const { projectConfig } = configuration;
|
|
4
4
|
const requiredCondition = "${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}";
|
|
@@ -245,11 +245,24 @@ export default ({ configuration, releaseProtection, reusableWorkflows, external:
|
|
|
245
245
|
throw new ReleaseError('GitHub did not provide the default branch.');
|
|
246
246
|
}
|
|
247
247
|
verifyProtection({ api: githubApi(exec, cwd, host), slug, branch: defaultBranch, ...requiredPolicy(cwd) });
|
|
248
|
-
checked(exec, 'git', ['fetch', 'origin', defaultBranch], cwd);
|
|
249
|
-
const
|
|
248
|
+
checked(exec, 'git', ['fetch', 'origin', `+refs/heads/${defaultBranch}:refs/remotes/origin/${defaultBranch}`], cwd);
|
|
249
|
+
const sourceSha = checked(exec, 'git', ['rev-parse', `origin/${defaultBranch}`], cwd);
|
|
250
|
+
const configFile = checked(exec, 'git', ['ls-tree', '--name-only', sourceSha, '--', 'peacekeeper.config.yaml'], cwd);
|
|
251
|
+
const sourceConfig = configFile
|
|
252
|
+
? yaml.parse(checkedOutput(exec, 'git', ['show', `${sourceSha}:peacekeeper.config.yaml`], cwd)) : {};
|
|
253
|
+
if (sourceConfig?.strictVersionHistory === true && bump) {
|
|
254
|
+
throw new ReleaseError('strictVersionHistory requires versions to be assigned before merging. Run npm run release without --bump.');
|
|
255
|
+
}
|
|
256
|
+
const manifest = JSON.parse(checkedOutput(exec, 'git', ['show', `${sourceSha}:package.json`], cwd));
|
|
250
257
|
const packageInfo = { name: manifest.name, version: manifest.version };
|
|
251
|
-
|
|
258
|
+
if (typeof packageInfo.name !== 'string' || !packageInfo.name
|
|
259
|
+
|| typeof packageInfo.version !== 'string' || !stableVersion.test(packageInfo.version) || manifest.workspaces) {
|
|
260
|
+
throw new ReleaseError('Default branch needs a named root package with a stable MAJOR.MINOR.PATCH version and no workspaces.');
|
|
261
|
+
}
|
|
262
|
+
const version = bump ? nextVersion(packageInfo.version, bump) : packageInfo.version;
|
|
252
263
|
const tag = `v${version}`;
|
|
264
|
+
const details = { host, slug, defaultBranch, sourceSha, name: packageInfo.name, version, tag, mergeMethod };
|
|
265
|
+
ensureUnpublished(exec, cwd, details);
|
|
253
266
|
const localTag = exec('git', ['show-ref', '--verify', '--quiet', `refs/tags/${tag}`], { cwd });
|
|
254
267
|
if (localTag.status === 0)
|
|
255
268
|
throw new ReleaseError(`Local tag ${tag} already exists.`);
|
|
@@ -261,7 +274,31 @@ export default ({ configuration, releaseProtection, reusableWorkflows, external:
|
|
|
261
274
|
if (remoteTag.status !== 2)
|
|
262
275
|
throw new ReleaseError(`Could not check origin tag ${tag}: ${remoteTag.stderr.trim()}`);
|
|
263
276
|
log(`Validated ${packageInfo.name}: ${packageInfo.version} -> ${version} on ${defaultBranch}.`);
|
|
264
|
-
return
|
|
277
|
+
return details;
|
|
278
|
+
}
|
|
279
|
+
function ensureUnpublished(exec, cwd, details) {
|
|
280
|
+
const cache = fs.mkdtempSync(path.join(os.tmpdir(), 'peacekeeper-registry-'));
|
|
281
|
+
try {
|
|
282
|
+
const result = exec('npm', ['view', `${details.name}@${details.version}`, '--json',
|
|
283
|
+
'--registry', 'https://registry.npmjs.org/', '--prefer-online', '--cache', cache], { cwd });
|
|
284
|
+
let metadata;
|
|
285
|
+
try {
|
|
286
|
+
metadata = JSON.parse(result.stdout);
|
|
287
|
+
}
|
|
288
|
+
catch { /* Report the command failure below. */ }
|
|
289
|
+
if (result.status !== 0) {
|
|
290
|
+
if (metadata?.error?.code === 'E404')
|
|
291
|
+
return;
|
|
292
|
+
throw new ReleaseError(`Cannot check npm publication: ${result.stderr.trim() || result.stdout.trim() || `exit ${result.status}`}`);
|
|
293
|
+
}
|
|
294
|
+
if (metadata?.name !== details.name || metadata?.version !== details.version) {
|
|
295
|
+
throw new ReleaseError('npm returned unexpected package metadata while checking publication.');
|
|
296
|
+
}
|
|
297
|
+
throw new ReleaseError(`${details.name}@${details.version} is already published. Assign a new version before merging when strictVersionHistory is enabled; otherwise use npm run release -- --bump patch, minor, or major.`);
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
fs.rmSync(cache, { recursive: true, force: true });
|
|
301
|
+
}
|
|
265
302
|
}
|
|
266
303
|
function makeVersionCommit(exec, cwd, bump, version) {
|
|
267
304
|
checked(exec, 'npm', ['version', bump, '--no-git-tag-version', '--ignore-scripts'], cwd);
|
|
@@ -434,7 +471,7 @@ export default ({ configuration, releaseProtection, reusableWorkflows, external:
|
|
|
434
471
|
if (fs.existsSync(statePath)) {
|
|
435
472
|
details = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
436
473
|
if (details.bump !== bump)
|
|
437
|
-
throw new ReleaseError(`An unfinished ${details.bump
|
|
474
|
+
throw new ReleaseError(`An unfinished release exists; retry with ${details.bump ? `--bump ${details.bump}` : 'no --bump'}.`);
|
|
438
475
|
const origin = originRepository(checked(exec, 'git', ['remote', 'get-url', 'origin'], cwd));
|
|
439
476
|
if (origin.host !== details.host || origin.slug !== details.slug)
|
|
440
477
|
throw new ReleaseError('Origin differs from the unfinished release repository.');
|
|
@@ -452,21 +489,25 @@ export default ({ configuration, releaseProtection, reusableWorkflows, external:
|
|
|
452
489
|
break;
|
|
453
490
|
}
|
|
454
491
|
details.bump = bump;
|
|
455
|
-
|
|
492
|
+
if (bump)
|
|
493
|
+
details.branch = `release/${details.tag}`;
|
|
494
|
+
checked(exec, 'git', ['update-ref', `refs/peacekeeper/releases/${details.tag}`, details.sourceSha], cwd);
|
|
456
495
|
saveState(statePath, details);
|
|
457
496
|
}
|
|
458
497
|
temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'peacekeeper-release-worktree-'));
|
|
459
498
|
worktree = path.join(temporary, 'repo');
|
|
460
499
|
if (!details.sha) {
|
|
461
|
-
checked(exec, 'git', ['worktree', 'add', '--detach', worktree,
|
|
500
|
+
checked(exec, 'git', ['worktree', 'add', '--detach', worktree, details.sourceSha], cwd);
|
|
462
501
|
const baseline = readPackage(worktree);
|
|
463
|
-
if (baseline.name !== details.name || nextVersion(baseline.version, bump) !== details.version)
|
|
502
|
+
if (baseline.name !== details.name || (bump ? nextVersion(baseline.version, bump) : baseline.version) !== details.version)
|
|
464
503
|
throw new ReleaseError('Default branch version changed before release preparation completed; inspect release state.');
|
|
504
|
+
if (projectConfig(worktree).strictVersionHistory && bump)
|
|
505
|
+
throw new ReleaseError('strictVersionHistory on the default branch requires releasing without --bump.');
|
|
465
506
|
ensureLockfilesMatch(worktree, baseline.version);
|
|
466
507
|
inspectWorkflow(worktree, details.tag);
|
|
467
508
|
const sourceSha = checked(exec, 'git', ['rev-parse', 'HEAD'], worktree);
|
|
468
509
|
log(`Preparing release from origin/${details.defaultBranch} at ${sourceSha}.`);
|
|
469
|
-
details.sha = makeVersionCommit(exec, worktree, bump, details.version);
|
|
510
|
+
details.sha = bump ? makeVersionCommit(exec, worktree, bump, details.version) : sourceSha;
|
|
470
511
|
// Keep the commit reachable if interrupted before the remote push.
|
|
471
512
|
checked(exec, 'git', ['update-ref', `refs/peacekeeper/releases/${details.tag}`, details.sha], cwd);
|
|
472
513
|
saveState(statePath, details);
|
|
@@ -474,7 +515,7 @@ export default ({ configuration, releaseProtection, reusableWorkflows, external:
|
|
|
474
515
|
else {
|
|
475
516
|
checked(exec, 'git', ['worktree', 'add', '--detach', worktree, details.sha], cwd);
|
|
476
517
|
}
|
|
477
|
-
if (!details.pr) {
|
|
518
|
+
if (bump && !details.pr) {
|
|
478
519
|
checked(exec, 'git', ['push', 'origin', `${details.sha}:refs/heads/${details.branch}`], cwd);
|
|
479
520
|
const existing = github(exec, cwd, details.host, `repos/${details.slug}/pulls`, {
|
|
480
521
|
state: 'all', head: `${details.slug.split('/')[0]}:${details.branch}`, base: details.defaultBranch,
|
|
@@ -498,9 +539,12 @@ export default ({ configuration, releaseProtection, reusableWorkflows, external:
|
|
|
498
539
|
}
|
|
499
540
|
saveState(statePath, details);
|
|
500
541
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
542
|
+
let sha = details.sha;
|
|
543
|
+
if (bump) {
|
|
544
|
+
log(`Release PR: https://${details.host}/${details.slug}/pull/${details.pr}`);
|
|
545
|
+
sha = await mergeRelease(exec, cwd, details, now, sleep, log);
|
|
546
|
+
}
|
|
547
|
+
checked(exec, 'git', ['fetch', 'origin', `+refs/heads/${details.defaultBranch}:refs/remotes/origin/${details.defaultBranch}`], cwd);
|
|
504
548
|
checked(exec, 'git', ['merge-base', '--is-ancestor', sha, `origin/${details.defaultBranch}`], cwd);
|
|
505
549
|
checked(exec, 'git', ['checkout', '--detach', sha], worktree);
|
|
506
550
|
const manifest = readPackage(worktree);
|
|
@@ -508,10 +552,15 @@ export default ({ configuration, releaseProtection, reusableWorkflows, external:
|
|
|
508
552
|
throw new ReleaseError('Merged package does not match the intended release.');
|
|
509
553
|
ensureLockfilesMatch(worktree, details.version);
|
|
510
554
|
details.workflow = inspectWorkflow(worktree, details.tag);
|
|
555
|
+
const config = projectConfig(worktree);
|
|
556
|
+
verifyReleaseCore.verifyRelease({ api: githubApi(exec, cwd, details.host), slug: details.slug,
|
|
557
|
+
sha, tag: details.tag, branch: details.defaultBranch, ...requiredPolicy(worktree),
|
|
558
|
+
workflow: config.git.releaseTestWorkflow, warn: log });
|
|
511
559
|
const remote = checked(exec, 'git', ['ls-remote', '--tags', 'origin', `refs/tags/${details.tag}`, `refs/tags/${details.tag}^{}`], cwd);
|
|
512
560
|
if (remote && !remote.split('\n').some((line) => line.startsWith(`${sha}\t`)))
|
|
513
561
|
throw new ReleaseError(`Origin tag ${details.tag} points to another commit.`);
|
|
514
562
|
if (!remote) {
|
|
563
|
+
ensureUnpublished(exec, worktree, details);
|
|
515
564
|
const local = exec('git', ['rev-parse', '--verify', `refs/tags/${details.tag}^{commit}`], { cwd });
|
|
516
565
|
if (local.status === 0 && local.stdout.trim() !== sha)
|
|
517
566
|
throw new ReleaseError(`Local tag ${details.tag} points to another commit.`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// --- Implementation ---
|
|
1
2
|
export default ({ releaseCore, external: { clock, output, runtime, spawnSync } }) => {
|
|
2
3
|
const { release } = releaseCore;
|
|
3
4
|
async function main(bump) {
|
|
@@ -10,7 +11,7 @@ export default ({ releaseCore, external: { clock, output, runtime, spawnSync } }
|
|
|
10
11
|
log: (message) => output.log(`${clock.date().toTimeString().slice(0, 8)} ${message}`),
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
|
-
async function run(bump) {
|
|
14
|
+
async function run({ bump } = {}) {
|
|
14
15
|
try {
|
|
15
16
|
await main(bump);
|
|
16
17
|
}
|
package/dist/src/modules/{releases/facade.js → implementations/+module-releases/releases-public.js}
RENAMED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export const createPorticoModule = ({ assessRelease, checkGithub, configureGithub, githubConfiguration, githubPolicy, release, releaseCore, reusableWorkflows, verifyRelease, verifyReleaseVersion }) => ({
|
|
2
3
|
assessRelease: assessRelease.run,
|
|
4
|
+
checkGithub: checkGithub.run,
|
|
3
5
|
configureGithub: configureGithub.run,
|
|
4
6
|
planGithub: githubConfiguration.plan,
|
|
5
7
|
createGithubPolicy: githubPolicy.createGithubPolicy,
|
|
@@ -9,6 +11,5 @@ export const porticoFacade = ({ assessRelease, configureGithub, githubConfigurat
|
|
|
9
11
|
reusableWorkflowErrors: reusableWorkflows.callErrors,
|
|
10
12
|
release: release.run,
|
|
11
13
|
verifyRelease: verifyRelease.run,
|
|
12
|
-
verifyReleaseProtection: verifyReleaseProtection.run,
|
|
13
14
|
verifyReleaseVersion: verifyReleaseVersion.run,
|
|
14
15
|
});
|
package/dist/src/modules/{releases → implementations/+module-releases}/reusable-workflows.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// --- Implementation ---
|
|
2
2
|
export default ({ external: { fs, modulesRoot, path } }) => {
|
|
3
|
-
const definitions = JSON.parse(fs.readFileSync(path.join(modulesRoot, 'releases/reusable-workflows.json'), 'utf8'));
|
|
3
|
+
const definitions = JSON.parse(fs.readFileSync(path.join(modulesRoot, 'implementations/+module-releases/reusable-workflows.json'), 'utf8'));
|
|
4
4
|
function definition(kind) {
|
|
5
5
|
return definitions[kind];
|
|
6
6
|
}
|
package/dist/src/modules/{releases → implementations/+module-releases}/verify-release-core.js
RENAMED
|
@@ -24,18 +24,18 @@ export default ({ releaseProtection }) => {
|
|
|
24
24
|
const pulls = list(api, `${base}/commits/${commit.sha}/pulls`);
|
|
25
25
|
const pull = pulls.find(pr => pr.merged_at && pr.merge_commit_sha === commit.sha &&
|
|
26
26
|
pr.base.ref === branch && pr.base.repo.full_name === slug &&
|
|
27
|
-
pr.head.repo?.full_name === slug
|
|
27
|
+
pr.head.repo?.full_name === slug);
|
|
28
28
|
if (!pull)
|
|
29
|
-
throw new Error('Tag must point to a merged
|
|
29
|
+
throw new Error('Tag must point to a merged PR');
|
|
30
30
|
const runs = list(api, `${base}/actions/workflows/${encodeURIComponent(workflow)}/runs?event=pull_request&head_sha=${pull.head.sha}`, 'workflow_runs');
|
|
31
31
|
const run = runs.sort((a, b) => b.run_number - a.run_number)[0];
|
|
32
32
|
if (!run || run.conclusion !== 'success')
|
|
33
|
-
throw new Error('
|
|
33
|
+
throw new Error('Tagged PR must have a successful CI run');
|
|
34
34
|
const jobs = list(api, `${base}/actions/runs/${run.id}/jobs?filter=latest`, 'jobs');
|
|
35
35
|
for (const name of checks) {
|
|
36
36
|
const matching = jobs.filter(job => job.name === name);
|
|
37
37
|
if (!matching.length || matching.some(job => job.conclusion !== 'success')) {
|
|
38
|
-
throw new Error(`
|
|
38
|
+
throw new Error(`Tagged PR requires successful ${name} check`);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ external: { buffer: Buffer, fs, path, semver } }) => {
|
|
3
|
+
function verifyVersionHistory({ api, slug, branch, root }) {
|
|
4
|
+
const base = `repos/${slug}`;
|
|
5
|
+
const ref = api(`${base}/git/ref/heads/${encodeURIComponent(branch)}`);
|
|
6
|
+
const commit = ref?.object;
|
|
7
|
+
if (commit?.type !== 'commit' || typeof commit.sha !== 'string' || !/^[a-f0-9]{40}$/u.test(commit.sha)) {
|
|
8
|
+
throw new Error('Cannot determine the default branch commit for version history verification.');
|
|
9
|
+
}
|
|
10
|
+
// Pin the file lookup so a concurrent merge cannot change its source revision.
|
|
11
|
+
const file = api(`${base}/contents/package.json?ref=${commit.sha}`);
|
|
12
|
+
if (file.type !== 'file' || file.encoding !== 'base64' || typeof file.content !== 'string') {
|
|
13
|
+
throw new Error('Cannot read package.json from the default branch for version history verification.');
|
|
14
|
+
}
|
|
15
|
+
const previous = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')).version;
|
|
16
|
+
const current = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version;
|
|
17
|
+
for (const [source, version] of [['Default branch', previous], ['Incoming', current]]) {
|
|
18
|
+
if (typeof version !== 'string' || semver.valid(version) !== version.split('+')[0]) {
|
|
19
|
+
throw new Error(`${source} package.json must have a valid exact semver version.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!semver.gt(current, previous)) {
|
|
23
|
+
throw new Error(`strictVersionHistory requires package.json version ${current} to be greater than ${previous} on default branch ${branch} (${commit.sha}). Bump the version before merging.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { verifyVersionHistory };
|
|
27
|
+
};
|
package/dist/src/modules/{testing/facade.js → implementations/+module-testing/testing-public.js}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export const createPorticoModule = ({ prepareTests, checkConventions, checkTestReceipt, recordTestReceipt, runTests }) => ({
|
|
2
3
|
prepareTests: prepareTests.run,
|
|
3
4
|
checkConventions: checkConventions.run,
|
|
4
5
|
checkTestReceipt: checkTestReceipt.run,
|
|
@@ -9,9 +9,9 @@ import { globSync, hasMagic } from 'glob';
|
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
10
|
import semver from 'semver';
|
|
11
11
|
import YAML from 'yaml';
|
|
12
|
-
import assessReleaseSchema from '
|
|
13
|
-
import packageManifest from '
|
|
14
|
-
import projectConfigDefaults from '
|
|
12
|
+
import assessReleaseSchema from './+module-releases/assess-release-schema.json' with { type: 'json' };
|
|
13
|
+
import packageManifest from '../../../package.json' with { type: 'json' };
|
|
14
|
+
import projectConfigDefaults from './+module-configuration/project-config-defaults.json' with { type: 'json' };
|
|
15
15
|
const moduleDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
16
16
|
export default () => ({
|
|
17
17
|
buffer: Buffer,
|
|
@@ -25,8 +25,8 @@ export default () => ({
|
|
|
25
25
|
},
|
|
26
26
|
timezone: () => Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
27
27
|
}),
|
|
28
|
-
cliConfigPath: path.resolve(moduleDirectory, '
|
|
29
|
-
executablePath: path.resolve(moduleDirectory, '
|
|
28
|
+
cliConfigPath: path.resolve(moduleDirectory, '../../../cmdabra.yaml'),
|
|
29
|
+
executablePath: path.resolve(moduleDirectory, '../../../bin/peacekeeper.js'),
|
|
30
30
|
assessReleaseSchema,
|
|
31
31
|
crypto,
|
|
32
32
|
execFileSync,
|
|
@@ -34,7 +34,7 @@ export default () => ({
|
|
|
34
34
|
globSync,
|
|
35
35
|
hasMagic,
|
|
36
36
|
isDeepStrictEqual,
|
|
37
|
-
modulesRoot: moduleDirectory,
|
|
37
|
+
modulesRoot: path.dirname(moduleDirectory),
|
|
38
38
|
os,
|
|
39
39
|
output: console,
|
|
40
40
|
packageVersion: packageManifest.version,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakobm/peacekeeper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.2",
|
|
4
4
|
"description": "Shared repository test, Git worktree, and Codex hook commands",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakob Mattsson",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dist/package.json"
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
|
-
"generate:cli-types": "cmdabra generate-types cmdabra.yaml --output src/modules/cli/types.ts",
|
|
27
|
-
"check:cli-types": "cmdabra generate-types cmdabra.yaml --output src/modules/cli/types.ts --check",
|
|
26
|
+
"generate:cli-types": "cmdabra generate-types cmdabra.yaml --output src/modules/implementations/+module-cli/types.ts",
|
|
27
|
+
"check:cli-types": "cmdabra generate-types cmdabra.yaml --output src/modules/implementations/+module-cli/types.ts --check",
|
|
28
28
|
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
29
29
|
"build": "npm run clean && npm run check:cli-types && tsc && tsc -p tsconfig.test.json && node dist/scripts/copy-assets.js",
|
|
30
30
|
"typecheck": "npm run check:cli-types && tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"node": "^22.14.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@jakobm/cmdabra": "^0.
|
|
44
|
-
"@jakobm/portico": "^0.
|
|
43
|
+
"@jakobm/cmdabra": "^0.9.0",
|
|
44
|
+
"@jakobm/portico": "^0.12.0",
|
|
45
45
|
"glob": "^14.0.4",
|
|
46
46
|
"semver": "^7.8.5",
|
|
47
47
|
"yaml": "^2.9.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const porticoFacade = ({ service }) => ({ run: service.run });
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export default ({ configuration, releaseCore, releaseProtection, external: { output, runtime, spawnSync, } }) => {
|
|
2
|
-
const { projectConfig } = configuration;
|
|
3
|
-
const { originRepository } = releaseCore;
|
|
4
|
-
const { githubApi, requiredPolicy, verifyProtection } = releaseProtection;
|
|
5
|
-
function main(cwd = runtime.cwd()) {
|
|
6
|
-
const config = projectConfig(cwd);
|
|
7
|
-
const remote = spawnSync('git', ['remote', 'get-url', config.git.remote], { encoding: 'utf8' });
|
|
8
|
-
if (remote.status !== 0)
|
|
9
|
-
throw new Error(remote.stderr);
|
|
10
|
-
const { host, slug } = originRepository(remote.stdout.trim());
|
|
11
|
-
const api = githubApi((command, args, options) => spawnSync(command, args, { ...options, encoding: 'utf8' }), cwd, host);
|
|
12
|
-
verifyProtection({ api, slug, branch: api(`repos/${slug}`).default_branch,
|
|
13
|
-
...requiredPolicy(cwd), warn: message => output.warn(message) });
|
|
14
|
-
}
|
|
15
|
-
function run() {
|
|
16
|
-
try {
|
|
17
|
-
main();
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
output.error(error instanceof Error ? error.message : String(error));
|
|
21
|
-
runtime.exitCode = 1;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return { run };
|
|
25
|
-
};
|
|
File without changes
|
|
File without changes
|
/package/dist/src/modules/{configuration → implementations/+module-configuration}/update-config.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/checkpoint-codex-stop.js
RENAMED
|
File without changes
|
/package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/checkpoint-instructions.js
RENAMED
|
File without changes
|
/package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/cleanup-ended-session.js
RENAMED
|
File without changes
|
/package/dist/src/modules/{lifecycle → implementations/+module-lifecycle}/log-script-invocation.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/modules/{projects → implementations/+module-projects}/generate-github-setup.js
RENAMED
|
File without changes
|
/package/dist/src/modules/{projects → implementations/+module-projects}/github-setup-prefix.sh
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/modules/{releases → implementations/+module-releases}/assess-release-schema.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/modules/{releases → implementations/+module-releases}/github-configuration.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/modules/{releases → implementations/+module-releases}/release-protection.js
RENAMED
|
File without changes
|
/package/dist/src/modules/{releases → implementations/+module-releases}/verify-release-version.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/modules/{testing → implementations/+module-testing}/record-test-receipt.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|