@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.
Files changed (36) hide show
  1. package/README.md +307 -129
  2. package/dist/cmdabra.yaml +174 -116
  3. package/dist/package.json +5 -6
  4. package/dist/src/modules/cli/legacy-commands.js +37 -0
  5. package/dist/src/modules/cli/service.js +48 -40
  6. package/dist/src/modules/configuration/facade.js +1 -0
  7. package/dist/src/modules/configuration/project-config-defaults.json +2 -1
  8. package/dist/src/modules/configuration/project-config.js +20 -8
  9. package/dist/src/modules/configuration/update-config.js +16 -2
  10. package/dist/src/modules/dependencies.yaml +2 -2
  11. package/dist/src/modules/external.js +0 -2
  12. package/dist/src/modules/lifecycle/checkpoint-instructions.js +1 -1
  13. package/dist/src/modules/lifecycle/cleanup-ended-session.js +1 -1
  14. package/dist/src/modules/maintenance/cleanup-merged-branches.js +4 -4
  15. package/dist/src/modules/maintenance/initialize-codex-worktree.js +1 -1
  16. package/dist/src/modules/maintenance/remove-empty-directories.js +1 -1
  17. package/dist/src/modules/projects/check-project-requirements.txt +38 -57
  18. package/dist/src/modules/projects/check-project.js +19 -45
  19. package/dist/src/modules/projects/create-project-core.js +13 -32
  20. package/dist/src/modules/projects/generate-github-setup.js +16 -55
  21. package/dist/src/modules/projects/github-setup-prefix.sh +29 -2
  22. package/dist/src/modules/projects/github-setup-repository-template.sh +1 -40
  23. package/dist/src/modules/projects/github-setup-suffix-template.sh +7 -5
  24. package/dist/src/modules/projects/install-hooks.js +6 -5
  25. package/dist/src/modules/releases/configure-github.js +57 -0
  26. package/dist/src/modules/releases/facade.js +3 -2
  27. package/dist/src/modules/releases/github-configuration.js +166 -0
  28. package/dist/src/modules/releases/github-policy.js +45 -11
  29. package/dist/src/modules/releases/github-remote.js +230 -0
  30. package/dist/src/modules/testing/check-test-receipt.js +17 -22
  31. package/dist/src/modules/testing/receipt-state.js +27 -1
  32. package/dist/src/modules/testing/record-test-receipt.js +14 -13
  33. package/dist/src/modules/testing/run-tests.js +23 -14
  34. package/dist/src/modules/testing/types.js +1 -0
  35. package/package.json +5 -6
  36. package/dist/src/modules/projects/codex-setup-prefix.sh +0 -25
@@ -1,40 +1,35 @@
1
- export default ({ configuration, receiptState, external: { clock, fs, output, runtime } }) => {
2
- const { ROOT, environmentFingerprint, receiptPath, snapshot } = receiptState;
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
- ? 'npm test -- --force'
7
- : 'node node_modules/@jakobm/peacekeeper/dist/bin/peacekeeper.js run-tests --force';
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.version !== 1 || !Number.isFinite(receipt.passedAt) ||
13
- clock.now() < receipt.passedAt || clock.now() - receipt.passedAt > receiptMaxAgeMinutes * 60_000 ||
14
- receipt.environment !== environmentFingerprint())
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
- let receipt;
22
- try {
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
- if (!checkReceipt())
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
- const api = { ROOT, environmentFingerprint, receiptPath, snapshot };
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
- export default ({ configuration, receiptState, external: { clock, fs, output, path, runtime } }) => {
2
- const { requireTestCommands } = configuration;
3
- const { ROOT, receiptPath, snapshot } = receiptState;
4
- function recordReceipt(root = ROOT(), testedSnapshot) {
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 receipt = { version: 1, passedAt: clock.now(), ...current };
11
- const destination = receiptPath(root);
12
- fs.mkdirSync(path.dirname(destination), { recursive: true });
13
- const temporary = `${destination}.${runtime.pid}.tmp`;
14
- fs.writeFileSync(temporary, `${JSON.stringify(receipt)}\n`);
15
- fs.renameSync(temporary, destination);
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
- recordReceipt();
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
- export default ({ checkTestReceipt, configuration, projects, receiptState, recordTestReceipt, external: { fs, output, runtime, spawnSync } }) => {
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 { receiptPath, snapshot } = receiptState;
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
- fs.rmSync(receiptPath(config.root), { force: true });
30
+ invalidateReceipts(config.root);
29
31
  runtime.exitCode = projectStatus;
30
32
  return;
31
33
  }
32
- if (!force && !runtime.env.CI && hasReusableReceipt()) {
33
- output.log(successMessage(config.root));
34
- return;
35
- }
36
- fs.rmSync(receiptPath(config.root), { force: true });
37
- const testedSnapshot = snapshot(config.root);
38
- for (const command of config.tests.commands) {
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
- recordReceipt(config.root, testedSnapshot);
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.26.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-tests",
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-merged-branches",
37
- "cleanup:empty-directories": "node dist/bin/peacekeeper.js remove-empty-directories"
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