@jakobm/peacekeeper 0.27.0 → 0.29.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 +155 -51
- package/dist/cmdabra.yaml +3 -1
- package/dist/package.json +1 -2
- package/dist/src/modules/cli/service.js +1 -0
- package/dist/src/modules/configuration/project-config-defaults.json +3 -1
- package/dist/src/modules/configuration/project-config.js +17 -2
- package/dist/src/modules/dependencies.yaml +1 -1
- package/dist/src/modules/external.js +0 -2
- package/dist/src/modules/projects/check-project-requirements.txt +67 -36
- package/dist/src/modules/projects/check-project.js +33 -40
- package/dist/src/modules/projects/create-project-core.js +16 -12
- package/dist/src/modules/releases/facade.js +3 -1
- package/dist/src/modules/releases/release-core.js +25 -15
- package/dist/src/modules/releases/reusable-workflows.js +38 -0
- package/dist/src/modules/releases/reusable-workflows.json +16 -0
- package/dist/src/modules/testing/facade.js +2 -1
- package/dist/src/modules/testing/prepare-tests.js +33 -0
- package/package.json +1 -2
- package/dist/src/modules/projects/codex-setup-prefix.sh +0 -25
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ completion follows the same hierarchy.
|
|
|
15
15
|
| Group | Commands |
|
|
16
16
|
| --- | --- |
|
|
17
17
|
| `project` | `create`, `check`, `update-config`, `check-conventions` |
|
|
18
|
-
| `test` | `run`, `check-receipt`, `record-receipt` |
|
|
18
|
+
| `test` | `run`, `check-receipt`, `record-receipt`, `prepare` |
|
|
19
19
|
| `github` | `configure`, `generate-setup` |
|
|
20
20
|
| `release` | `assess`, `verify`, `verify-protection`, `verify-version`, `publish` |
|
|
21
21
|
| `codex` | `install-hooks`, `init-worktree`, `checkpoint`, `session-start`, `stop`, `session-end` |
|
|
@@ -34,8 +34,8 @@ For example, `run-tests --checkpoint` maps to `test run --checkpoint`,
|
|
|
34
34
|
`checkpoint-codex-changes` maps to `codex checkpoint`, and `release patch` maps
|
|
35
35
|
to `release publish patch`. Bare `release` now displays the release group's help.
|
|
36
36
|
Help and generated project files use the grouped names. Update existing package
|
|
37
|
-
scripts and CI to those names
|
|
38
|
-
|
|
37
|
+
scripts and CI to those names. The legacy hook installer remains available, but its repository-local files
|
|
38
|
+
conflict with the current project requirements.
|
|
39
39
|
|
|
40
40
|
## Architecture
|
|
41
41
|
|
|
@@ -59,7 +59,7 @@ checked-in output lives in `architecture/`. Peacekeeper's configured
|
|
|
59
59
|
|
|
60
60
|
Checkpoint and session lifecycle hooks use the same Cmdabra and Portico composition
|
|
61
61
|
as other CLI commands. Dependencies must therefore be installed in every worktree
|
|
62
|
-
before its hooks run;
|
|
62
|
+
before its hooks run; run `npm ci` explicitly when preparing a worktree.
|
|
63
63
|
|
|
64
64
|
The CLI also exposes Cmdabra's global `--cmdabra-complete` option for
|
|
65
65
|
[shell completion adapters](https://github.com/jakobmattsson/cmdabra#shell-completion).
|
|
@@ -84,6 +84,127 @@ cover deterministic output and local preflight failures for those commands.
|
|
|
84
84
|
CLI syntax validation and generated help output are covered by Cmdabra's own tests.
|
|
85
85
|
Expected output is reviewed text; tests never regenerate it automatically.
|
|
86
86
|
|
|
87
|
+
## Reuse the central workflows
|
|
88
|
+
|
|
89
|
+
Use Peacekeeper's reusable workflows for PR checks and npm publication. They
|
|
90
|
+
check out the calling repository, select its pinned Node/npm versions through
|
|
91
|
+
Volta, and run `npm ci`. The PR workflow verifies GitHub policy and runs
|
|
92
|
+
`npm test`; the publish workflow verifies the release and runs `npm publish`
|
|
93
|
+
through OIDC. Put project-specific checks, including packaging checks, in
|
|
94
|
+
`tests.all`. Neither workflow accepts inputs.
|
|
95
|
+
|
|
96
|
+
Install a Peacekeeper version containing this support before switching. Older
|
|
97
|
+
versions reject required reusable jobs. A minimal `.github/workflows/test.yml` is:
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
on:
|
|
101
|
+
pull_request:
|
|
102
|
+
branches: [main]
|
|
103
|
+
permissions:
|
|
104
|
+
contents: read
|
|
105
|
+
jobs:
|
|
106
|
+
test:
|
|
107
|
+
uses: jakobmattsson/peacekeeper/.github/workflows/reusable-pr.yml@17a6c202c0f3cd66f1bb4a42d1dc8c78e7eb60d6
|
|
108
|
+
secrets:
|
|
109
|
+
RELEASE_POLICY_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
For npm packages, keep a separate publishing entrypoint with its existing filename
|
|
113
|
+
(the filename forms part of the npm trusted-publisher registration):
|
|
114
|
+
|
|
115
|
+
```yaml
|
|
116
|
+
on:
|
|
117
|
+
push:
|
|
118
|
+
tags: ['v*']
|
|
119
|
+
permissions:
|
|
120
|
+
contents: read
|
|
121
|
+
id-token: write
|
|
122
|
+
jobs:
|
|
123
|
+
publish:
|
|
124
|
+
uses: jakobmattsson/peacekeeper/.github/workflows/reusable-publish.yml@a438e3d706a1812fea72dc0858378566f4e3bb21
|
|
125
|
+
secrets:
|
|
126
|
+
RELEASE_POLICY_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The caller owns event triggers, explicit permissions, and secret mapping.
|
|
130
|
+
GitHub does not let the called workflow raise permissions granted by the caller;
|
|
131
|
+
publication therefore declares `id-token: write` in both. `name` is optional.
|
|
132
|
+
Use `git.defaultBranch` in the PR trigger. Pass the policy secret explicitly;
|
|
133
|
+
`secrets: inherit` is not supported, and its source may have another name.
|
|
134
|
+
The policy token is exposed only to verification. Configure repository secrets,
|
|
135
|
+
GitHub protection, and npm trusted publishing separately; fork PRs do not receive
|
|
136
|
+
repository secrets. npm must authorize the calling repository and entrypoint.
|
|
137
|
+
|
|
138
|
+
GitHub names the checks `test / test` and `publish / publish`: the caller job's
|
|
139
|
+
name (or ID), followed by the central job name. Merge these fields into the full
|
|
140
|
+
project configuration:
|
|
141
|
+
|
|
142
|
+
```yaml
|
|
143
|
+
projectChecks:
|
|
144
|
+
testWorkflow: test.yml
|
|
145
|
+
requiredJobs: ['test / test']
|
|
146
|
+
git:
|
|
147
|
+
releaseTestWorkflow: test.yml
|
|
148
|
+
releaseRequiredChecks: ['test / test']
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
If the caller has `name: CI`, require `CI / test` instead. Update GitHub's required
|
|
152
|
+
checks to the same name when migrating and confirm it in a PR run. A skipped or
|
|
153
|
+
renamed check cannot satisfy release verification. Additional local jobs remain
|
|
154
|
+
supported and are validated separately when required. `project create` generates
|
|
155
|
+
these thin callers, including publication for npm projects.
|
|
156
|
+
|
|
157
|
+
Peacekeeper trusts reviewed central implementations through the full workflow
|
|
158
|
+
commit SHAs bundled in
|
|
159
|
+
[`reusable-workflows.json`](src/modules/releases/reusable-workflows.json).
|
|
160
|
+
Caller contracts are checked offline, without downloading remote YAML. Unknown
|
|
161
|
+
SHAs, branch names, tags, inherited secrets, inputs, matrices and runner/step
|
|
162
|
+
or failure-handling overrides are rejected. Inline workflows remain supported.
|
|
163
|
+
|
|
164
|
+
To approve an update, review, test and commit the central workflows first, then
|
|
165
|
+
add that commit's full SHA to the allowlist in a subsequent commit. Preserve the
|
|
166
|
+
single static `test` or `publish` job, explicit policy secret, no-input contract,
|
|
167
|
+
and verified setup and step order. Contract tests check both implementations
|
|
168
|
+
through the public project checker. Consumers deliberately update approved pins.
|
|
169
|
+
|
|
170
|
+
## Standard CI test environment
|
|
171
|
+
|
|
172
|
+
The central PR workflow runs one Ubuntu 24.04 job. It cancels superseded runs for
|
|
173
|
+
one PR, installs npm dependencies, validates the project, prepares the test
|
|
174
|
+
prerequisites, verifies GitHub policy and runs `npm test`.
|
|
175
|
+
|
|
176
|
+
Declare the optional test prerequisites in `peacekeeper.config.yaml`:
|
|
177
|
+
|
|
178
|
+
```yaml
|
|
179
|
+
tests:
|
|
180
|
+
aptPackages: [ledger, bash-completion]
|
|
181
|
+
playwrightBrowsers: [chromium, webkit]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Both lists default to empty. `aptPackages` installs Ubuntu packages, optionally
|
|
185
|
+
pinned as `name=version`. `playwrightBrowsers` installs the named browsers and
|
|
186
|
+
their system dependencies using the project's installed Playwright CLI. The
|
|
187
|
+
project's lockfile therefore selects the matching browser versions. An empty
|
|
188
|
+
browser list skips Playwright installation entirely, including its system
|
|
189
|
+
dependencies; Peacekeeper never installs the Playwright npm package itself.
|
|
190
|
+
|
|
191
|
+
`test prepare` installs these prerequisites after `npm ci` and before tests.
|
|
192
|
+
`project update-config` adds explicit empty lists to existing configurations.
|
|
193
|
+
The standard workflow allows 15 minutes for preparation, 30 minutes for tests
|
|
194
|
+
and 60 minutes for the overall job. Upgrade the approved PR workflow pin
|
|
195
|
+
together with Peacekeeper when adopting this preparation support.
|
|
196
|
+
|
|
197
|
+
Keep actual package, image and application checks in the canonical test chain.
|
|
198
|
+
`npm test` must run the complete intended verification. It can use Peacekeeper's
|
|
199
|
+
runner or the project's independent test engine. For an independent engine,
|
|
200
|
+
set `tests.npmTestUsesRunner: false` and `tests.all: ['npm test']`; that npm
|
|
201
|
+
script must not invoke `peacekeeper test run` recursively. Project validation
|
|
202
|
+
also runs explicitly in CI.
|
|
203
|
+
|
|
204
|
+
Projects needing additional setup or reporting can define their own workflows
|
|
205
|
+
with ordinary GitHub Actions steps. The standard workflow only configures the
|
|
206
|
+
two prerequisite lists above.
|
|
207
|
+
|
|
87
208
|
## Create a compliant TypeScript project
|
|
88
209
|
|
|
89
210
|
`project create` creates a minimal ESM TypeScript library in an existing, completely
|
|
@@ -431,7 +552,12 @@ Test-generated files should be ignored or written outside the repository.
|
|
|
431
552
|
receipt. `test record-receipt` certifies those commands without executing them.
|
|
432
553
|
Both support `--checkpoint` to select `tests.checkpoint` instead.
|
|
433
554
|
|
|
434
|
-
###
|
|
555
|
+
### Legacy repository hooks
|
|
556
|
+
|
|
557
|
+
Repository-local `.codex` is no longer supported by `project check`. Remove
|
|
558
|
+
existing `.codex` directories when upgrading, preserving any needed setup outside
|
|
559
|
+
the repository first. New projects do not generate them. The commands below
|
|
560
|
+
remain available for explicit legacy use and create files rejected by project validation.
|
|
435
561
|
|
|
436
562
|
Install or update the project hooks from the caller's Git worktree:
|
|
437
563
|
|
|
@@ -739,12 +865,12 @@ With `true`, declare a publishable package (`private` absent or `false`), a vali
|
|
|
739
865
|
npm name, stable version, description, license, nonempty `files` list, and
|
|
740
866
|
`publishConfig` with registry `https://registry.npmjs.org/` and explicit access
|
|
741
867
|
`public` or `restricted`. Add a direct `peacekeeper release publish` package script
|
|
742
|
-
(the npm-exec and local Node CLI forms are also supported)
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
868
|
+
(the npm-exec and local Node CLI forms are also supported) and the verified OIDC
|
|
869
|
+
release workflow described below. Put packaging checks such as
|
|
870
|
+
`npm pack --dry-run --json` or `npm run test:package` in `tests.all`.
|
|
871
|
+
Installation tests of the packed package in a temporary consumer project are
|
|
872
|
+
recommended. The local checker does not enforce a special packaging command
|
|
873
|
+
or inspect test-script assertions.
|
|
748
874
|
|
|
749
875
|
With `false`, set `package.json.private` to `true` and remove `publishConfig`,
|
|
750
876
|
`files`, npm publication/release scripts, and npm publication workflow steps.
|
|
@@ -765,39 +891,16 @@ architecture, requirements, configuration examples, and verification limits.
|
|
|
765
891
|
The command prints the bundled [formal requirements](src/modules/projects/check-project-requirements.txt),
|
|
766
892
|
which can also be read without a repository or project configuration.
|
|
767
893
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
and runs `npm ci` using the package.json pins. It then runs
|
|
779
|
-
`peacekeeper codex init-worktree --sync-primary` followed by
|
|
780
|
-
`peacekeeper cleanup merged-branches --execute` before any project-specific setup,
|
|
781
|
-
initializing each new linked worktree from the exact commit fetched from the
|
|
782
|
-
configured remote default branch, safely synchronizing the primary checkout, and
|
|
783
|
-
removing merged branches and their linked worktrees.
|
|
784
|
-
A passing check validates the parsed script text; it does not run setup or prove
|
|
785
|
-
that a fresh environment works. Verify that separately in a new Codex worktree.
|
|
786
|
-
Prefix changes in future Peacekeeper versions require updating each project's
|
|
787
|
-
environment configuration.
|
|
788
|
-
|
|
789
|
-
The required sequence ends like this:
|
|
790
|
-
|
|
791
|
-
```toml
|
|
792
|
-
[setup]
|
|
793
|
-
script = '''
|
|
794
|
-
# ...the required Peacekeeper setup prefix...
|
|
795
|
-
npm ci
|
|
796
|
-
npm exec --no -- peacekeeper codex init-worktree --sync-primary
|
|
797
|
-
npm exec --no -- peacekeeper cleanup merged-branches --execute
|
|
798
|
-
# Add custom project setup below
|
|
799
|
-
'''
|
|
800
|
-
```
|
|
894
|
+
The repository root must not contain `.codex`, even as an empty directory, file,
|
|
895
|
+
or symbolic link. Remove it when upgrading, preserving any needed setup outside
|
|
896
|
+
the repository first. Validation reports the violation without changing files.
|
|
897
|
+
New projects omit both environment configuration and repository hooks. The legacy
|
|
898
|
+
`codex install-hooks` command still creates `.codex/hooks.json` when explicitly
|
|
899
|
+
requested; that output fails `project check`.
|
|
900
|
+
|
|
901
|
+
Prepare new worktrees explicitly: select the pinned Volta toolchain, run `npm ci`,
|
|
902
|
+
and, when needed, run `peacekeeper codex init-worktree --sync-primary` for a fresh
|
|
903
|
+
worktree. Keep project-specific setup in your external environment configuration.
|
|
801
904
|
|
|
802
905
|
`--sync-primary` makes Peacekeeper also update a clean primary checkout when its
|
|
803
906
|
default branch can be fast-forwarded safely. A clean non-default branch there is
|
|
@@ -899,14 +1002,14 @@ with direct publishing enabled. Confirm npm publish access to the `@jakobm`
|
|
|
899
1002
|
scope separately from GitHub repository access. The workflow verifies
|
|
900
1003
|
the release and publishes via OIDC. It needs no npm access token.
|
|
901
1004
|
|
|
902
|
-
`test.yml`
|
|
1005
|
+
`test.yml` calls the central PR workflow, producing `test / test`. `package.yml` calls the central publication workflow and runs
|
|
903
1006
|
on `v*` tags and only verifies and publishes. Merging to `main` does not start
|
|
904
1007
|
another run.
|
|
905
1008
|
|
|
906
1009
|
Release verification uses GitHub's enforced branch policy instead of retaining
|
|
907
1010
|
artifacts of tested contents. Configure `git.releaseRequiredChecks` in the root
|
|
908
1011
|
`peacekeeper.config.yaml` with the exact CI job names required for a release
|
|
909
|
-
(for this repository: `["test
|
|
1012
|
+
(for this repository: `["test / test"]`). These checks must be mandatory
|
|
910
1013
|
with **Require branches to be up to date before merging** enabled. Classic branch
|
|
911
1014
|
protection may provide the base PR and check requirements. Active base rulesets
|
|
912
1015
|
may provide them instead. Merge
|
|
@@ -932,13 +1035,14 @@ Required linear history and any applicable PR rule excluding merge commits fail
|
|
|
932
1035
|
verification. Bypass actors for base PR and strict-check rules require manual
|
|
933
1036
|
inspection only when GitHub omits them from its response.
|
|
934
1037
|
Enable `allow_auto_merge` in repository settings: this permits opting in per PR;
|
|
935
|
-
|
|
1038
|
+
the release command enables auto-merge on its release PRs.
|
|
936
1039
|
|
|
937
1040
|
`project check` makes no network requests. It runs implicitly before
|
|
938
1041
|
`tests.all` or `tests.checkpoint`, including when reusing receipts, and checks that the configured
|
|
939
1042
|
PR workflow uses only `pull_request`, with `branches` set to exactly
|
|
940
1043
|
`[git.defaultBranch]`, and runs `release verify-protection` with `GH_TOKEN` after `npm ci` and
|
|
941
|
-
before tests in a job listed in `git.releaseRequiredChecks
|
|
1044
|
+
before tests in a job listed in `git.releaseRequiredChecks`, either through local
|
|
1045
|
+
steps or the approved central PR workflow above. The job and step must
|
|
942
1046
|
not skip verification or ignore failures. The online verifier then checks that
|
|
943
1047
|
exactly those configured check names are mandatory on GitHub, including its own
|
|
944
1048
|
job; missing and additional checks are both configuration drift.
|
|
@@ -1041,9 +1145,9 @@ increment the package and lockfile versions. Your current branch and local defau
|
|
|
1041
1145
|
branch stay unchanged, including when the default branch is checked out elsewhere.
|
|
1042
1146
|
Before changing versions it logs `Preparing release from origin/<branch> at <SHA>.`
|
|
1043
1147
|
using the full source commit ID checked out in the temporary worktree.
|
|
1044
|
-
It pushes a `release/v<version>` branch and opens a release PR. The
|
|
1045
|
-
|
|
1046
|
-
|
|
1148
|
+
It pushes a `release/v<version>` branch and opens a release PR. The command enables
|
|
1149
|
+
auto-merge for the expected PR head using a merge commit, then waits up to 20
|
|
1150
|
+
minutes for GitHub to complete the merge,
|
|
1047
1151
|
respecting required checks, reviews, resolved conversations, and branch freshness.
|
|
1048
1152
|
It never uses an administrator bypass or pushes directly to the default branch.
|
|
1049
1153
|
|
package/dist/cmdabra.yaml
CHANGED
|
@@ -44,7 +44,7 @@ commands:
|
|
|
44
44
|
description: Replace generated output directories after successful generation; check other rules.
|
|
45
45
|
type: boolean
|
|
46
46
|
test:
|
|
47
|
-
description:
|
|
47
|
+
description: Prepare test prerequisites, run tests and manage command receipts.
|
|
48
48
|
commands:
|
|
49
49
|
run:
|
|
50
50
|
description: Run tests.all, reusing valid receipts for individual commands.
|
|
@@ -67,6 +67,8 @@ commands:
|
|
|
67
67
|
checkpoint:
|
|
68
68
|
description: Record tests.checkpoint instead of tests.all.
|
|
69
69
|
type: boolean
|
|
70
|
+
prepare:
|
|
71
|
+
description: Install tests.aptPackages and tests.playwrightBrowsers when configured.
|
|
70
72
|
github:
|
|
71
73
|
description: Configure GitHub repository policy.
|
|
72
74
|
commands:
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakobm/peacekeeper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Shared repository test, Git worktree, and Codex hook commands",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakob Mattsson",
|
|
@@ -40,7 +40,6 @@
|
|
|
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",
|
|
@@ -20,6 +20,7 @@ export default ({ configuration, legacyCommands, lifecycle, maintenance, project
|
|
|
20
20
|
checkConventions: options => testing.checkConventions({ update: options.update }),
|
|
21
21
|
},
|
|
22
22
|
test: {
|
|
23
|
+
prepare: () => testing.prepareTests(),
|
|
23
24
|
run: options => testing.runTests({ force: options.force, checkpoint: options.checkpoint }),
|
|
24
25
|
checkReceipt: options => testing.checkTestReceipt({ checkpoint: options.checkpoint }),
|
|
25
26
|
recordReceipt: options => testing.recordTestReceipt({ checkpoint: options.checkpoint }),
|
|
@@ -13,7 +13,7 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
13
13
|
git: { remote: true, defaultBranch: true, branchPrefix: true, requiredApprover: true,
|
|
14
14
|
checkpointPushRemotes: true, releaseMergeMethod: true,
|
|
15
15
|
releaseRequiredChecks: true, releaseTestWorkflow: true },
|
|
16
|
-
tests: { all: true, checkpoint: true, receiptMaxAgeMinutes: true, npmTestUsesRunner: true },
|
|
16
|
+
tests: { all: true, checkpoint: true, receiptMaxAgeMinutes: true, npmTestUsesRunner: true, aptPackages: true, playwrightBrowsers: true },
|
|
17
17
|
conventions: { rules: true },
|
|
18
18
|
loggingDirectory: true,
|
|
19
19
|
loggingEnabled: true,
|
|
@@ -30,6 +30,8 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
30
30
|
}
|
|
31
31
|
for (const [key, child] of Object.entries(schema)) {
|
|
32
32
|
const name = location === 'config' ? key : `${location}.${key}`;
|
|
33
|
+
if (location === 'tests' && ['aptPackages', 'playwrightBrowsers'].includes(key) && !Object.hasOwn(value, key))
|
|
34
|
+
continue;
|
|
33
35
|
if (!Object.hasOwn(value, key))
|
|
34
36
|
errors.push(`missing field ${name}`);
|
|
35
37
|
else if (child !== true)
|
|
@@ -97,6 +99,19 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
97
99
|
throw new Error(`${file}: tests.${level} must be an array of command strings`);
|
|
98
100
|
}
|
|
99
101
|
}
|
|
102
|
+
for (const field of ['aptPackages', 'playwrightBrowsers']) {
|
|
103
|
+
const entries = config.tests[field] === undefined ? [] : config.tests[field];
|
|
104
|
+
if (!Array.isArray(entries) || entries.some(entry => typeof entry !== 'string' || !entry.trim())
|
|
105
|
+
|| new Set(entries).size !== entries.length) {
|
|
106
|
+
throw new Error(`${file}: tests.${field} must be an array of unique nonempty strings`);
|
|
107
|
+
}
|
|
108
|
+
if (field === 'aptPackages' && entries.some(name => !/^[a-z0-9][a-z0-9+.-]*(?:=[A-Za-z0-9:.+~_-]+)?$/u.test(name))) {
|
|
109
|
+
throw new Error(`${file}: tests.aptPackages must contain package names with optional exact versions`);
|
|
110
|
+
}
|
|
111
|
+
if (field === 'playwrightBrowsers' && entries.some(browser => !['chromium', 'firefox', 'webkit'].includes(browser))) {
|
|
112
|
+
throw new Error(`${file}: tests.playwrightBrowsers must select chromium, firefox or webkit`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
100
115
|
const missing = config.tests.checkpoint.filter(command => !config.tests.all.includes(command));
|
|
101
116
|
if (missing.length) {
|
|
102
117
|
throw new Error(`${file}: every command in tests.checkpoint must also appear in tests.all; missing: ${JSON.stringify(missing)}`);
|
|
@@ -120,7 +135,7 @@ export default ({ conventionRules, external: { execFileSync, fs, path, projectCo
|
|
|
120
135
|
? YAML.parse(fs.readFileSync(file, 'utf8'))
|
|
121
136
|
: JSON.parse(JSON.stringify(projectConfigDefaults));
|
|
122
137
|
validateConfig(config, file);
|
|
123
|
-
return { root, ...config };
|
|
138
|
+
return { root, ...config, tests: { ...projectConfigDefaults.tests, ...config.tests } };
|
|
124
139
|
}
|
|
125
140
|
function requireTestCommands(root) {
|
|
126
141
|
if (!projectConfig(root).tests.all.length) {
|
|
@@ -11,6 +11,6 @@ allowed-external:
|
|
|
11
11
|
configuration: [YAML, execFileSync, fs, hasMagic, isDeepStrictEqual, output, path, projectConfigDefaults, runtime]
|
|
12
12
|
lifecycle: [buffer, clock, executablePath, fs, output, path, runtime, spawn, spawnSync]
|
|
13
13
|
maintenance: [execFileSync, fs, output, path, runtime, spawnSync]
|
|
14
|
-
projects: [
|
|
14
|
+
projects: [YAML, buffer, fs, modulesRoot, output, packageVersion, path, projectConfigDefaults, runtime, semver, spawnSync, structuredClone, url]
|
|
15
15
|
releases: [YAML, assessReleaseSchema, buffer, clock, execFileSync, fs, modulesRoot, os, output, packageVersion, path, projectConfigDefaults, runtime, semver, spawnSync, structuredClone, url]
|
|
16
16
|
testing: [YAML, clock, crypto, execFileSync, fs, globSync, hasMagic, modulesRoot, os, output, path, runtime, spawnSync, test]
|
|
@@ -7,7 +7,6 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
7
7
|
import test from 'node:test';
|
|
8
8
|
import { globSync, hasMagic } from 'glob';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
|
-
import TOML from '@iarna/toml';
|
|
11
10
|
import semver from 'semver';
|
|
12
11
|
import YAML from 'yaml';
|
|
13
12
|
import assessReleaseSchema from './releases/assess-release-schema.json' with { type: 'json' };
|
|
@@ -48,7 +47,6 @@ export default () => ({
|
|
|
48
47
|
spawnSync,
|
|
49
48
|
structuredClone,
|
|
50
49
|
test,
|
|
51
|
-
TOML,
|
|
52
50
|
url: URL,
|
|
53
51
|
YAML,
|
|
54
52
|
});
|
|
@@ -15,7 +15,8 @@ Purpose and scope
|
|
|
15
15
|
Project configuration
|
|
16
16
|
package.json is required at the Git root. Without peacekeeper.config.yaml,
|
|
17
17
|
bundled defaults apply. An existing configuration must declare every schema
|
|
18
|
-
field, including nested fields
|
|
18
|
+
field, including nested fields, except the optional tests.aptPackages and
|
|
19
|
+
tests.playwrightBrowsers lists; unknown fields and invalid values fail.
|
|
19
20
|
Run peacekeeper project update-config to create or complete it without overwriting
|
|
20
21
|
existing values. Migrate tests.commands to tests.all and add tests.checkpoint
|
|
21
22
|
as an empty list. Review inserted defaults. Empty tests.all blocks tests
|
|
@@ -78,33 +79,13 @@ Toolchain: package.json and all Node-based CI jobs
|
|
|
78
79
|
- run: npm ci
|
|
79
80
|
- run: npm test
|
|
80
81
|
|
|
81
|
-
Codex
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
If setup.linux, setup.macos or setup.windows overrides are present, their
|
|
89
|
-
script values must start with the same prefix to prevent bypassing setup.
|
|
90
|
-
|
|
91
|
-
Copy the reference into a TOML multiline literal string to preserve shell
|
|
92
|
-
backslashes. Preserve project-specific steps when replacing an older prefix.
|
|
93
|
-
The prefix requires Bash and curl, activates or installs Volta without editing
|
|
94
|
-
shell profiles, logs tool versions, runs npm ci using package.json pins, then
|
|
95
|
-
initializes the linked worktree and safely synchronizes the primary checkout.
|
|
96
|
-
Peacekeeper only reads this reference; it never executes the shell file or
|
|
97
|
-
the project's setup script. Passing validates declarations, not successful
|
|
98
|
-
provisioning, network access or availability of project-specific prerequisites.
|
|
99
|
-
Verify actual setup separately in a clean Codex worktree. New prefix versions
|
|
100
|
-
require updating consumer configurations.
|
|
101
|
-
|
|
102
|
-
Codex lifecycle hooks
|
|
103
|
-
.codex/hooks.json must contain the current peacekeeper hooks exactly once
|
|
104
|
-
for each lifecycle event, in their expected order, without group conditions.
|
|
105
|
-
Unrelated hooks are allowed. Repair with:
|
|
106
|
-
peacekeeper codex install-hooks
|
|
107
|
-
Hook installation does not itself grant Codex trust.
|
|
82
|
+
Codex configuration
|
|
83
|
+
The repository root must not contain .codex, including an empty directory,
|
|
84
|
+
file or symbolic link. Remove existing repository-local Codex configuration.
|
|
85
|
+
Preserve any needed setup outside the repository before removing it.
|
|
86
|
+
Project validation only reports the path; it does not delete or migrate files.
|
|
87
|
+
New projects do not generate .codex. The legacy codex install-hooks command
|
|
88
|
+
still creates .codex/hooks.json explicitly and therefore conflicts with this rule.
|
|
108
89
|
|
|
109
90
|
All GitHub Actions workflows
|
|
110
91
|
Every .yml/.yaml file under .github/workflows must parse and declare jobs.
|
|
@@ -127,13 +108,15 @@ Required PR workflow and jobs
|
|
|
127
108
|
in separate workflows.
|
|
128
109
|
|
|
129
110
|
Each required name must match exactly one static job display name (name), or
|
|
130
|
-
the job ID if name is absent.
|
|
131
|
-
|
|
111
|
+
the job ID if name is absent. For an approved reusable PR call, use the full
|
|
112
|
+
GitHub check name: "<caller name or ID> / test". Expressions in required names
|
|
113
|
+
are rejected. Required jobs and all their needs dependencies must use local
|
|
114
|
+
steps or the approved reusable PR workflow described below, must
|
|
132
115
|
not allow failure, and must not have conditions that skip required PR checks.
|
|
133
116
|
Accepted job conditions are absent, success(), ${{ success() }}, or exactly:
|
|
134
117
|
${{ github.event_name == 'pull_request' }}
|
|
135
118
|
|
|
136
|
-
Each required test job must run unconditional npm ci before an unconditional
|
|
119
|
+
Each required test job using local steps must run unconditional npm ci before an unconditional
|
|
137
120
|
supported validation command, with neither step allowed to fail. Commands
|
|
138
121
|
must be direct run steps, exactly one of:
|
|
139
122
|
npm test
|
|
@@ -141,11 +124,59 @@ Required PR workflow and jobs
|
|
|
141
124
|
npm run test:<name> (name contains letters, digits, _ or -)
|
|
142
125
|
npm pack --dry-run
|
|
143
126
|
npm pack --dry-run --json
|
|
144
|
-
Shell wrappers, combined commands, and reusable workflows cannot establish
|
|
127
|
+
Shell wrappers, combined commands, and unapproved reusable workflows cannot establish
|
|
145
128
|
these requirements. Conditional reporting steps after tests are allowed.
|
|
146
129
|
An unconditional step either omits if or sets it to success() or
|
|
147
130
|
${{ success() }}.
|
|
148
131
|
|
|
132
|
+
Standard CI preparation
|
|
133
|
+
Optional tests.aptPackages and tests.playwrightBrowsers lists default to empty.
|
|
134
|
+
Apt entries select Ubuntu packages with optional exact versions. Playwright
|
|
135
|
+
browsers select chromium, firefox or webkit from the project's installed CLI.
|
|
136
|
+
An empty browser list skips browser and Playwright system dependency installation.
|
|
137
|
+
The standard PR job runs test prepare after npm ci, before npm test, and validates
|
|
138
|
+
project configuration independently of the chosen test engine. The lists must
|
|
139
|
+
contain unique nonempty strings; invalid package names and browsers fail.
|
|
140
|
+
Keep the intended verification in npm test and additional workflow behavior
|
|
141
|
+
in repository-defined GitHub Actions steps. See README for the full contract.
|
|
142
|
+
|
|
143
|
+
Approved reusable PR workflow
|
|
144
|
+
Instead of repeating setup, policy verification and test steps in every repo,
|
|
145
|
+
call the central workflow with a full SHA approved by this Peacekeeper version:
|
|
146
|
+
jobs:
|
|
147
|
+
test:
|
|
148
|
+
uses: jakobmattsson/peacekeeper/.github/workflows/reusable-pr.yml@17a6c202c0f3cd66f1bb4a42d1dc8c78e7eb60d6
|
|
149
|
+
secrets:
|
|
150
|
+
RELEASE_POLICY_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
|
|
151
|
+
Declare permissions.contents as read (or write) at the caller job or workflow.
|
|
152
|
+
Keep the caller's PR trigger and branch restriction described above. The central
|
|
153
|
+
workflow owns checkout, Volta, npm ci, release verify-protection and npm test.
|
|
154
|
+
The consumer must install a Peacekeeper version supporting this contract as a project dependency.
|
|
155
|
+
|
|
156
|
+
Set both projectChecks.requiredJobs and git.releaseRequiredChecks to include
|
|
157
|
+
"test / test" (or "<caller name> / test" with an explicit name). Npm projects
|
|
158
|
+
must also set git.releaseTestWorkflow to projectChecks.testWorkflow. Require
|
|
159
|
+
the same full context in GitHub protection and verify it in a PR run.
|
|
160
|
+
|
|
161
|
+
No inputs are accepted. Put project-specific checks, including packaging, in
|
|
162
|
+
tests.all. Only the explicitly mapped RELEASE_POLICY_TOKEN secret
|
|
163
|
+
is accepted; its value must reference a repository secret. Inherited secrets,
|
|
164
|
+
arbitrary inputs, matrices, runner/step/environment overrides and ignored
|
|
165
|
+
failures are rejected. Required-job conditions and needs checks still apply.
|
|
166
|
+
|
|
167
|
+
The approved workflow path and commit SHAs are bundled in
|
|
168
|
+
releases/reusable-workflows.json. Local checks validate this caller contract
|
|
169
|
+
without downloading or expanding the central workflow. Unknown SHAs, branches
|
|
170
|
+
and tags are rejected. Other reusable workflows cannot replace required jobs.
|
|
171
|
+
Inline required jobs continue to use the detailed local-step rules above.
|
|
172
|
+
Publication can call reusable-publish.yml at a SHA in that allowlist through
|
|
173
|
+
a separate caller workflow.
|
|
174
|
+
Keep the local push tags trigger and explicit secret mapping. Declare contents:
|
|
175
|
+
read and id-token: write in the caller; the callee cannot raise its permissions.
|
|
176
|
+
This workflow owns setup, npm ci, release verify and npm publish. It accepts no
|
|
177
|
+
inputs and exposes one static publish job, producing "publish / publish".
|
|
178
|
+
Keep the caller filename registered with npm trusted publishing.
|
|
179
|
+
|
|
149
180
|
Matrix example: tests on three platforms and one static required gate:
|
|
150
181
|
jobs:
|
|
151
182
|
matrix-tests:
|
|
@@ -232,9 +263,8 @@ Publication: publishesToNpm=true
|
|
|
232
263
|
directly invoke peacekeeper release publish (also supported: npm exec --no --
|
|
233
264
|
peacekeeper release publish or the local Node CLI forms). Run releases through
|
|
234
265
|
npm run release so npm does not bypass the prerelease installation.
|
|
235
|
-
|
|
236
|
-
npm
|
|
237
|
-
--dry-run, optionally followed by --json), or npm run test:package.
|
|
266
|
+
Put packaging checks in tests.all, such as npm pack --dry-run --json or
|
|
267
|
+
npm run test:package. No workflow step receives special packaging treatment.
|
|
238
268
|
npm script aliases are resolved without executing them. Package installation
|
|
239
269
|
tests using a temporary consumer are recommended; script names do not prove
|
|
240
270
|
assertion coverage. npm publish must not be conditional or allowed to fail.
|
|
@@ -402,7 +432,8 @@ Using this check in the test chain
|
|
|
402
432
|
existing receipt. This check remains entirely local.
|
|
403
433
|
|
|
404
434
|
Default-branch GitHub policy chain
|
|
405
|
-
The configured PR workflow must
|
|
435
|
+
The configured PR workflow must use the approved reusable PR workflow in a
|
|
436
|
+
required release job, or run release verify-protection with step GH_TOKEN
|
|
406
437
|
after npm ci and before tests in at least one job in git.releaseRequiredChecks.
|
|
407
438
|
Verification must be unconditional and must not allow failure. The existing
|
|
408
439
|
required-job validation applies to that job and its dependencies.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ configuration, releases, external: { fs, modulesRoot, output, path, runtime, semver, YAML, } }) => {
|
|
2
3
|
const { projectConfig } = configuration;
|
|
3
|
-
const {
|
|
4
|
-
const { inspectWorkflow, ensureLockfilesMatch } = releases;
|
|
4
|
+
const { inspectWorkflow, ensureLockfilesMatch, reusableWorkflow, reusableWorkflowErrors } = releases;
|
|
5
5
|
function read(root, file, parse = JSON.parse) {
|
|
6
6
|
try {
|
|
7
7
|
return parse(fs.readFileSync(path.join(root, file), 'utf8'));
|
|
@@ -19,6 +19,11 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
19
19
|
const testCommand = /^npm (?:test|run test(?::[\w-]+)?|pack --dry-run(?: --json)?)$/u;
|
|
20
20
|
const installCommand = /^npm ci$/u;
|
|
21
21
|
const verifyCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) (?:release verify|verify-release)$/u;
|
|
22
|
+
const reusable = reusableWorkflow('pr');
|
|
23
|
+
function checkName(id, job) {
|
|
24
|
+
const name = job.name || id;
|
|
25
|
+
return job.uses ? `${name} / ${reusable.jobName}` : name;
|
|
26
|
+
}
|
|
22
27
|
function checkProject(cwd = runtime.cwd()) {
|
|
23
28
|
const config = projectConfig(cwd);
|
|
24
29
|
const root = config.root;
|
|
@@ -145,33 +150,21 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
145
150
|
});
|
|
146
151
|
}
|
|
147
152
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const prefix = fs.readFileSync(path.join(modulesRoot, 'projects/codex-setup-prefix.sh'), 'utf8');
|
|
153
|
-
requireThat(typeof document.setup?.script === 'string' && document.setup.script.startsWith(prefix), `${file}: setup.script must start with the exact prefix below, including the newline after the final comment. Preserve custom project setup after that comment.\n${prefix}`);
|
|
154
|
-
// Platform overrides replace the default setup and must preserve its contract too.
|
|
155
|
-
for (const platform of ['linux', 'macos', 'windows']) {
|
|
156
|
-
if (!Object.hasOwn(document.setup || {}, platform))
|
|
153
|
+
const centralJobs = new Set();
|
|
154
|
+
for (const [file, workflow] of workflows)
|
|
155
|
+
for (const [id, job] of Object.entries(workflow.jobs)) {
|
|
156
|
+
if (typeof job?.uses !== 'string' || !job.uses.startsWith(`${reusable.workflow}@`))
|
|
157
157
|
continue;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const localSource = fs.realpathSync(root) === fs.realpathSync(path.resolve(modulesRoot, '../../..'));
|
|
165
|
-
const expected = planHooks(document, localSource).document;
|
|
166
|
-
for (const event of new Set([...Object.keys(document.hooks || {}), ...Object.keys(expected.hooks)])) {
|
|
167
|
-
const owned = groups => groups.flatMap(group => {
|
|
168
|
-
const handlers = group.hooks.filter(hook => classifyCommand(hook.command) !== 'other');
|
|
169
|
-
if (handlers.length)
|
|
170
|
-
requireThat(Object.keys(group).every(key => key === 'hooks'), '.codex/hooks.json: peacekeeper lifecycle hooks must not have group conditions.');
|
|
171
|
-
return handlers;
|
|
158
|
+
check('CI', () => {
|
|
159
|
+
const before = errors.length;
|
|
160
|
+
for (const error of reusableWorkflowErrors('pr', job, workflow.permissions))
|
|
161
|
+
requireThat(false, `${file}/${id}: ${error}`);
|
|
162
|
+
if (errors.length === before)
|
|
163
|
+
centralJobs.add(job);
|
|
172
164
|
});
|
|
173
|
-
requireThat(isDeepStrictEqual(owned(document.hooks?.[event] || []), owned(expected.hooks[event] || [])), `.codex/hooks.json: missing, duplicate or outdated ${event} lifecycle hooks; run peacekeeper codex install-hooks.`);
|
|
174
165
|
}
|
|
166
|
+
check('Codex configuration', () => {
|
|
167
|
+
requireThat(!fs.lstatSync(path.join(root, '.codex'), { throwIfNoEntry: false }), '.codex must be removed from the repository root; repository-local Codex configuration is no longer supported. Preserve any needed setup outside the repository before removing it.');
|
|
175
168
|
});
|
|
176
169
|
const published = config.publishesToNpm;
|
|
177
170
|
check('publication', () => {
|
|
@@ -202,16 +195,6 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
202
195
|
requireThat(Array.isArray(manifest.files) && manifest.files.length > 0 && manifest.files.every(nonblank), 'package.json: published packages require a nonempty files list.');
|
|
203
196
|
requireThat(typeof scripts.prerelease === 'string' && scripts.prerelease.trim() === 'npm ci', 'package.json: scripts.prerelease must be exactly npm ci so release uses the locked dependencies.');
|
|
204
197
|
requireThat(typeof scripts.release === 'string' && releaseCommand.test(scripts.release.trim()), 'package.json: scripts.release must invoke peacekeeper release publish directly.');
|
|
205
|
-
const testWorkflow = workflows.get(config.projectChecks.testWorkflow);
|
|
206
|
-
requireThat(testWorkflow && Object.values(testWorkflow.jobs).some((rawJob) => {
|
|
207
|
-
const job = rawJob;
|
|
208
|
-
const steps = job.steps || [];
|
|
209
|
-
const installed = steps.findIndex(step => directCommand(step, installCommand)
|
|
210
|
-
&& unconditional(step.if) && !step['continue-on-error']);
|
|
211
|
-
return unconditional(job.if) && !job['continue-on-error'] && installed >= 0
|
|
212
|
-
&& steps.some((step, index) => index > installed && unconditional(step.if)
|
|
213
|
-
&& !step['continue-on-error'] && commands(step.run).some(command => /^npm (?:pack(?: --dry-run(?: --json)?)?|run test:package)$/u.test(command)));
|
|
214
|
-
}), 'Add an unconditional npm pack or npm run test:package CI check after npm ci in projectChecks.testWorkflow for published packages.');
|
|
215
198
|
}
|
|
216
199
|
else {
|
|
217
200
|
for (const field of ['publishConfig', 'files'])
|
|
@@ -221,6 +204,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
221
204
|
for (const [file, workflow] of workflows)
|
|
222
205
|
for (const [id, rawJob] of Object.entries(workflow.jobs)) {
|
|
223
206
|
const job = rawJob;
|
|
207
|
+
requireThat(!(typeof job.uses === 'string' && job.uses.startsWith(`${reusableWorkflow('publish').workflow}@`)), `${file}/${id}: remove npm publication steps when publishesToNpm=false.`);
|
|
224
208
|
for (const step of job.steps || [])
|
|
225
209
|
requireThat(!publicationCommand(step.run)
|
|
226
210
|
&& !/npm-publish/iu.test(step.uses || ''), `${file}/${id}: remove npm publication steps when publishesToNpm=false.`);
|
|
@@ -250,7 +234,8 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
250
234
|
if (!requireThat(job && typeof job === 'object', `${filename}/${id}: required job is missing; checks for this job are blocked.`))
|
|
251
235
|
return;
|
|
252
236
|
requireThat(unconditional(job.if) || job.if === "${{ github.event_name == 'pull_request' }}", `${filename}/${id}: required PR job must not be skipped by an if condition.`);
|
|
253
|
-
requireThat(!job['continue-on-error']
|
|
237
|
+
requireThat(!job['continue-on-error'], `${filename}/${id}: required jobs must not allow failure.`);
|
|
238
|
+
requireThat(!job.uses || centralJobs.has(job), `${filename}/${id}: required jobs must have verifiable local steps or use the approved reusable PR workflow.`);
|
|
254
239
|
if (checked.has(id))
|
|
255
240
|
return;
|
|
256
241
|
checked.add(id);
|
|
@@ -259,6 +244,11 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
259
244
|
requiredJob(dependency, jobs[dependency], false);
|
|
260
245
|
if (!testsRequired)
|
|
261
246
|
return;
|
|
247
|
+
if (job.uses) {
|
|
248
|
+
if (centralJobs.has(job) && config.git.releaseRequiredChecks.includes(checkName(id, job)))
|
|
249
|
+
policyJobs += 1;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
262
252
|
const steps = job.steps || [];
|
|
263
253
|
const installed = steps.findIndex(step => directCommand(step, installCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
264
254
|
const tested = steps.findIndex(step => directCommand(step, testCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
@@ -270,7 +260,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
270
260
|
}
|
|
271
261
|
for (const name of required) {
|
|
272
262
|
const matching = Object.entries(jobs)
|
|
273
|
-
.filter(([id, job]) => (job
|
|
263
|
+
.filter(([id, job]) => checkName(id, job) === name);
|
|
274
264
|
if (!requireThat(matching.length === 1 && !name.includes('${{'), `${filename}: required job ${name} must have a unique static name. Match a job name (or ID when name is absent); checks for this job are blocked.`))
|
|
275
265
|
continue;
|
|
276
266
|
// Validate the test steps even if this job was visited as a dependency.
|
|
@@ -298,6 +288,9 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
298
288
|
if (!workflow)
|
|
299
289
|
throw new Error(`${publishing.path}: selected publish workflow was not loaded.`);
|
|
300
290
|
const job = workflow.jobs.publish;
|
|
291
|
+
// inspectWorkflow already validates approved reusable publication callers.
|
|
292
|
+
if (job.uses)
|
|
293
|
+
return;
|
|
301
294
|
const steps = job.steps || [];
|
|
302
295
|
requireThat(!job['continue-on-error'], `${publishing.path}: publication must not allow failure.`);
|
|
303
296
|
const installed = steps.findIndex(step => directCommand(step, installCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
@@ -329,7 +322,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
329
322
|
runtime.exitCode = 1;
|
|
330
323
|
}
|
|
331
324
|
else
|
|
332
|
-
output.log(`Project checks passed: package, tools,
|
|
325
|
+
output.log(`Project checks passed: package, tools, Codex configuration, CI${published ? ', publication' : ' (publishesToNpm=false; publication skipped)'}.`);
|
|
333
326
|
}
|
|
334
327
|
function run(options = {}) {
|
|
335
328
|
try {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export default ({
|
|
2
|
-
const { planHooks } = installHooks;
|
|
1
|
+
export default ({ releases, external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, YAML, } }) => {
|
|
3
2
|
const TOOLCHAIN = Object.freeze({
|
|
4
3
|
node: '22.14.0',
|
|
5
4
|
npm: '11.21.0',
|
|
@@ -62,11 +61,17 @@ export default ({ installHooks, external: { fs, modulesRoot, packageVersion, pat
|
|
|
62
61
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
63
62
|
fs.writeFileSync(target, contents, { mode });
|
|
64
63
|
}
|
|
65
|
-
function workflow(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
function workflow(kind) {
|
|
65
|
+
const definition = releases.reusableWorkflow(kind);
|
|
66
|
+
const id = kind === 'pr' ? 'test' : 'publish';
|
|
67
|
+
return YAML.stringify({
|
|
68
|
+
on: kind === 'pr' ? { pull_request: { branches: ['main'] } } : { push: { tags: ['v*'] } },
|
|
69
|
+
permissions: { contents: 'read', ...(kind === 'publish' ? { 'id-token': 'write' } : {}) },
|
|
70
|
+
jobs: { [id]: {
|
|
71
|
+
uses: `${definition.workflow}@${definition.refs.at(-1)}`,
|
|
72
|
+
secrets: { RELEASE_POLICY_TOKEN: '${{ secrets.RELEASE_POLICY_TOKEN }}' },
|
|
73
|
+
} },
|
|
74
|
+
}, { lineWidth: 0 });
|
|
70
75
|
}
|
|
71
76
|
function renderTemplate(filename, replacements) {
|
|
72
77
|
let template = fs.readFileSync(path.join(modulesRoot, `projects/${filename}`), 'utf8');
|
|
@@ -125,16 +130,15 @@ export default ({ installHooks, external: { fs, modulesRoot, packageVersion, pat
|
|
|
125
130
|
const defaults = JSON.parse(JSON.stringify(projectConfigDefaults));
|
|
126
131
|
defaults.publishesToNpm = options.published;
|
|
127
132
|
defaults.git.requiredApprover = options.owner;
|
|
133
|
+
defaults.git.releaseRequiredChecks = ['test / test'];
|
|
134
|
+
defaults.projectChecks.requiredJobs = ['test / test'];
|
|
128
135
|
defaults.tests.all = ['npm run typecheck', 'npm run build', 'npm run test:unit', ...(options.published ? ['npm run test:package'] : [])];
|
|
129
136
|
defaults.tests.npmTestUsesRunner = true;
|
|
130
137
|
write(root, 'peacekeeper.config.yaml', YAML.stringify(defaults, { lineWidth: 0 }));
|
|
131
|
-
write(root, '.
|
|
132
|
-
const prefix = fs.readFileSync(path.join(modulesRoot, 'projects/codex-setup-prefix.sh'), 'utf8');
|
|
133
|
-
write(root, '.codex/environments/environment.toml', `version = 1\nname = ${JSON.stringify(options.repositoryName)}\n\n[setup]\nscript = '''\n${prefix}'''\n`);
|
|
134
|
-
write(root, '.github/workflows/test.yml', workflow(options.published));
|
|
138
|
+
write(root, '.github/workflows/test.yml', workflow('pr'));
|
|
135
139
|
write(root, '.github/CODEOWNERS', `* @${options.owner}\n`);
|
|
136
140
|
if (options.published)
|
|
137
|
-
write(root, '.github/workflows/publish.yml',
|
|
141
|
+
write(root, '.github/workflows/publish.yml', workflow('publish'));
|
|
138
142
|
write(root, '.gitignore', 'node_modules/\n*.tgz\ntmp/\n');
|
|
139
143
|
write(root, 'README.md', `# ${options.repositoryName}\n\nA TypeScript library generated by Peacekeeper.\n\n## API\n\n\`hello()\` returns \`"hello world"\`.\n`);
|
|
140
144
|
write(root, 'LICENSE', `MIT License\n\nCopyright (c) ${options.authorName}\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n`);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
export const porticoFacade = ({ assessRelease, configureGithub, githubConfiguration, githubPolicy, release, releaseCore, verifyRelease, verifyReleaseProtection, verifyReleaseVersion }) => ({
|
|
1
|
+
export const porticoFacade = ({ assessRelease, configureGithub, githubConfiguration, githubPolicy, release, releaseCore, reusableWorkflows, verifyRelease, verifyReleaseProtection, verifyReleaseVersion }) => ({
|
|
2
2
|
assessRelease: assessRelease.run,
|
|
3
3
|
configureGithub: configureGithub.run,
|
|
4
4
|
planGithub: githubConfiguration.plan,
|
|
5
5
|
createGithubPolicy: githubPolicy.createGithubPolicy,
|
|
6
6
|
ensureLockfilesMatch: releaseCore.ensureLockfilesMatch,
|
|
7
7
|
inspectWorkflow: releaseCore.inspectWorkflow,
|
|
8
|
+
reusableWorkflow: reusableWorkflows.definition,
|
|
9
|
+
reusableWorkflowErrors: reusableWorkflows.callErrors,
|
|
8
10
|
release: release.run,
|
|
9
11
|
verifyRelease: verifyRelease.run,
|
|
10
12
|
verifyReleaseProtection: verifyReleaseProtection.run,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default ({ configuration, releaseProtection, external: { clock, fs, os, path, runtime, url: Url, YAML: yaml, } }) => {
|
|
1
|
+
export default ({ configuration, releaseProtection, reusableWorkflows, 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') }}";
|
|
@@ -145,18 +145,27 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
|
|
|
145
145
|
}
|
|
146
146
|
if (!document?.jobs || !Object.hasOwn(document.jobs, 'publish'))
|
|
147
147
|
continue;
|
|
148
|
+
// A pure workflow_call definition is a library, not a tag-triggered entrypoint.
|
|
149
|
+
if (document.on && typeof document.on === 'object' && !Array.isArray(document.on)
|
|
150
|
+
&& Object.keys(document.on).length === 1 && Object.hasOwn(document.on, 'workflow_call'))
|
|
151
|
+
continue;
|
|
148
152
|
const job = document.jobs.publish;
|
|
149
153
|
if (!job || (job.if !== requiredCondition && (Object.hasOwn(job, 'if') || !onlyReleaseTagPushes(document.on)))) {
|
|
150
154
|
throw new ReleaseError(`${relativePath}: publish job needs the exact required if condition unless the workflow only triggers on v-prefixed tag pushes.`);
|
|
151
155
|
}
|
|
152
|
-
if (
|
|
156
|
+
if (job.uses) {
|
|
157
|
+
const errors = reusableWorkflows.callErrors('publish', job, document.permissions);
|
|
158
|
+
if (errors.length)
|
|
159
|
+
throw new ReleaseError(`${relativePath}/publish: ${errors.join(' ')}`);
|
|
160
|
+
}
|
|
161
|
+
else if (!Array.isArray(job.steps) || !job.steps.some((step) => step?.run === 'npm publish')) {
|
|
153
162
|
throw new ReleaseError(`${relativePath}: publish job needs a step whose run is exactly npm publish.`);
|
|
154
163
|
}
|
|
155
164
|
const name = job.name || 'publish';
|
|
156
165
|
if (typeof name !== 'string' || name.includes('${{')) {
|
|
157
166
|
throw new ReleaseError(`${relativePath}: publish job needs a static display name.`);
|
|
158
167
|
}
|
|
159
|
-
matches.push({ path: relativePath, name, on: document.on });
|
|
168
|
+
matches.push({ path: relativePath, name: job.uses ? `${name} / ${reusableWorkflows.definition('publish').jobName}` : name, on: document.on });
|
|
160
169
|
}
|
|
161
170
|
if (matches.length !== 1) {
|
|
162
171
|
throw new ReleaseError(`Expected exactly one publish job; found ${matches.length}.`);
|
|
@@ -363,6 +372,8 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
|
|
|
363
372
|
return github(exec, cwd, details.host, `repos/${details.slug}/pulls/${details.pr}`, {});
|
|
364
373
|
}
|
|
365
374
|
async function mergeRelease(exec, cwd, details, now, sleep, log) {
|
|
375
|
+
if (details.mergeMethod && details.mergeMethod !== 'merge')
|
|
376
|
+
throw new ReleaseError('Release must use merge commits on the default branch; restart this release.');
|
|
366
377
|
const deadline = now() + workflowTimeoutMs;
|
|
367
378
|
while (now() < deadline) {
|
|
368
379
|
const pr = pullRequest(exec, cwd, details);
|
|
@@ -376,19 +387,18 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
|
|
|
376
387
|
throw new ReleaseError(`Release PR #${details.pr} has conflicts; inspect it before continuing.`);
|
|
377
388
|
verifyProtection({ api: githubApi(exec, cwd, details.host), slug: details.slug,
|
|
378
389
|
branch: details.defaultBranch, ...requiredPolicy(cwd) });
|
|
379
|
-
if (
|
|
380
|
-
throw new ReleaseError('Release must use merge commits
|
|
381
|
-
// GitHub enforces required checks, reviews, and branch freshness on this request.
|
|
382
|
-
const result = exec('gh', ['api', '--hostname', details.host, '--method', 'PUT',
|
|
383
|
-
`repos/${details.slug}/pulls/${details.pr}/merge`,
|
|
384
|
-
'-f', `merge_method=${details.mergeMethod || 'merge'}`, '-f', `sha=${details.sha}`], { cwd });
|
|
385
|
-
if (result.status === 0) {
|
|
386
|
-
const merged = JSON.parse(result.stdout);
|
|
387
|
-
if (merged.merged)
|
|
388
|
-
return merged.sha;
|
|
390
|
+
if (pr.auto_merge && pr.auto_merge.merge_method !== 'merge') {
|
|
391
|
+
throw new ReleaseError('Release PR auto-merge must use merge commits.');
|
|
389
392
|
}
|
|
390
|
-
|
|
391
|
-
|
|
393
|
+
if (!pr.auto_merge) {
|
|
394
|
+
if (typeof pr.node_id !== 'string' || !pr.node_id)
|
|
395
|
+
throw new ReleaseError('GitHub did not provide the release PR node ID.');
|
|
396
|
+
// Enable auto-merge; GitHub applies all required reviews, checks and freshness gates.
|
|
397
|
+
checked(exec, 'gh', ['api', '--hostname', details.host, '--method', 'POST', 'graphql',
|
|
398
|
+
'-f', 'query=mutation($pullRequestId: ID!, $expectedHeadOid: GitObjectID!) { enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, expectedHeadOid: $expectedHeadOid, mergeMethod: MERGE}) { pullRequest { id } } }',
|
|
399
|
+
'-f', `pullRequestId=${pr.node_id}`, '-f', `expectedHeadOid=${details.sha}`], cwd);
|
|
400
|
+
log(`Enabled auto-merge for release PR #${details.pr}.`);
|
|
401
|
+
continue;
|
|
392
402
|
}
|
|
393
403
|
log(`Waiting for release PR #${details.pr} to satisfy merge requirements.`);
|
|
394
404
|
await sleep(pollIntervalMs);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ external: { fs, modulesRoot, path } }) => {
|
|
3
|
+
const definitions = JSON.parse(fs.readFileSync(path.join(modulesRoot, 'releases/reusable-workflows.json'), 'utf8'));
|
|
4
|
+
function definition(kind) {
|
|
5
|
+
return definitions[kind];
|
|
6
|
+
}
|
|
7
|
+
function callErrors(kind, job, workflowPermissions) {
|
|
8
|
+
const policy = definition(kind);
|
|
9
|
+
const errors = [];
|
|
10
|
+
if (!policy.refs.some(ref => job.uses === `${policy.workflow}@${ref}`)) {
|
|
11
|
+
errors.push(`Use an approved reusable ${kind} workflow SHA: ${policy.refs.map(ref => `${policy.workflow}@${ref}`).join(', ')}.`);
|
|
12
|
+
}
|
|
13
|
+
if (!Object.keys(job).every(key => ['name', 'uses', 'secrets', 'permissions', 'if', 'needs', 'concurrency', 'with'].includes(key))) {
|
|
14
|
+
errors.push('The reusable job cannot override steps, runner, strategy, environment, or failure handling.');
|
|
15
|
+
}
|
|
16
|
+
if (job.name !== undefined && (typeof job.name !== 'string' || !job.name.trim() || job.name.includes('${{'))) {
|
|
17
|
+
errors.push('The reusable job must have a static display name.');
|
|
18
|
+
}
|
|
19
|
+
if (job.with !== undefined && (!job.with || typeof job.with !== 'object' || Array.isArray(job.with) || Object.keys(job.with).length)) {
|
|
20
|
+
errors.push('The reusable workflow accepts no inputs; put project-specific checks in tests.all.');
|
|
21
|
+
}
|
|
22
|
+
const secrets = job.secrets;
|
|
23
|
+
if (!secrets || typeof secrets !== 'object' || Array.isArray(secrets)
|
|
24
|
+
|| Object.keys(secrets).length !== 1 || typeof secrets.RELEASE_POLICY_TOKEN !== 'string'
|
|
25
|
+
|| !/^\$\{\{\s*secrets\.[A-Za-z_][A-Za-z0-9_]*\s*\}\}$/u.test(secrets.RELEASE_POLICY_TOKEN)) {
|
|
26
|
+
errors.push('Pass RELEASE_POLICY_TOKEN explicitly from a repository secret; secrets: inherit is not supported.');
|
|
27
|
+
}
|
|
28
|
+
const permissions = (job.permissions === undefined ? workflowPermissions : job.permissions);
|
|
29
|
+
if (!permissions || !['read', 'write'].includes(permissions.contents)) {
|
|
30
|
+
errors.push('Declare contents: read for the reusable workflow (job or workflow permissions).');
|
|
31
|
+
}
|
|
32
|
+
if (kind === 'publish' && permissions?.['id-token'] !== 'write') {
|
|
33
|
+
errors.push('Declare id-token: write in the caller for OIDC publication.');
|
|
34
|
+
}
|
|
35
|
+
return errors;
|
|
36
|
+
}
|
|
37
|
+
return { definition, callErrors };
|
|
38
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pr": {
|
|
3
|
+
"workflow": "jakobmattsson/peacekeeper/.github/workflows/reusable-pr.yml",
|
|
4
|
+
"refs": [
|
|
5
|
+
"17a6c202c0f3cd66f1bb4a42d1dc8c78e7eb60d6"
|
|
6
|
+
],
|
|
7
|
+
"jobName": "test"
|
|
8
|
+
},
|
|
9
|
+
"publish": {
|
|
10
|
+
"workflow": "jakobmattsson/peacekeeper/.github/workflows/reusable-publish.yml",
|
|
11
|
+
"refs": [
|
|
12
|
+
"a438e3d706a1812fea72dc0858378566f4e3bb21"
|
|
13
|
+
],
|
|
14
|
+
"jobName": "publish"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export const porticoFacade = ({ checkConventions, checkTestReceipt, recordTestReceipt, runTests }) => ({
|
|
1
|
+
export const porticoFacade = ({ prepareTests, checkConventions, checkTestReceipt, recordTestReceipt, runTests }) => ({
|
|
2
|
+
prepareTests: prepareTests.run,
|
|
2
3
|
checkConventions: checkConventions.run,
|
|
3
4
|
checkTestReceipt: checkTestReceipt.run,
|
|
4
5
|
recordTestReceipt: recordTestReceipt.run,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// --- Implementation ---
|
|
2
|
+
export default ({ configuration, external: { output, runtime, spawnSync } }) => {
|
|
3
|
+
function prepare() {
|
|
4
|
+
const { tests, root } = configuration.projectConfig();
|
|
5
|
+
function run(command, args) {
|
|
6
|
+
const result = spawnSync(command, args, { cwd: root, stdio: 'inherit' });
|
|
7
|
+
if (result.error)
|
|
8
|
+
throw result.error;
|
|
9
|
+
if (result.status !== 0)
|
|
10
|
+
throw new Error(`CI command failed (${result.status ?? result.signal}): ${command}`);
|
|
11
|
+
}
|
|
12
|
+
if (tests.aptPackages.length) {
|
|
13
|
+
if (runtime.platform !== 'linux')
|
|
14
|
+
throw new Error('tests.aptPackages requires a Linux environment with apt-get.');
|
|
15
|
+
run('sudo', ['apt-get', 'update']);
|
|
16
|
+
run('sudo', ['apt-get', 'install', '--yes', '--no-install-recommends', '--', ...tests.aptPackages]);
|
|
17
|
+
}
|
|
18
|
+
if (tests.playwrightBrowsers.length) {
|
|
19
|
+
run('npm', ['exec', '--no', '--', 'playwright', 'install', '--with-deps', ...tests.playwrightBrowsers]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
run: () => {
|
|
24
|
+
try {
|
|
25
|
+
prepare();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
output.error(error instanceof Error ? error.message : String(error));
|
|
29
|
+
runtime.exitCode = 1;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakobm/peacekeeper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Shared repository test, Git worktree, and Codex hook commands",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakob Mattsson",
|
|
@@ -40,7 +40,6 @@
|
|
|
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 codex init-worktree --sync-primary
|
|
23
|
-
npm exec --no -- peacekeeper cleanup merged-branches --execute
|
|
24
|
-
|
|
25
|
-
# Add custom project setup below
|