@jakobm/peacekeeper 0.29.0 → 0.30.1
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 +106 -41
- package/dist/cmdabra.yaml +5 -5
- package/dist/package.json +3 -3
- package/dist/src/modules/cli/legacy-commands.js +0 -5
- package/dist/src/modules/cli/service.js +2 -2
- package/dist/src/modules/configuration/project-config-defaults.json +2 -1
- package/dist/src/modules/configuration/project-config.js +7 -1
- package/dist/src/modules/projects/check-project-requirements.txt +36 -13
- package/dist/src/modules/projects/check-project.js +2 -2
- package/dist/src/modules/releases/assess-release-core.js +5 -4
- package/dist/src/modules/releases/check-github.js +27 -0
- package/dist/src/modules/releases/facade.js +2 -2
- package/dist/src/modules/releases/release-core.js +63 -14
- package/dist/src/modules/releases/release.js +2 -1
- package/dist/src/modules/releases/reusable-workflows.json +1 -1
- package/dist/src/modules/releases/verify-release-core.js +4 -4
- package/dist/src/modules/releases/version-history.js +26 -0
- package/package.json +3 -3
- package/dist/src/modules/releases/verify-release-protection.js +0 -25
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@ completion follows the same hierarchy.
|
|
|
16
16
|
| --- | --- |
|
|
17
17
|
| `project` | `create`, `check`, `update-config`, `check-conventions` |
|
|
18
18
|
| `test` | `run`, `check-receipt`, `record-receipt`, `prepare` |
|
|
19
|
-
| `github` | `configure`, `generate-setup` |
|
|
20
|
-
| `release` | `assess`, `verify`, `verify-
|
|
19
|
+
| `github` | `check`, `configure`, `generate-setup` |
|
|
20
|
+
| `release` | `assess`, `verify`, `verify-version`, `publish` |
|
|
21
21
|
| `codex` | `install-hooks`, `init-worktree`, `checkpoint`, `session-start`, `stop`, `session-end` |
|
|
22
22
|
| `cleanup` | `merged-branches`, `empty-directories`, `queue-merged-worktree` |
|
|
23
23
|
|
|
@@ -31,8 +31,9 @@ peacekeeper cleanup merged-branches --execute
|
|
|
31
31
|
|
|
32
32
|
The previous flat command names remain accepted for existing scripts and hooks.
|
|
33
33
|
For example, `run-tests --checkpoint` maps to `test run --checkpoint`,
|
|
34
|
-
`checkpoint-codex-changes` maps to `codex checkpoint
|
|
35
|
-
|
|
34
|
+
and `checkpoint-codex-changes` maps to `codex checkpoint`. The old `release patch`
|
|
35
|
+
syntax has been removed; use `npm run release -- --bump patch`. Bare
|
|
36
|
+
`release` displays the release group's help.
|
|
36
37
|
Help and generated project files use the grouped names. Update existing package
|
|
37
38
|
scripts and CI to those names. The legacy hook installer remains available, but its repository-local files
|
|
38
39
|
conflict with the current project requirements.
|
|
@@ -66,6 +67,10 @@ The CLI also exposes Cmdabra's global `--cmdabra-complete` option for
|
|
|
66
67
|
It accepts the current word index followed by all command-line words and prints
|
|
67
68
|
completion candidates without running a command.
|
|
68
69
|
|
|
70
|
+
Use `peacekeeper --cmdabra-completion bash` to print a completion script or
|
|
71
|
+
`peacekeeper --cmdabra-install-completion bash` to install it. Both options
|
|
72
|
+
support `bash`, `zsh`, and `fish`.
|
|
73
|
+
|
|
69
74
|
## Testing Peacekeeper
|
|
70
75
|
|
|
71
76
|
Run `npm test` with the pinned Volta toolchain to build and run type checks,
|
|
@@ -94,7 +99,8 @@ through OIDC. Put project-specific checks, including packaging checks, in
|
|
|
94
99
|
`tests.all`. Neither workflow accepts inputs.
|
|
95
100
|
|
|
96
101
|
Install a Peacekeeper version containing this support before switching. Older
|
|
97
|
-
versions reject required reusable jobs
|
|
102
|
+
versions may reject required reusable jobs or lack the `github check` command
|
|
103
|
+
used by the revised workflow. A minimal `.github/workflows/test.yml` is:
|
|
98
104
|
|
|
99
105
|
```yaml
|
|
100
106
|
on:
|
|
@@ -104,7 +110,7 @@ permissions:
|
|
|
104
110
|
contents: read
|
|
105
111
|
jobs:
|
|
106
112
|
test:
|
|
107
|
-
uses: jakobmattsson/peacekeeper/.github/workflows/reusable-pr.yml@
|
|
113
|
+
uses: jakobmattsson/peacekeeper/.github/workflows/reusable-pr.yml@071a6102729107f4f4f01851e0b661355985a676
|
|
108
114
|
secrets:
|
|
109
115
|
RELEASE_POLICY_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
|
|
110
116
|
```
|
|
@@ -167,6 +173,50 @@ single static `test` or `publish` job, explicit policy secret, no-input contract
|
|
|
167
173
|
and verified setup and step order. Contract tests check both implementations
|
|
168
174
|
through the public project checker. Consumers deliberately update approved pins.
|
|
169
175
|
|
|
176
|
+
## Strict version history
|
|
177
|
+
|
|
178
|
+
Set the optional top-level `strictVersionHistory` boolean in
|
|
179
|
+
`peacekeeper.config.yaml` to require an increasing package version for each
|
|
180
|
+
future merge to the default branch:
|
|
181
|
+
|
|
182
|
+
```yaml
|
|
183
|
+
strictVersionHistory: true
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Peacekeeper itself enables this setting; every PR must increase the package version.
|
|
187
|
+
|
|
188
|
+
The default is `false`, including for existing files that omit the field.
|
|
189
|
+
`project update-config` inserts an explicit `false` without changing an existing
|
|
190
|
+
value. With `false`, GitHub protection remains mandatory and versions may stay
|
|
191
|
+
unchanged between merges.
|
|
192
|
+
|
|
193
|
+
`peacekeeper github check` verifies the repository's GitHub protection and, when
|
|
194
|
+
strict history is enabled, compares the incoming checkout's `package.json`
|
|
195
|
+
version with the version on GitHub's actual default branch. It reads the branch
|
|
196
|
+
commit and then fetches its package metadata by that immutable SHA. Local
|
|
197
|
+
remote-tracking refs, full Git history and an explicit base argument are not
|
|
198
|
+
needed. Missing or invalid versions and unavailable API data fail verification.
|
|
199
|
+
The version must be strictly greater according to semver precedence; changing
|
|
200
|
+
build metadata alone does not count as an increase.
|
|
201
|
+
|
|
202
|
+
Required strict status checks force a parallel PR to update and pass CI again
|
|
203
|
+
after another PR merges. A version already taken by that merge must be raised
|
|
204
|
+
again. The rule applies to the default branch's first-parent merge history;
|
|
205
|
+
feature-branch commits may share versions. It does not audit older history or
|
|
206
|
+
require every version to be published, and it does not select the appropriate
|
|
207
|
+
major/minor/patch increment for you.
|
|
208
|
+
|
|
209
|
+
The GitHub check is separate from offline `project check`, local tests and
|
|
210
|
+
checkpoints, so development can proceed before choosing a version. Use
|
|
211
|
+
`github check` in PR workflows. Older verification command names and workflow
|
|
212
|
+
revisions that invoke them are unsupported by this version of Peacekeeper.
|
|
213
|
+
|
|
214
|
+
Publication's `release verify` continues to verify GitHub protection, tag/package/
|
|
215
|
+
lockfile agreement and the merged PR's CI independently. It does not apply the
|
|
216
|
+
incoming-version comparison to an already merged release. With strict history,
|
|
217
|
+
`npm run release` publishes the existing default-branch version without creating
|
|
218
|
+
a version-bump PR.
|
|
219
|
+
|
|
170
220
|
## Standard CI test environment
|
|
171
221
|
|
|
172
222
|
The central PR workflow runs one Ubuntu 24.04 job. It cancels superseded runs for
|
|
@@ -345,7 +395,7 @@ is a separate step; a secret-sync failure does not roll back GitHub settings.
|
|
|
345
395
|
Use a manually authenticated GitHub identity with repository Administration write
|
|
346
396
|
access for execute, and sufficient Contents/Administration read access for complete
|
|
347
397
|
policy inspection. Do not put admin-write credentials in Actions secrets.
|
|
348
|
-
The shared policy model also serves `
|
|
398
|
+
The shared policy model also serves `github check`; that existing
|
|
349
399
|
command retains its documented semantic alternatives, including equivalent classic
|
|
350
400
|
protection, while github configure verifies the exact owned configuration.
|
|
351
401
|
|
|
@@ -442,13 +492,14 @@ All CLI commands validate configuration before executing, except help,
|
|
|
442
492
|
`project check --explain`, and `project update-config`. Checkpoint hooks instead validate
|
|
443
493
|
the event worktree configuration when the event requires instructions or a check.
|
|
444
494
|
An incomplete existing file fails
|
|
445
|
-
with missing field paths and a repair hint. Updates introducing new fields
|
|
495
|
+
with missing field paths and a repair hint. Updates introducing new required fields
|
|
446
496
|
therefore require `peacekeeper project update-config` before ordinary commands can run.
|
|
447
497
|
|
|
448
498
|
Complete example:
|
|
449
499
|
|
|
450
500
|
```yaml
|
|
451
501
|
publishesToNpm: false
|
|
502
|
+
strictVersionHistory: false
|
|
452
503
|
git:
|
|
453
504
|
remote: origin
|
|
454
505
|
defaultBranch: main
|
|
@@ -880,7 +931,7 @@ proven free of publication code by this local check. Remove dedicated npm
|
|
|
880
931
|
publishing credentials and trusted-publisher registrations separately.
|
|
881
932
|
Internal `npm pack`, build scripts, module entry points and CLI metadata remain
|
|
882
933
|
allowed, as do deployment workflows and read authentication for dependencies.
|
|
883
|
-
PR checks, lockfiles, toolchain requirements and `
|
|
934
|
+
PR checks, lockfiles, toolchain requirements and `github check`
|
|
884
935
|
remain independent of publication intent, including `git.releaseRequiredChecks`.
|
|
885
936
|
|
|
886
937
|
All projects must declare nonblank `author` and `repository` values in
|
|
@@ -946,8 +997,10 @@ model selection remains at Codex's default.
|
|
|
946
997
|
default-branch commit being assessed. Peacekeeper supplies these full commit IDs,
|
|
947
998
|
independently of the AI response. They remain available when Codex cannot complete
|
|
948
999
|
its analysis. Each is `null` if it could not be resolved and verified. The target
|
|
949
|
-
identifies the source code
|
|
950
|
-
|
|
1000
|
+
identifies the source code at assessment time. The target package version may
|
|
1001
|
+
already be higher than the published version; assessment still considers all changes
|
|
1002
|
+
since the published release. A release without a bump tags the selected default-branch
|
|
1003
|
+
commit; a release with a bump tags the resulting release PR merge commit.
|
|
951
1004
|
|
|
952
1005
|
The command requires Git, npm, an authenticated GitHub CLI (`gh`) with repository
|
|
953
1006
|
read access, and an installed, authenticated Codex CLI supporting `codex exec`,
|
|
@@ -956,8 +1009,9 @@ which must match `git.defaultBranch`, and pins its exact commit. It uses the
|
|
|
956
1009
|
highest stable version published on the public npm registry as the baseline;
|
|
957
1010
|
prereleases and tags without npm publication do not advance that baseline.
|
|
958
1011
|
The published version must have a matching remote `v<version>` tag in the target's
|
|
959
|
-
ancestry.
|
|
960
|
-
|
|
1012
|
+
ancestry. The package name at both revisions and the version at the published
|
|
1013
|
+
tag must agree with npm; the target version may already be higher. When npm
|
|
1014
|
+
supplies `gitHead`, it must match the tag's commit. Missing tags,
|
|
961
1015
|
inconsistent metadata, no previous stable publication, unsupported private or
|
|
962
1016
|
workspace packages, and unavailable history or services produce `undetermined`.
|
|
963
1017
|
It does not guess an older baseline when the latest stable release cannot be verified.
|
|
@@ -1040,7 +1094,7 @@ the release command enables auto-merge on its release PRs.
|
|
|
1040
1094
|
`project check` makes no network requests. It runs implicitly before
|
|
1041
1095
|
`tests.all` or `tests.checkpoint`, including when reusing receipts, and checks that the configured
|
|
1042
1096
|
PR workflow uses only `pull_request`, with `branches` set to exactly
|
|
1043
|
-
`[git.defaultBranch]`, and runs `
|
|
1097
|
+
`[git.defaultBranch]`, and runs `github check` with `GH_TOKEN` after `npm ci` and
|
|
1044
1098
|
before tests in a job listed in `git.releaseRequiredChecks`, either through local
|
|
1045
1099
|
steps or the approved central PR workflow above. The job and step must
|
|
1046
1100
|
not skip verification or ignore failures. The online verifier then checks that
|
|
@@ -1052,7 +1106,7 @@ For example, in a required `test` job:
|
|
|
1052
1106
|
|
|
1053
1107
|
```yaml
|
|
1054
1108
|
- run: npm ci
|
|
1055
|
-
- run: peacekeeper
|
|
1109
|
+
- run: peacekeeper github check
|
|
1056
1110
|
env:
|
|
1057
1111
|
GH_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
|
|
1058
1112
|
- run: npm test
|
|
@@ -1063,14 +1117,16 @@ This creates a local-to-CI chain: missing workflows are detected on the next loc
|
|
|
1063
1117
|
continuous monitoring. Removing both CI and the local invocation prevents this
|
|
1064
1118
|
chain from running. No central scheduled audit is required by this setup.
|
|
1065
1119
|
|
|
1066
|
-
The PR test job runs `peacekeeper
|
|
1120
|
+
The PR test job runs `peacekeeper github check` before its tests.
|
|
1067
1121
|
The command reads the actual default branch from GitHub, regardless of the PR
|
|
1068
1122
|
base. Other release commands require their configured branch to match it.
|
|
1069
1123
|
`peacekeeper release publish` checks the default branch before preparing a release
|
|
1070
1124
|
and again immediately before each merge attempt. Before publishing,
|
|
1071
1125
|
`peacekeeper release verify` checks the policy, matching package/tag/lockfile
|
|
1072
|
-
versions, a same-repository merged
|
|
1073
|
-
jobs in its latest PR workflow run.
|
|
1126
|
+
versions, a same-repository merged PR, and successful required
|
|
1127
|
+
jobs in its latest PR workflow run. The PR may be a feature PR or a release PR;
|
|
1128
|
+
its branch name and commit message do not determine publication eligibility.
|
|
1129
|
+
Tags without a qualifying merged PR are rejected.
|
|
1074
1130
|
`release verify-version` remains available for local version checks alone.
|
|
1075
1131
|
|
|
1076
1132
|
API failures, missing permissions, and unverifiable rules stop the commands.
|
|
@@ -1135,35 +1191,44 @@ state without a merge method. Saved unfinished releases that explicitly select
|
|
|
1135
1191
|
squash or rebase must be restarted. `git.releaseMergeMethod` remains accepted for
|
|
1136
1192
|
configuration compatibility, but no longer selects the default-branch merge method.
|
|
1137
1193
|
|
|
1138
|
-
From a clean repository root, run `npm run release
|
|
1194
|
+
From a clean repository root, run `npm run release` to publish the existing version
|
|
1195
|
+
at the latest remote default-branch commit. With `strictVersionHistory: true`,
|
|
1196
|
+
versions must already have been assigned in the PRs that introduced the changes;
|
|
1197
|
+
release does not create a bump commit or another PR, and `--bump` is rejected.
|
|
1198
|
+
Not every default-branch version needs to be published.
|
|
1199
|
+
|
|
1200
|
+
With `strictVersionHistory: false` (the default), the same command publishes an
|
|
1201
|
+
already assigned, unpublished version. If that version is already on npm, choose
|
|
1202
|
+
an increment explicitly: `npm run release -- --bump patch`, `--bump minor`, or
|
|
1203
|
+
`--bump major`. Peacekeeper increments the version from the fetched default branch,
|
|
1204
|
+
updates the package and lockfiles in a temporary detached worktree, and opens a
|
|
1205
|
+
`release/v<version>` PR. It enables auto-merge for the expected PR head, then waits
|
|
1206
|
+
up to 20 minutes for GitHub to merge it, respecting checks, reviews, resolved
|
|
1207
|
+
conversations and branch freshness. The resulting merge commit is the release target.
|
|
1208
|
+
|
|
1139
1209
|
The required `prerelease` script runs `npm ci` first, replacing `node_modules`
|
|
1140
1210
|
with the exact dependency versions in the committed lockfile before npm resolves
|
|
1141
1211
|
and starts Peacekeeper. Always use the npm script; invoking `peacekeeper release publish`
|
|
1142
|
-
directly bypasses this dependency bootstrap.
|
|
1143
|
-
The command fetches the default branch and uses a temporary detached worktree to
|
|
1144
|
-
increment the package and lockfile versions. Your current branch and local default
|
|
1212
|
+
directly bypasses this dependency bootstrap. Your current branch and local default
|
|
1145
1213
|
branch stay unchanged, including when the default branch is checked out elsewhere.
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
false publication failure. Git and an authenticated
|
|
1160
|
-
GitHub CLI (`gh`) with Contents read/write, Pull requests read/write, Actions
|
|
1161
|
-
read and the policy-reading access described above are required. Registry checks
|
|
1162
|
-
use a temporary npm cache and request current metadata.
|
|
1214
|
+
The command pins the fetched source commit and logs its full SHA. It never uses
|
|
1215
|
+
an administrator bypass or pushes directly to the default branch.
|
|
1216
|
+
|
|
1217
|
+
Both paths verify the target package and lockfiles, GitHub protection, the merged
|
|
1218
|
+
PR and its successful required CI before creating and pushing `v<version>`.
|
|
1219
|
+
The version must be unpublished on npm; registry access failures stop the command.
|
|
1220
|
+
The tag-triggered workflow independently verifies the release and publishes through
|
|
1221
|
+
npm trusted publishing. The command waits for the publish job and npm visibility.
|
|
1222
|
+
Monitoring reads the run status before its jobs so a job finishing between requests
|
|
1223
|
+
does not produce a false publication failure. Git and an authenticated GitHub CLI
|
|
1224
|
+
(`gh`) with Contents read/write, Pull requests read/write, Actions read and the
|
|
1225
|
+
policy-reading access described above are required. Registry checks use a temporary
|
|
1226
|
+
npm cache and request current metadata.
|
|
1163
1227
|
|
|
1164
1228
|
Retry the same command and release type after an interruption: release state is
|
|
1165
1229
|
stored in `peacekeeper-release.json` in the shared Git directory, so retries
|
|
1166
|
-
from another worktree of the same checkout continue the same
|
|
1230
|
+
from another worktree of the same checkout continue the same target revision and
|
|
1231
|
+
version, even if the default branch has advanced.
|
|
1167
1232
|
Already-merged PRs and already-pushed matching tags are reused. A local lock
|
|
1168
1233
|
prevents concurrent commands in that checkout; an open release PR from a different
|
|
1169
1234
|
checkout blocks a new release. Do not delete the state or manually create a new
|
|
@@ -1182,7 +1247,7 @@ Other npm projects can use this command through package scripts such as
|
|
|
1182
1247
|
former automatically before the latter. The project must use a root package
|
|
1183
1248
|
with a stable version, a `peacekeeper.config.yaml` with
|
|
1184
1249
|
`git.releaseRequiredChecks`, and the supported tag-triggered GitHub Actions
|
|
1185
|
-
publish job. Add `peacekeeper
|
|
1250
|
+
publish job. Add `peacekeeper github check` to a required PR
|
|
1186
1251
|
test job and `peacekeeper release verify` before publishing, with `GH_TOKEN`
|
|
1187
1252
|
and `RELEASE_TAG` set for release verification. Both commands are shipped with
|
|
1188
1253
|
the package; no verifier script or artifact upload needs to be copied.
|
package/dist/cmdabra.yaml
CHANGED
|
@@ -70,8 +70,10 @@ commands:
|
|
|
70
70
|
prepare:
|
|
71
71
|
description: Install tests.aptPackages and tests.playwrightBrowsers when configured.
|
|
72
72
|
github:
|
|
73
|
-
description:
|
|
73
|
+
description: Check and configure GitHub repository policy.
|
|
74
74
|
commands:
|
|
75
|
+
check:
|
|
76
|
+
description: Verify GitHub protection and configured version history requirements.
|
|
75
77
|
configure:
|
|
76
78
|
description: Plan or apply exact GitHub policy from a SHA-pinned remote source.
|
|
77
79
|
named-options:
|
|
@@ -107,15 +109,13 @@ commands:
|
|
|
107
109
|
description: Assess unpublished changes with Codex and return a JSON recommendation.
|
|
108
110
|
verify:
|
|
109
111
|
description: Verify release versions, required CI and strict branch protection.
|
|
110
|
-
verify-protection:
|
|
111
|
-
description: Require strict mandatory release checks without bypass.
|
|
112
112
|
verify-version:
|
|
113
113
|
description: Check a release tag against package and lockfile versions.
|
|
114
114
|
publish:
|
|
115
115
|
description: Publish a version through a GitHub Actions npm workflow.
|
|
116
|
-
|
|
116
|
+
named-options:
|
|
117
117
|
bump:
|
|
118
|
-
description:
|
|
118
|
+
description: Increment the default-branch version through a release PR (without strictVersionHistory).
|
|
119
119
|
type: enum
|
|
120
120
|
choices:
|
|
121
121
|
- major
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakobm/peacekeeper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Shared repository test, Git worktree, and Codex hook commands",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakob Mattsson",
|
|
@@ -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.10.1",
|
|
45
45
|
"glob": "^14.0.4",
|
|
46
46
|
"semver": "^7.8.5",
|
|
47
47
|
"yaml": "^2.9.1"
|
|
@@ -13,9 +13,7 @@ export default () => {
|
|
|
13
13
|
'generate-github-setup': ['github', 'generate-setup'],
|
|
14
14
|
'assess-release': ['release', 'assess'],
|
|
15
15
|
'verify-release': ['release', 'verify'],
|
|
16
|
-
'verify-release-protection': ['release', 'verify-protection'],
|
|
17
16
|
'verify-release-version': ['release', 'verify-version'],
|
|
18
|
-
'release': ['release', 'publish'],
|
|
19
17
|
'install-hooks': ['codex', 'install-hooks'],
|
|
20
18
|
'initialize-codex-worktree': ['codex', 'init-worktree'],
|
|
21
19
|
'checkpoint-codex-changes': ['codex', 'checkpoint'],
|
|
@@ -28,9 +26,6 @@ export default () => {
|
|
|
28
26
|
};
|
|
29
27
|
function normalize(rawArgs) {
|
|
30
28
|
const [command, ...rest] = rawArgs;
|
|
31
|
-
// The new release group shares the old publish command's name.
|
|
32
|
-
if (command === 'release' && !['major', 'minor', 'patch'].includes(rest[0]))
|
|
33
|
-
return rawArgs;
|
|
34
29
|
return Object.hasOwn(commands, command) ? [...commands[command], ...rest] : rawArgs;
|
|
35
30
|
}
|
|
36
31
|
return { commands, normalize };
|
|
@@ -26,15 +26,15 @@ export default ({ configuration, legacyCommands, lifecycle, maintenance, project
|
|
|
26
26
|
recordReceipt: options => testing.recordTestReceipt({ checkpoint: options.checkpoint }),
|
|
27
27
|
},
|
|
28
28
|
github: {
|
|
29
|
+
check: () => releases.checkGithub(),
|
|
29
30
|
configure: options => releases.configureGithub(options),
|
|
30
31
|
generateSetup: options => projects.generateGithubSetup(options),
|
|
31
32
|
},
|
|
32
33
|
release: {
|
|
33
34
|
assess: () => releases.assessRelease(),
|
|
34
35
|
verify: () => releases.verifyRelease(),
|
|
35
|
-
verifyProtection: () => releases.verifyReleaseProtection(),
|
|
36
36
|
verifyVersion: () => releases.verifyReleaseVersion(),
|
|
37
|
-
publish:
|
|
37
|
+
publish: options => releases.release(options),
|
|
38
38
|
},
|
|
39
39
|
codex: {
|
|
40
40
|
installHooks: options => projects.installHooks({ dryRun: options.dryRun }),
|
|
@@ -10,6 +10,7 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
10
10
|
// Kept independent of the defaults so additions require an explicit default.
|
|
11
11
|
const CONFIG_SCHEMA = {
|
|
12
12
|
publishesToNpm: true,
|
|
13
|
+
strictVersionHistory: true,
|
|
13
14
|
git: { remote: true, defaultBranch: true, branchPrefix: true, requiredApprover: true,
|
|
14
15
|
checkpointPushRemotes: true, releaseMergeMethod: true,
|
|
15
16
|
releaseRequiredChecks: true, releaseTestWorkflow: true },
|
|
@@ -30,6 +31,8 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
30
31
|
}
|
|
31
32
|
for (const [key, child] of Object.entries(schema)) {
|
|
32
33
|
const name = location === 'config' ? key : `${location}.${key}`;
|
|
34
|
+
if (location === 'config' && key === 'strictVersionHistory' && !Object.hasOwn(value, key))
|
|
35
|
+
continue;
|
|
33
36
|
if (location === 'tests' && ['aptPackages', 'playwrightBrowsers'].includes(key) && !Object.hasOwn(value, key))
|
|
34
37
|
continue;
|
|
35
38
|
if (!Object.hasOwn(value, key))
|
|
@@ -89,6 +92,9 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
89
92
|
if (typeof config.publishesToNpm !== 'boolean') {
|
|
90
93
|
throw new Error(`${file}: publishesToNpm must be a boolean`);
|
|
91
94
|
}
|
|
95
|
+
if (Object.hasOwn(config, 'strictVersionHistory') && typeof config.strictVersionHistory !== 'boolean') {
|
|
96
|
+
throw new Error(`${file}: strictVersionHistory must be a boolean`);
|
|
97
|
+
}
|
|
92
98
|
if (typeof config.loggingEnabled !== 'boolean') {
|
|
93
99
|
throw new Error(`${file}: loggingEnabled must be a boolean`);
|
|
94
100
|
}
|
|
@@ -135,7 +141,7 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
135
141
|
? YAML.parse(fs.readFileSync(file, 'utf8'))
|
|
136
142
|
: JSON.parse(JSON.stringify(projectConfigDefaults));
|
|
137
143
|
validateConfig(config, file);
|
|
138
|
-
return { root, ...config, tests: { ...projectConfigDefaults.tests, ...config.tests } };
|
|
144
|
+
return { root, strictVersionHistory: projectConfigDefaults.strictVersionHistory, ...config, tests: { ...projectConfigDefaults.tests, ...config.tests } };
|
|
139
145
|
}
|
|
140
146
|
function requireTestCommands(root) {
|
|
141
147
|
if (!projectConfig(root).tests.all.length) {
|
|
@@ -12,11 +12,27 @@ Purpose and scope
|
|
|
12
12
|
of problems behind those prerequisites. Fix them and run the command again.
|
|
13
13
|
--explain prints this entire document without loading or checking a project.
|
|
14
14
|
|
|
15
|
+
Strict version history
|
|
16
|
+
strictVersionHistory is an optional top-level boolean, defaulting to false
|
|
17
|
+
even in existing files. project update-config inserts an explicit false.
|
|
18
|
+
github check always verifies GitHub protection. When strictVersionHistory is
|
|
19
|
+
true, it also requires the incoming package.json version to be strictly
|
|
20
|
+
greater by semver precedence than the actual default branch version on GitHub.
|
|
21
|
+
The default branch package is fetched by immutable commit SHA. API failures,
|
|
22
|
+
missing or invalid versions, equal versions, and lower versions fail the check.
|
|
23
|
+
Strict required checks force parallel PRs to update and rerun after a merge.
|
|
24
|
+
Offline project check, local tests, checkpoints and publication verification
|
|
25
|
+
do not perform this incoming-version comparison. PR workflows must use
|
|
26
|
+
github check; older verification command names are unsupported.
|
|
27
|
+
This applies to future first-parent merges; it does not audit old history
|
|
28
|
+
or require every version to be published. With strict history, release publish
|
|
29
|
+
publishes the existing default-branch version without a version-bump PR.
|
|
30
|
+
|
|
15
31
|
Project configuration
|
|
16
32
|
package.json is required at the Git root. Without peacekeeper.config.yaml,
|
|
17
33
|
bundled defaults apply. An existing configuration must declare every schema
|
|
18
|
-
field, including nested fields, except the optional
|
|
19
|
-
tests.playwrightBrowsers lists; unknown fields and invalid values fail.
|
|
34
|
+
field, including nested fields, except the optional strictVersionHistory boolean
|
|
35
|
+
and tests.aptPackages and tests.playwrightBrowsers lists; unknown fields and invalid values fail.
|
|
20
36
|
Run peacekeeper project update-config to create or complete it without overwriting
|
|
21
37
|
existing values. Migrate tests.commands to tests.all and add tests.checkpoint
|
|
22
38
|
as an empty list. Review inserted defaults. Empty tests.all blocks tests
|
|
@@ -145,12 +161,12 @@ Approved reusable PR workflow
|
|
|
145
161
|
call the central workflow with a full SHA approved by this Peacekeeper version:
|
|
146
162
|
jobs:
|
|
147
163
|
test:
|
|
148
|
-
uses: jakobmattsson/peacekeeper/.github/workflows/reusable-pr.yml@
|
|
164
|
+
uses: jakobmattsson/peacekeeper/.github/workflows/reusable-pr.yml@071a6102729107f4f4f01851e0b661355985a676
|
|
149
165
|
secrets:
|
|
150
166
|
RELEASE_POLICY_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
|
|
151
167
|
Declare permissions.contents as read (or write) at the caller job or workflow.
|
|
152
168
|
Keep the caller's PR trigger and branch restriction described above. The central
|
|
153
|
-
workflow owns checkout, Volta, npm ci,
|
|
169
|
+
workflow owns checkout, Volta, npm ci, github check and npm test.
|
|
154
170
|
The consumer must install a Peacekeeper version supporting this contract as a project dependency.
|
|
155
171
|
|
|
156
172
|
Set both projectChecks.requiredJobs and git.releaseRequiredChecks to include
|
|
@@ -279,11 +295,11 @@ Publication: publishesToNpm=true
|
|
|
279
295
|
Internal packing, prepack/build scripts, main/exports/types/bin, deployment
|
|
280
296
|
workflows, OIDC for other services, and dependency read authentication remain
|
|
281
297
|
allowed. Workflow filenames and job names alone do not imply npm publication.
|
|
282
|
-
Toolchain, hooks, PR checks and
|
|
298
|
+
Toolchain, hooks, PR checks and github check still apply.
|
|
283
299
|
|
|
284
300
|
Online release policy and GitHub token setup
|
|
285
301
|
These are online installation requirements; project check only verifies the
|
|
286
|
-
local declarations above. Use
|
|
302
|
+
local declarations above. Use github check to check the branch
|
|
287
303
|
policy and release verify before publishing to check the release itself.
|
|
288
304
|
|
|
289
305
|
Enable "Automatically delete head branches" (delete_branch_on_merge=true) in
|
|
@@ -329,15 +345,22 @@ Online release policy and GitHub token setup
|
|
|
329
345
|
Fork PRs do not receive repository secrets; do not expose this token by
|
|
330
346
|
running fork code with pull_request_target.
|
|
331
347
|
|
|
332
|
-
|
|
333
|
-
|
|
348
|
+
github check reads the actual default branch from GitHub. It can be run before
|
|
349
|
+
tests in a required trusted PR job. release verify
|
|
334
350
|
checks matching package/tag/lockfile versions, that the tagged commit belongs
|
|
335
351
|
to the default branch and is the merge commit of a same-repository merged
|
|
336
|
-
|
|
352
|
+
PR (regardless of branch name), and the latest selected PR workflow run and required
|
|
337
353
|
jobs. The workflow and all matching required jobs must conclude success.
|
|
338
|
-
A
|
|
339
|
-
and unverifiable protection settings stop verification. Use
|
|
340
|
-
|
|
354
|
+
A tag without a qualifying merged PR is rejected. API access errors
|
|
355
|
+
and unverifiable protection settings stop verification. Use npm run release
|
|
356
|
+
to publish the existing version at the fetched default-branch commit. It checks
|
|
357
|
+
the merged PR and CI before tagging; the publish workflow verifies them again.
|
|
358
|
+
With strictVersionHistory true, --bump is rejected because versions must be
|
|
359
|
+
assigned before merge. With false, an unpublished existing version can be
|
|
360
|
+
released directly, or npm run release -- --bump patch (minor/major) prepares
|
|
361
|
+
a version-bump PR, waits for merge, then tags its merge commit. Already-published
|
|
362
|
+
versions and registry access errors stop a new release. Retries reuse the
|
|
363
|
+
pinned revision, PR and matching tag rather than creating another bump.
|
|
341
364
|
|
|
342
365
|
Complete npm trusted-publishing example with Volta
|
|
343
366
|
Keep publishing in a separate publish.yml as shown below, with exactly one
|
|
@@ -433,7 +456,7 @@ Using this check in the test chain
|
|
|
433
456
|
|
|
434
457
|
Default-branch GitHub policy chain
|
|
435
458
|
The configured PR workflow must use the approved reusable PR workflow in a
|
|
436
|
-
required release job, or run
|
|
459
|
+
required release job, or run github check with step GH_TOKEN
|
|
437
460
|
after npm ci and before tests in at least one job in git.releaseRequiredChecks.
|
|
438
461
|
Verification must be unconditional and must not allow failure. The existing
|
|
439
462
|
required-job validation applies to that job and its dependencies.
|
|
@@ -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', () => {
|
|
@@ -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']));
|
|
@@ -111,7 +112,7 @@ Do not delegate or launch other agents. Only read and assess; do not execute the
|
|
|
111
112
|
'-c', 'model_reasoning_effort="low"', '-c', 'model_verbosity="low"',
|
|
112
113
|
'--ephemeral', '--output-schema', path.join(modulesRoot, '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
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export const porticoFacade = ({ assessRelease, configureGithub, githubConfiguration, githubPolicy, release, releaseCore, reusableWorkflows, verifyRelease,
|
|
1
|
+
export const porticoFacade = ({ assessRelease, checkGithub, configureGithub, githubConfiguration, githubPolicy, release, releaseCore, reusableWorkflows, verifyRelease, verifyReleaseVersion }) => ({
|
|
2
2
|
assessRelease: assessRelease.run,
|
|
3
|
+
checkGithub: checkGithub.run,
|
|
3
4
|
configureGithub: configureGithub.run,
|
|
4
5
|
planGithub: githubConfiguration.plan,
|
|
5
6
|
createGithubPolicy: githubPolicy.createGithubPolicy,
|
|
@@ -9,6 +10,5 @@ export const porticoFacade = ({ assessRelease, configureGithub, githubConfigurat
|
|
|
9
10
|
reusableWorkflowErrors: reusableWorkflows.callErrors,
|
|
10
11
|
release: release.run,
|
|
11
12
|
verifyRelease: verifyRelease.run,
|
|
12
|
-
verifyReleaseProtection: verifyReleaseProtection.run,
|
|
13
13
|
verifyReleaseVersion: verifyReleaseVersion.run,
|
|
14
14
|
});
|
|
@@ -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
|
}
|
|
@@ -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,26 @@
|
|
|
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 commit = api(`${base}/commits/${encodeURIComponent(branch)}`);
|
|
6
|
+
if (typeof commit.sha !== 'string' || !/^[a-f0-9]{40}$/u.test(commit.sha)) {
|
|
7
|
+
throw new Error('Cannot determine the default branch commit for version history verification.');
|
|
8
|
+
}
|
|
9
|
+
// Pin the file lookup so a concurrent merge cannot change its source revision.
|
|
10
|
+
const file = api(`${base}/contents/package.json?ref=${commit.sha}`);
|
|
11
|
+
if (file.type !== 'file' || file.encoding !== 'base64' || typeof file.content !== 'string') {
|
|
12
|
+
throw new Error('Cannot read package.json from the default branch for version history verification.');
|
|
13
|
+
}
|
|
14
|
+
const previous = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')).version;
|
|
15
|
+
const current = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version;
|
|
16
|
+
for (const [source, version] of [['Default branch', previous], ['Incoming', current]]) {
|
|
17
|
+
if (typeof version !== 'string' || semver.valid(version) !== version.split('+')[0]) {
|
|
18
|
+
throw new Error(`${source} package.json must have a valid exact semver version.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!semver.gt(current, previous)) {
|
|
22
|
+
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.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { verifyVersionHistory };
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakobm/peacekeeper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Shared repository test, Git worktree, and Codex hook commands",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakob Mattsson",
|
|
@@ -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.10.1",
|
|
45
45
|
"glob": "^14.0.4",
|
|
46
46
|
"semver": "^7.8.5",
|
|
47
47
|
"yaml": "^2.9.1"
|
|
@@ -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
|
-
};
|