@jakobm/peacekeeper 0.26.0 → 0.28.0
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 +307 -129
- package/dist/cmdabra.yaml +174 -116
- package/dist/package.json +5 -6
- package/dist/src/modules/cli/legacy-commands.js +37 -0
- package/dist/src/modules/cli/service.js +48 -40
- package/dist/src/modules/configuration/facade.js +1 -0
- package/dist/src/modules/configuration/project-config-defaults.json +2 -1
- package/dist/src/modules/configuration/project-config.js +20 -8
- package/dist/src/modules/configuration/update-config.js +16 -2
- package/dist/src/modules/dependencies.yaml +2 -2
- package/dist/src/modules/external.js +0 -2
- package/dist/src/modules/lifecycle/checkpoint-instructions.js +1 -1
- package/dist/src/modules/lifecycle/cleanup-ended-session.js +1 -1
- package/dist/src/modules/maintenance/cleanup-merged-branches.js +4 -4
- package/dist/src/modules/maintenance/initialize-codex-worktree.js +1 -1
- package/dist/src/modules/maintenance/remove-empty-directories.js +1 -1
- package/dist/src/modules/projects/check-project-requirements.txt +38 -57
- package/dist/src/modules/projects/check-project.js +19 -45
- package/dist/src/modules/projects/create-project-core.js +13 -32
- package/dist/src/modules/projects/generate-github-setup.js +16 -55
- package/dist/src/modules/projects/github-setup-prefix.sh +29 -2
- package/dist/src/modules/projects/github-setup-repository-template.sh +1 -40
- package/dist/src/modules/projects/github-setup-suffix-template.sh +7 -5
- package/dist/src/modules/projects/install-hooks.js +6 -5
- package/dist/src/modules/releases/configure-github.js +57 -0
- package/dist/src/modules/releases/facade.js +3 -2
- package/dist/src/modules/releases/github-configuration.js +166 -0
- package/dist/src/modules/releases/github-policy.js +45 -11
- package/dist/src/modules/releases/github-remote.js +230 -0
- package/dist/src/modules/testing/check-test-receipt.js +17 -22
- package/dist/src/modules/testing/receipt-state.js +27 -1
- package/dist/src/modules/testing/record-test-receipt.js +14 -13
- package/dist/src/modules/testing/run-tests.js +23 -14
- package/dist/src/modules/testing/types.js +1 -0
- package/package.json +5 -6
- package/dist/src/modules/projects/codex-setup-prefix.sh +0 -25
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ configuration, receiptState, external: { clock, output, runtime } }) => {
|
|
3
|
+
const { ROOT, environmentFingerprint, readReceipts, snapshot } = receiptState;
|
|
3
4
|
const { projectConfig, requireTestCommands } = configuration;
|
|
4
|
-
function successMessage(root = ROOT()) {
|
|
5
|
+
function successMessage(root = ROOT(), checkpoint = false) {
|
|
5
6
|
const command = projectConfig(root).tests.npmTestUsesRunner
|
|
6
|
-
?
|
|
7
|
-
:
|
|
7
|
+
? `npm test -- --force${checkpoint ? ' --checkpoint' : ''}`
|
|
8
|
+
: `node node_modules/@jakobm/peacekeeper/dist/bin/peacekeeper.js test run --force${checkpoint ? ' --checkpoint' : ''}`;
|
|
8
9
|
return `Tests already passed for this change set. In order to rerun tests anyway, use: ${command}`;
|
|
9
10
|
}
|
|
10
11
|
function matchesReceipt(receipt, root = ROOT()) {
|
|
11
12
|
const { receiptMaxAgeMinutes } = projectConfig(root).tests;
|
|
12
|
-
if (!receipt || receipt.
|
|
13
|
-
|
|
14
|
-
receipt.
|
|
13
|
+
if (!receipt || typeof receipt.command !== 'string' || typeof receipt.baseCommit !== 'string'
|
|
14
|
+
|| !Array.isArray(receipt.changedFiles) || !Number.isFinite(receipt.passedAt)
|
|
15
|
+
|| clock.now() < receipt.passedAt || clock.now() - receipt.passedAt > receiptMaxAgeMinutes * 60_000
|
|
16
|
+
|| receipt.environment !== environmentFingerprint())
|
|
15
17
|
return false;
|
|
16
18
|
const current = snapshot(root, receipt.baseCommit);
|
|
17
19
|
return JSON.stringify(current.changedFiles) === JSON.stringify(receipt.changedFiles);
|
|
18
20
|
}
|
|
19
|
-
function checkReceipt(root = ROOT()) {
|
|
21
|
+
function checkReceipt(root = ROOT(), commands = projectConfig(root).tests.all) {
|
|
20
22
|
requireTestCommands(root);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
receipt = JSON.parse(fs.readFileSync(receiptPath(root), 'utf8'));
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
if (error.code === 'ENOENT' || error instanceof SyntaxError)
|
|
27
|
-
return false;
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
return matchesReceipt(receipt, root);
|
|
23
|
+
const receipts = readReceipts(root);
|
|
24
|
+
return commands.every(command => receipts.some(receipt => receipt?.command === command && matchesReceipt(receipt, root)));
|
|
31
25
|
}
|
|
32
|
-
function run() {
|
|
26
|
+
function run({ checkpoint = false } = {}) {
|
|
33
27
|
try {
|
|
34
|
-
|
|
28
|
+
const config = projectConfig();
|
|
29
|
+
if (!checkReceipt(config.root, config.tests[checkpoint ? 'checkpoint' : 'all']))
|
|
35
30
|
runtime.exitCode = 1;
|
|
36
31
|
else
|
|
37
|
-
output.log(successMessage());
|
|
32
|
+
output.log(successMessage(config.root, checkpoint));
|
|
38
33
|
}
|
|
39
34
|
catch (error) {
|
|
40
35
|
output.error(error instanceof Error ? error.message : String(error));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// --- Implementation ---
|
|
1
2
|
export default ({ configuration, external: { clock, crypto, execFileSync, fs, modulesRoot, os, path, runtime, } }) => {
|
|
2
3
|
const { repositoryRoot } = configuration;
|
|
3
4
|
const ROOT = repositoryRoot;
|
|
@@ -94,6 +95,31 @@ export default ({ configuration, external: { clock, crypto, execFileSync, fs, mo
|
|
|
94
95
|
const id = crypto.createHash('sha256').update(fs.realpathSync(root)).digest('hex');
|
|
95
96
|
return path.join(os.tmpdir(), RECEIPT_DIRECTORY, `${id}.git.json`);
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
+
function readReceipts(root = ROOT()) {
|
|
99
|
+
try {
|
|
100
|
+
const stored = JSON.parse(fs.readFileSync(receiptPath(root), 'utf8'));
|
|
101
|
+
return stored?.version === 2 && Array.isArray(stored.receipts) ? stored.receipts : [];
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error.code === 'ENOENT' || error instanceof SyntaxError)
|
|
105
|
+
return [];
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function writeReceipts(root, receipts) {
|
|
110
|
+
const destination = receiptPath(root);
|
|
111
|
+
if (!receipts.length) {
|
|
112
|
+
fs.rmSync(destination, { force: true });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
116
|
+
const temporary = `${destination}.${runtime.pid}.tmp`;
|
|
117
|
+
fs.writeFileSync(temporary, `${JSON.stringify({ version: 2, receipts })}\n`);
|
|
118
|
+
fs.renameSync(temporary, destination);
|
|
119
|
+
}
|
|
120
|
+
function invalidateReceipts(root = ROOT(), commands) {
|
|
121
|
+
writeReceipts(root, commands ? readReceipts(root).filter(receipt => !commands.includes(receipt?.command)) : []);
|
|
122
|
+
}
|
|
123
|
+
const api = { ROOT, environmentFingerprint, receiptPath, snapshot, readReceipts, writeReceipts, invalidateReceipts };
|
|
98
124
|
return api;
|
|
99
125
|
};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ configuration, receiptState, external: { clock, output, runtime } }) => {
|
|
3
|
+
const { projectConfig, requireTestCommands } = configuration;
|
|
4
|
+
const { ROOT, readReceipts, writeReceipts, snapshot } = receiptState;
|
|
5
|
+
function recordReceipt(root = ROOT(), testedSnapshot, commands = projectConfig(root).tests.all) {
|
|
5
6
|
requireTestCommands(root);
|
|
6
7
|
const current = snapshot(root, testedSnapshot?.baseCommit);
|
|
7
8
|
if (testedSnapshot && JSON.stringify(current) !== JSON.stringify(testedSnapshot)) {
|
|
8
9
|
throw new Error('Files or environment changed while tests ran; rerun tests before recording a receipt.');
|
|
9
10
|
}
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return receipt;
|
|
11
|
+
const receipts = [...new Set(commands)].map(command => ({ command, passedAt: clock.now(), ...current }));
|
|
12
|
+
writeReceipts(root, [
|
|
13
|
+
...readReceipts(root).filter(receipt => !commands.includes(receipt?.command)),
|
|
14
|
+
...receipts,
|
|
15
|
+
]);
|
|
16
|
+
return receipts[0];
|
|
17
17
|
}
|
|
18
|
-
function run() {
|
|
18
|
+
function run({ checkpoint = false } = {}) {
|
|
19
19
|
try {
|
|
20
|
-
|
|
20
|
+
const config = projectConfig();
|
|
21
|
+
recordReceipt(config.root, undefined, config.tests[checkpoint ? 'checkpoint' : 'all']);
|
|
21
22
|
}
|
|
22
23
|
catch (error) {
|
|
23
24
|
output.error(error instanceof Error ? error.message : String(error));
|
|
@@ -1,48 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ checkTestReceipt, configuration, projects, receiptState, recordTestReceipt, external: { output, runtime, spawnSync } }) => {
|
|
2
3
|
const { checkReceipt, successMessage } = checkTestReceipt;
|
|
3
4
|
const { recordReceipt } = recordTestReceipt;
|
|
4
5
|
const { projectConfig, requireTestCommands } = configuration;
|
|
5
|
-
const {
|
|
6
|
+
const { invalidateReceipts, snapshot } = receiptState;
|
|
6
7
|
function run(command, root) {
|
|
7
8
|
const result = spawnSync(command, { cwd: root, stdio: 'inherit', shell: true });
|
|
8
9
|
if (result.error)
|
|
9
10
|
throw result.error;
|
|
10
11
|
return result.status ?? 1;
|
|
11
12
|
}
|
|
12
|
-
function hasReusableReceipt() {
|
|
13
|
+
function hasReusableReceipt(root, command) {
|
|
13
14
|
try {
|
|
14
|
-
return checkReceipt();
|
|
15
|
+
return checkReceipt(root, [command]);
|
|
15
16
|
}
|
|
16
17
|
catch (error) {
|
|
17
18
|
output.error(error instanceof Error ? error.message : String(error));
|
|
18
19
|
return false;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
function main({ force = false } = {}) {
|
|
22
|
+
function main({ force = false, checkpoint = false } = {}) {
|
|
22
23
|
requireTestCommands();
|
|
23
24
|
const config = projectConfig();
|
|
25
|
+
const commands = [...new Set(config.tests[checkpoint ? 'checkpoint' : 'all'])];
|
|
24
26
|
runtime.exitCode = undefined;
|
|
25
27
|
projects.checkProject();
|
|
26
28
|
const projectStatus = runtime.exitCode ?? 0;
|
|
27
29
|
if (projectStatus !== 0) {
|
|
28
|
-
|
|
30
|
+
invalidateReceipts(config.root);
|
|
29
31
|
runtime.exitCode = projectStatus;
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const bypassReceipts = force || Boolean(runtime.env.CI);
|
|
35
|
+
if (bypassReceipts)
|
|
36
|
+
invalidateReceipts(config.root, commands);
|
|
37
|
+
let ran = false;
|
|
38
|
+
for (const command of commands) {
|
|
39
|
+
if (!bypassReceipts && hasReusableReceipt(config.root, command)) {
|
|
40
|
+
output.log(`Skipping previously passed command: ${command}`);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
invalidateReceipts(config.root, [command]);
|
|
44
|
+
const testedSnapshot = snapshot(config.root);
|
|
39
45
|
const status = run(command, config.root);
|
|
40
46
|
if (status !== 0) {
|
|
41
47
|
runtime.exitCode = status;
|
|
42
48
|
return;
|
|
43
49
|
}
|
|
50
|
+
recordReceipt(config.root, testedSnapshot, [command]);
|
|
51
|
+
ran = true;
|
|
44
52
|
}
|
|
45
|
-
|
|
53
|
+
if (commands.length && !ran)
|
|
54
|
+
output.log(successMessage(config.root, checkpoint));
|
|
46
55
|
}
|
|
47
56
|
function runCommand(options = {}) {
|
|
48
57
|
try {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakobm/peacekeeper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Shared repository test, Git worktree, and Codex hook commands",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakob Mattsson",
|
|
@@ -28,19 +28,18 @@
|
|
|
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",
|
|
31
|
-
"test": "npm run build && node dist/bin/peacekeeper.js run
|
|
31
|
+
"test": "npm run build && node dist/bin/peacekeeper.js test run",
|
|
32
32
|
"prepare": "npm run build",
|
|
33
33
|
"architecture": "npm run build && portico architecture --modules dist/src/modules --output architecture",
|
|
34
34
|
"prerelease": "npm ci",
|
|
35
|
-
"release": "node dist/bin/peacekeeper.js release",
|
|
36
|
-
"cleanup:branches": "node dist/bin/peacekeeper.js cleanup
|
|
37
|
-
"cleanup:empty-directories": "node dist/bin/peacekeeper.js
|
|
35
|
+
"release": "node dist/bin/peacekeeper.js release publish",
|
|
36
|
+
"cleanup:branches": "node dist/bin/peacekeeper.js cleanup merged-branches",
|
|
37
|
+
"cleanup:empty-directories": "node dist/bin/peacekeeper.js cleanup empty-directories"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": "^22.14.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@iarna/toml": "^2.2.5",
|
|
44
43
|
"@jakobm/cmdabra": "^0.7.0",
|
|
45
44
|
"@jakobm/portico": "^0.8.1",
|
|
46
45
|
"glob": "^14.0.4",
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Stop setup if a command or any part of a pipeline fails.
|
|
2
|
-
set -eo pipefail
|
|
3
|
-
|
|
4
|
-
# Put Volta's shims first in PATH so package.json selects Node and npm versions.
|
|
5
|
-
export VOLTA_HOME="${VOLTA_HOME:-$HOME/.volta}"
|
|
6
|
-
export PATH="$VOLTA_HOME/bin:$PATH"
|
|
7
|
-
|
|
8
|
-
# Install Volta if missing, without modifying shell profiles.
|
|
9
|
-
if ! command -v volta >/dev/null 2>&1; then
|
|
10
|
-
curl --proto '=https' --tlsv1.2 -fsS https://get.volta.sh | bash -s -- --skip-setup
|
|
11
|
-
fi
|
|
12
|
-
|
|
13
|
-
# Log tool versions to help diagnose setup failures.
|
|
14
|
-
volta --version
|
|
15
|
-
node --version
|
|
16
|
-
npm --version
|
|
17
|
-
|
|
18
|
-
# Install the exact dependency versions recorded in the lockfile.
|
|
19
|
-
npm ci
|
|
20
|
-
|
|
21
|
-
# Initialize the linked worktree and safely synchronize the primary checkout.
|
|
22
|
-
npm exec --no -- peacekeeper initialize-codex-worktree --sync-primary
|
|
23
|
-
npm exec --no -- peacekeeper cleanup-merged-branches --execute
|
|
24
|
-
|
|
25
|
-
# Add custom project setup below
|