@jakobm/peacekeeper 0.28.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 +136 -14
- package/dist/cmdabra.yaml +3 -1
- package/dist/package.json +1 -1
- 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/projects/check-project-requirements.txt +60 -9
- package/dist/src/modules/projects/check-project.js +32 -13
- package/dist/src/modules/projects/create-project-core.js +16 -8
- 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 -1
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` |
|
|
@@ -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
|
|
@@ -744,12 +865,12 @@ With `true`, declare a publishable package (`private` absent or `false`), a vali
|
|
|
744
865
|
npm name, stable version, description, license, nonempty `files` list, and
|
|
745
866
|
`publishConfig` with registry `https://registry.npmjs.org/` and explicit access
|
|
746
867
|
`public` or `restricted`. Add a direct `peacekeeper release publish` package script
|
|
747
|
-
(the npm-exec and local Node CLI forms are also supported)
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
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.
|
|
753
874
|
|
|
754
875
|
With `false`, set `package.json.private` to `true` and remove `publishConfig`,
|
|
755
876
|
`files`, npm publication/release scripts, and npm publication workflow steps.
|
|
@@ -881,14 +1002,14 @@ with direct publishing enabled. Confirm npm publish access to the `@jakobm`
|
|
|
881
1002
|
scope separately from GitHub repository access. The workflow verifies
|
|
882
1003
|
the release and publishes via OIDC. It needs no npm access token.
|
|
883
1004
|
|
|
884
|
-
`test.yml`
|
|
1005
|
+
`test.yml` calls the central PR workflow, producing `test / test`. `package.yml` calls the central publication workflow and runs
|
|
885
1006
|
on `v*` tags and only verifies and publishes. Merging to `main` does not start
|
|
886
1007
|
another run.
|
|
887
1008
|
|
|
888
1009
|
Release verification uses GitHub's enforced branch policy instead of retaining
|
|
889
1010
|
artifacts of tested contents. Configure `git.releaseRequiredChecks` in the root
|
|
890
1011
|
`peacekeeper.config.yaml` with the exact CI job names required for a release
|
|
891
|
-
(for this repository: `["test
|
|
1012
|
+
(for this repository: `["test / test"]`). These checks must be mandatory
|
|
892
1013
|
with **Require branches to be up to date before merging** enabled. Classic branch
|
|
893
1014
|
protection may provide the base PR and check requirements. Active base rulesets
|
|
894
1015
|
may provide them instead. Merge
|
|
@@ -914,13 +1035,14 @@ Required linear history and any applicable PR rule excluding merge commits fail
|
|
|
914
1035
|
verification. Bypass actors for base PR and strict-check rules require manual
|
|
915
1036
|
inspection only when GitHub omits them from its response.
|
|
916
1037
|
Enable `allow_auto_merge` in repository settings: this permits opting in per PR;
|
|
917
|
-
|
|
1038
|
+
the release command enables auto-merge on its release PRs.
|
|
918
1039
|
|
|
919
1040
|
`project check` makes no network requests. It runs implicitly before
|
|
920
1041
|
`tests.all` or `tests.checkpoint`, including when reusing receipts, and checks that the configured
|
|
921
1042
|
PR workflow uses only `pull_request`, with `branches` set to exactly
|
|
922
1043
|
`[git.defaultBranch]`, and runs `release verify-protection` with `GH_TOKEN` after `npm ci` and
|
|
923
|
-
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
|
|
924
1046
|
not skip verification or ignore failures. The online verifier then checks that
|
|
925
1047
|
exactly those configured check names are mandatory on GitHub, including its own
|
|
926
1048
|
job; missing and additional checks are both configuration drift.
|
|
@@ -1023,9 +1145,9 @@ increment the package and lockfile versions. Your current branch and local defau
|
|
|
1023
1145
|
branch stay unchanged, including when the default branch is checked out elsewhere.
|
|
1024
1146
|
Before changing versions it logs `Preparing release from origin/<branch> at <SHA>.`
|
|
1025
1147
|
using the full source commit ID checked out in the temporary worktree.
|
|
1026
|
-
It pushes a `release/v<version>` branch and opens a release PR. The
|
|
1027
|
-
|
|
1028
|
-
|
|
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,
|
|
1029
1151
|
respecting required checks, reviews, resolved conversations, and branch freshness.
|
|
1030
1152
|
It never uses an administrator bypass or pushes directly to the default branch.
|
|
1031
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
|
@@ -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) {
|
|
@@ -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
|
|
@@ -107,13 +108,15 @@ Required PR workflow and jobs
|
|
|
107
108
|
in separate workflows.
|
|
108
109
|
|
|
109
110
|
Each required name must match exactly one static job display name (name), or
|
|
110
|
-
the job ID if name is absent.
|
|
111
|
-
|
|
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
|
|
112
115
|
not allow failure, and must not have conditions that skip required PR checks.
|
|
113
116
|
Accepted job conditions are absent, success(), ${{ success() }}, or exactly:
|
|
114
117
|
${{ github.event_name == 'pull_request' }}
|
|
115
118
|
|
|
116
|
-
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
|
|
117
120
|
supported validation command, with neither step allowed to fail. Commands
|
|
118
121
|
must be direct run steps, exactly one of:
|
|
119
122
|
npm test
|
|
@@ -121,11 +124,59 @@ Required PR workflow and jobs
|
|
|
121
124
|
npm run test:<name> (name contains letters, digits, _ or -)
|
|
122
125
|
npm pack --dry-run
|
|
123
126
|
npm pack --dry-run --json
|
|
124
|
-
Shell wrappers, combined commands, and reusable workflows cannot establish
|
|
127
|
+
Shell wrappers, combined commands, and unapproved reusable workflows cannot establish
|
|
125
128
|
these requirements. Conditional reporting steps after tests are allowed.
|
|
126
129
|
An unconditional step either omits if or sets it to success() or
|
|
127
130
|
${{ success() }}.
|
|
128
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
|
+
|
|
129
180
|
Matrix example: tests on three platforms and one static required gate:
|
|
130
181
|
jobs:
|
|
131
182
|
matrix-tests:
|
|
@@ -212,9 +263,8 @@ Publication: publishesToNpm=true
|
|
|
212
263
|
directly invoke peacekeeper release publish (also supported: npm exec --no --
|
|
213
264
|
peacekeeper release publish or the local Node CLI forms). Run releases through
|
|
214
265
|
npm run release so npm does not bypass the prerelease installation.
|
|
215
|
-
|
|
216
|
-
npm
|
|
217
|
-
--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.
|
|
218
268
|
npm script aliases are resolved without executing them. Package installation
|
|
219
269
|
tests using a temporary consumer are recommended; script names do not prove
|
|
220
270
|
assertion coverage. npm publish must not be conditional or allowed to fail.
|
|
@@ -382,7 +432,8 @@ Using this check in the test chain
|
|
|
382
432
|
existing receipt. This check remains entirely local.
|
|
383
433
|
|
|
384
434
|
Default-branch GitHub policy chain
|
|
385
|
-
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
|
|
386
437
|
after npm ci and before tests in at least one job in git.releaseRequiredChecks.
|
|
387
438
|
Verification must be unconditional and must not allow failure. The existing
|
|
388
439
|
required-job validation applies to that job and its dependencies.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// --- Implementation ---
|
|
1
2
|
export default ({ configuration, releases, external: { fs, modulesRoot, output, path, runtime, semver, YAML, } }) => {
|
|
2
3
|
const { projectConfig } = configuration;
|
|
3
|
-
const { inspectWorkflow, ensureLockfilesMatch } = releases;
|
|
4
|
+
const { inspectWorkflow, ensureLockfilesMatch, reusableWorkflow, reusableWorkflowErrors } = releases;
|
|
4
5
|
function read(root, file, parse = JSON.parse) {
|
|
5
6
|
try {
|
|
6
7
|
return parse(fs.readFileSync(path.join(root, file), 'utf8'));
|
|
@@ -18,6 +19,11 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
18
19
|
const testCommand = /^npm (?:test|run test(?::[\w-]+)?|pack --dry-run(?: --json)?)$/u;
|
|
19
20
|
const installCommand = /^npm ci$/u;
|
|
20
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
|
+
}
|
|
21
27
|
function checkProject(cwd = runtime.cwd()) {
|
|
22
28
|
const config = projectConfig(cwd);
|
|
23
29
|
const root = config.root;
|
|
@@ -144,6 +150,19 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
144
150
|
});
|
|
145
151
|
}
|
|
146
152
|
}
|
|
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
|
+
continue;
|
|
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);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
147
166
|
check('Codex configuration', () => {
|
|
148
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.');
|
|
149
168
|
});
|
|
@@ -176,16 +195,6 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
176
195
|
requireThat(Array.isArray(manifest.files) && manifest.files.length > 0 && manifest.files.every(nonblank), 'package.json: published packages require a nonempty files list.');
|
|
177
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.');
|
|
178
197
|
requireThat(typeof scripts.release === 'string' && releaseCommand.test(scripts.release.trim()), 'package.json: scripts.release must invoke peacekeeper release publish directly.');
|
|
179
|
-
const testWorkflow = workflows.get(config.projectChecks.testWorkflow);
|
|
180
|
-
requireThat(testWorkflow && Object.values(testWorkflow.jobs).some((rawJob) => {
|
|
181
|
-
const job = rawJob;
|
|
182
|
-
const steps = job.steps || [];
|
|
183
|
-
const installed = steps.findIndex(step => directCommand(step, installCommand)
|
|
184
|
-
&& unconditional(step.if) && !step['continue-on-error']);
|
|
185
|
-
return unconditional(job.if) && !job['continue-on-error'] && installed >= 0
|
|
186
|
-
&& steps.some((step, index) => index > installed && unconditional(step.if)
|
|
187
|
-
&& !step['continue-on-error'] && commands(step.run).some(command => /^npm (?:pack(?: --dry-run(?: --json)?)?|run test:package)$/u.test(command)));
|
|
188
|
-
}), 'Add an unconditional npm pack or npm run test:package CI check after npm ci in projectChecks.testWorkflow for published packages.');
|
|
189
198
|
}
|
|
190
199
|
else {
|
|
191
200
|
for (const field of ['publishConfig', 'files'])
|
|
@@ -195,6 +204,7 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
195
204
|
for (const [file, workflow] of workflows)
|
|
196
205
|
for (const [id, rawJob] of Object.entries(workflow.jobs)) {
|
|
197
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.`);
|
|
198
208
|
for (const step of job.steps || [])
|
|
199
209
|
requireThat(!publicationCommand(step.run)
|
|
200
210
|
&& !/npm-publish/iu.test(step.uses || ''), `${file}/${id}: remove npm publication steps when publishesToNpm=false.`);
|
|
@@ -224,7 +234,8 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
224
234
|
if (!requireThat(job && typeof job === 'object', `${filename}/${id}: required job is missing; checks for this job are blocked.`))
|
|
225
235
|
return;
|
|
226
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.`);
|
|
227
|
-
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.`);
|
|
228
239
|
if (checked.has(id))
|
|
229
240
|
return;
|
|
230
241
|
checked.add(id);
|
|
@@ -233,6 +244,11 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
233
244
|
requiredJob(dependency, jobs[dependency], false);
|
|
234
245
|
if (!testsRequired)
|
|
235
246
|
return;
|
|
247
|
+
if (job.uses) {
|
|
248
|
+
if (centralJobs.has(job) && config.git.releaseRequiredChecks.includes(checkName(id, job)))
|
|
249
|
+
policyJobs += 1;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
236
252
|
const steps = job.steps || [];
|
|
237
253
|
const installed = steps.findIndex(step => directCommand(step, installCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
238
254
|
const tested = steps.findIndex(step => directCommand(step, testCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
@@ -244,7 +260,7 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
244
260
|
}
|
|
245
261
|
for (const name of required) {
|
|
246
262
|
const matching = Object.entries(jobs)
|
|
247
|
-
.filter(([id, job]) => (job
|
|
263
|
+
.filter(([id, job]) => checkName(id, job) === name);
|
|
248
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.`))
|
|
249
265
|
continue;
|
|
250
266
|
// Validate the test steps even if this job was visited as a dependency.
|
|
@@ -272,6 +288,9 @@ export default ({ configuration, releases, external: { fs, modulesRoot, output,
|
|
|
272
288
|
if (!workflow)
|
|
273
289
|
throw new Error(`${publishing.path}: selected publish workflow was not loaded.`);
|
|
274
290
|
const job = workflow.jobs.publish;
|
|
291
|
+
// inspectWorkflow already validates approved reusable publication callers.
|
|
292
|
+
if (job.uses)
|
|
293
|
+
return;
|
|
275
294
|
const steps = job.steps || [];
|
|
276
295
|
requireThat(!job['continue-on-error'], `${publishing.path}: publication must not allow failure.`);
|
|
277
296
|
const installed = steps.findIndex(step => directCommand(step, installCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default ({ external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, YAML, } }) => {
|
|
1
|
+
export default ({ releases, external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, YAML, } }) => {
|
|
2
2
|
const TOOLCHAIN = Object.freeze({
|
|
3
3
|
node: '22.14.0',
|
|
4
4
|
npm: '11.21.0',
|
|
@@ -61,11 +61,17 @@ export default ({ external: { fs, modulesRoot, packageVersion, path, projectConf
|
|
|
61
61
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
62
62
|
fs.writeFileSync(target, contents, { mode });
|
|
63
63
|
}
|
|
64
|
-
function workflow(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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 });
|
|
69
75
|
}
|
|
70
76
|
function renderTemplate(filename, replacements) {
|
|
71
77
|
let template = fs.readFileSync(path.join(modulesRoot, `projects/${filename}`), 'utf8');
|
|
@@ -124,13 +130,15 @@ export default ({ external: { fs, modulesRoot, packageVersion, path, projectConf
|
|
|
124
130
|
const defaults = JSON.parse(JSON.stringify(projectConfigDefaults));
|
|
125
131
|
defaults.publishesToNpm = options.published;
|
|
126
132
|
defaults.git.requiredApprover = options.owner;
|
|
133
|
+
defaults.git.releaseRequiredChecks = ['test / test'];
|
|
134
|
+
defaults.projectChecks.requiredJobs = ['test / test'];
|
|
127
135
|
defaults.tests.all = ['npm run typecheck', 'npm run build', 'npm run test:unit', ...(options.published ? ['npm run test:package'] : [])];
|
|
128
136
|
defaults.tests.npmTestUsesRunner = true;
|
|
129
137
|
write(root, 'peacekeeper.config.yaml', YAML.stringify(defaults, { lineWidth: 0 }));
|
|
130
|
-
write(root, '.github/workflows/test.yml', workflow(
|
|
138
|
+
write(root, '.github/workflows/test.yml', workflow('pr'));
|
|
131
139
|
write(root, '.github/CODEOWNERS', `* @${options.owner}\n`);
|
|
132
140
|
if (options.published)
|
|
133
|
-
write(root, '.github/workflows/publish.yml',
|
|
141
|
+
write(root, '.github/workflows/publish.yml', workflow('publish'));
|
|
134
142
|
write(root, '.gitignore', 'node_modules/\n*.tgz\ntmp/\n');
|
|
135
143
|
write(root, 'README.md', `# ${options.repositoryName}\n\nA TypeScript library generated by Peacekeeper.\n\n## API\n\n\`hello()\` returns \`"hello world"\`.\n`);
|
|
136
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
|
+
};
|