@jakobm/peacekeeper 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +307 -129
- package/dist/cmdabra.yaml +174 -116
- package/dist/package.json +5 -6
- package/dist/src/modules/cli/legacy-commands.js +37 -0
- package/dist/src/modules/cli/service.js +48 -40
- package/dist/src/modules/configuration/facade.js +1 -0
- package/dist/src/modules/configuration/project-config-defaults.json +2 -1
- package/dist/src/modules/configuration/project-config.js +20 -8
- package/dist/src/modules/configuration/update-config.js +16 -2
- package/dist/src/modules/dependencies.yaml +2 -2
- package/dist/src/modules/external.js +0 -2
- package/dist/src/modules/lifecycle/checkpoint-instructions.js +1 -1
- package/dist/src/modules/lifecycle/cleanup-ended-session.js +1 -1
- package/dist/src/modules/maintenance/cleanup-merged-branches.js +4 -4
- package/dist/src/modules/maintenance/initialize-codex-worktree.js +1 -1
- package/dist/src/modules/maintenance/remove-empty-directories.js +1 -1
- package/dist/src/modules/projects/check-project-requirements.txt +38 -57
- package/dist/src/modules/projects/check-project.js +19 -45
- package/dist/src/modules/projects/create-project-core.js +13 -32
- package/dist/src/modules/projects/generate-github-setup.js +16 -55
- package/dist/src/modules/projects/github-setup-prefix.sh +29 -2
- package/dist/src/modules/projects/github-setup-repository-template.sh +1 -40
- package/dist/src/modules/projects/github-setup-suffix-template.sh +7 -5
- package/dist/src/modules/projects/install-hooks.js +6 -5
- package/dist/src/modules/releases/configure-github.js +57 -0
- package/dist/src/modules/releases/facade.js +3 -2
- package/dist/src/modules/releases/github-configuration.js +166 -0
- package/dist/src/modules/releases/github-policy.js +45 -11
- package/dist/src/modules/releases/github-remote.js +230 -0
- package/dist/src/modules/testing/check-test-receipt.js +17 -22
- package/dist/src/modules/testing/receipt-state.js +27 -1
- package/dist/src/modules/testing/record-test-receipt.js +14 -13
- package/dist/src/modules/testing/run-tests.js +23 -14
- package/dist/src/modules/testing/types.js +1 -0
- package/package.json +5 -6
- package/dist/src/modules/projects/codex-setup-prefix.sh +0 -25
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Recommended usage:
|
|
7
7
|
*
|
|
8
|
-
* npm exec --no -- peacekeeper cleanup
|
|
9
|
-
* npm exec --no -- peacekeeper cleanup
|
|
10
|
-
* npm exec --no -- peacekeeper cleanup
|
|
8
|
+
* npm exec --no -- peacekeeper cleanup merged-branches # Dry-run (default).
|
|
9
|
+
* npm exec --no -- peacekeeper cleanup merged-branches --dry-run # Explicit dry-run.
|
|
10
|
+
* npm exec --no -- peacekeeper cleanup merged-branches --execute # Apply the displayed cleanup.
|
|
11
11
|
*
|
|
12
12
|
* Every run fetches the configured remote, including dry-runs, so the cleanup
|
|
13
13
|
* plan uses current remote references. Dry-run does not remove anything,
|
|
@@ -252,7 +252,7 @@ export default ({ configuration, external: { execFileSync, fs, output, path, run
|
|
|
252
252
|
if (!execute) {
|
|
253
253
|
log('');
|
|
254
254
|
log('To apply this cleanup, run:');
|
|
255
|
-
log(' npm exec --no -- peacekeeper cleanup
|
|
255
|
+
log(' npm exec --no -- peacekeeper cleanup merged-branches --execute');
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
function run({ execute = false } = {}) {
|
|
@@ -264,7 +264,7 @@ export default ({ configuration, external: { fs, output, path, runtime, spawnSyn
|
|
|
264
264
|
const root = git(cwd, 'rev-parse', '--show-toplevel');
|
|
265
265
|
const primaryRoot = primaryWorktree(root);
|
|
266
266
|
if (samePath(root, primaryRoot)) {
|
|
267
|
-
throw new Error('
|
|
267
|
+
throw new Error('codex init-worktree must run from a linked Git worktree');
|
|
268
268
|
}
|
|
269
269
|
const config = projectConfig(root);
|
|
270
270
|
let state = readState(root);
|
|
@@ -89,7 +89,7 @@ export default ({ external: { execFileSync, fs, output, path, runtime, } }) => {
|
|
|
89
89
|
log(`Would remove ${directory}`);
|
|
90
90
|
log('');
|
|
91
91
|
log('To remove these directories, run:');
|
|
92
|
-
log(' npm exec --no -- peacekeeper
|
|
92
|
+
log(' npm exec --no -- peacekeeper cleanup empty-directories --execute');
|
|
93
93
|
}
|
|
94
94
|
function main({ execute = false } = {}) {
|
|
95
95
|
try {
|
|
@@ -5,7 +5,7 @@ Purpose and scope
|
|
|
5
5
|
lifecycle hooks, and runs reproducible PR checks. Published npm packages also
|
|
6
6
|
verify a release before publishing the tested version.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
project check reads local files at the Git root. It makes no network requests,
|
|
9
9
|
runs no project scripts, and changes no files. Failure exits with status 1.
|
|
10
10
|
Independent failures are reported together. Missing or unreadable prerequisites
|
|
11
11
|
can block dependent checks; the reported failures are not an exhaustive list
|
|
@@ -16,9 +16,10 @@ 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
18
|
field, including nested fields; unknown fields and invalid values fail.
|
|
19
|
-
Run peacekeeper update-config to create or complete it without overwriting
|
|
20
|
-
existing values.
|
|
21
|
-
|
|
19
|
+
Run peacekeeper project update-config to create or complete it without overwriting
|
|
20
|
+
existing values. Migrate tests.commands to tests.all and add tests.checkpoint
|
|
21
|
+
as an empty list. Review inserted defaults. Empty tests.all blocks tests
|
|
22
|
+
and receipts. Help, --explain and project update-config bypass completeness checking.
|
|
22
23
|
|
|
23
24
|
projectChecks.testWorkflow selects the PR workflow filename.
|
|
24
25
|
projectChecks.requiredJobs selects required job names.
|
|
@@ -42,7 +43,7 @@ Project configuration
|
|
|
42
43
|
|
|
43
44
|
git.requiredApprover must identify the personal GitHub account that owns the
|
|
44
45
|
repository. Its bundled default is null so migrations must choose explicitly.
|
|
45
|
-
|
|
46
|
+
project check requires .github/CODEOWNERS to contain exactly one non-comment
|
|
46
47
|
rule matching that account:
|
|
47
48
|
* @OWNER
|
|
48
49
|
Additional ownership patterns or owners are rejected because GitHub accepts
|
|
@@ -77,33 +78,13 @@ Toolchain: package.json and all Node-based CI jobs
|
|
|
77
78
|
- run: npm ci
|
|
78
79
|
- run: npm test
|
|
79
80
|
|
|
80
|
-
Codex
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
If setup.linux, setup.macos or setup.windows overrides are present, their
|
|
88
|
-
script values must start with the same prefix to prevent bypassing setup.
|
|
89
|
-
|
|
90
|
-
Copy the reference into a TOML multiline literal string to preserve shell
|
|
91
|
-
backslashes. Preserve project-specific steps when replacing an older prefix.
|
|
92
|
-
The prefix requires Bash and curl, activates or installs Volta without editing
|
|
93
|
-
shell profiles, logs tool versions, runs npm ci using package.json pins, then
|
|
94
|
-
initializes the linked worktree and safely synchronizes the primary checkout.
|
|
95
|
-
Peacekeeper only reads this reference; it never executes the shell file or
|
|
96
|
-
the project's setup script. Passing validates declarations, not successful
|
|
97
|
-
provisioning, network access or availability of project-specific prerequisites.
|
|
98
|
-
Verify actual setup separately in a clean Codex worktree. New prefix versions
|
|
99
|
-
require updating consumer configurations.
|
|
100
|
-
|
|
101
|
-
Codex lifecycle hooks
|
|
102
|
-
.codex/hooks.json must contain the current peacekeeper hooks exactly once
|
|
103
|
-
for each lifecycle event, in their expected order, without group conditions.
|
|
104
|
-
Unrelated hooks are allowed. Repair with:
|
|
105
|
-
peacekeeper install-hooks
|
|
106
|
-
Hook installation does not itself grant Codex trust.
|
|
81
|
+
Codex configuration
|
|
82
|
+
The repository root must not contain .codex, including an empty directory,
|
|
83
|
+
file or symbolic link. Remove existing repository-local Codex configuration.
|
|
84
|
+
Preserve any needed setup outside the repository before removing it.
|
|
85
|
+
Project validation only reports the path; it does not delete or migrate files.
|
|
86
|
+
New projects do not generate .codex. The legacy codex install-hooks command
|
|
87
|
+
still creates .codex/hooks.json explicitly and therefore conflicts with this rule.
|
|
107
88
|
|
|
108
89
|
All GitHub Actions workflows
|
|
109
90
|
Every .yml/.yaml file under .github/workflows must parse and declare jobs.
|
|
@@ -172,7 +153,7 @@ Required PR workflow and jobs
|
|
|
172
153
|
GitHub check contexts and branch protection still need online verification.
|
|
173
154
|
|
|
174
155
|
If any matrix leg fails or is cancelled, the dependent test gate is normally
|
|
175
|
-
skipped, not failed.
|
|
156
|
+
skipped, not failed. release verify requires each configured release job to
|
|
176
157
|
conclude success, so a skipped gate blocks publication (even if the overall
|
|
177
158
|
workflow conclusion were success).
|
|
178
159
|
|
|
@@ -185,7 +166,7 @@ Required PR workflow and jobs
|
|
|
185
166
|
names in that setting. Alternatively, use separate static required jobs for
|
|
186
167
|
each platform and list all of them in git.releaseRequiredChecks. A gate using
|
|
187
168
|
always() to fail explicitly on failed dependencies is not currently accepted
|
|
188
|
-
by check
|
|
169
|
+
by project check's required-job condition rules.
|
|
189
170
|
|
|
190
171
|
Publication: publishesToNpm=true
|
|
191
172
|
package.json version must be exact and stable (no prerelease). Commit a
|
|
@@ -199,13 +180,13 @@ Publication: publishesToNpm=true
|
|
|
199
180
|
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
|
|
200
181
|
The publish job must not allow failure.
|
|
201
182
|
|
|
202
|
-
In publish steps, run unconditional npm ci, then unconditional verify
|
|
183
|
+
In publish steps, run unconditional npm ci, then unconditional release verify,
|
|
203
184
|
then npm publish. Neither install nor verification may allow failure.
|
|
204
185
|
Accepted direct verification commands:
|
|
205
|
-
peacekeeper verify
|
|
206
|
-
npm exec --no -- peacekeeper verify
|
|
207
|
-
node dist/bin/peacekeeper.js verify
|
|
208
|
-
node node_modules/@jakobm/peacekeeper/dist/bin/peacekeeper.js verify
|
|
186
|
+
peacekeeper release verify
|
|
187
|
+
npm exec --no -- peacekeeper release verify
|
|
188
|
+
node dist/bin/peacekeeper.js release verify
|
|
189
|
+
node node_modules/@jakobm/peacekeeper/dist/bin/peacekeeper.js release verify
|
|
209
190
|
The node paths may also start with ./.
|
|
210
191
|
|
|
211
192
|
Verification must receive these environment inputs, directly on the step or
|
|
@@ -218,9 +199,9 @@ Publication: publishesToNpm=true
|
|
|
218
199
|
contents: write is also accepted. The same toolchain rules apply to publishing.
|
|
219
200
|
|
|
220
201
|
Publication intent comes only from the mandatory boolean publishesToNpm.
|
|
221
|
-
Its bundled default is false. update-config inserts false even if existing
|
|
202
|
+
Its bundled default is false. project update-config inserts false even if existing
|
|
222
203
|
package metadata looks publishable; explicitly select true when migrating.
|
|
223
|
-
A missing field in an existing configuration fails check
|
|
204
|
+
A missing field in an existing configuration fails project check.
|
|
224
205
|
|
|
225
206
|
With true, package.json private must be absent or false. Require a valid npm
|
|
226
207
|
name, nonblank description and license, nonempty files list, and publishConfig
|
|
@@ -228,8 +209,8 @@ Publication: publishesToNpm=true
|
|
|
228
209
|
scripts.prerelease must be exactly npm ci. npm runs it before scripts.release,
|
|
229
210
|
so release starts with the dependency versions committed in the lockfile even
|
|
230
211
|
when node_modules was installed before the latest pull. scripts.release must
|
|
231
|
-
directly invoke peacekeeper release (also supported: npm exec --no --
|
|
232
|
-
peacekeeper release or the local Node CLI forms). Run releases through
|
|
212
|
+
directly invoke peacekeeper release publish (also supported: npm exec --no --
|
|
213
|
+
peacekeeper release publish or the local Node CLI forms). Run releases through
|
|
233
214
|
npm run release so npm does not bypass the prerelease installation.
|
|
234
215
|
The selected PR workflow must declare an unconditional packaging check after
|
|
235
216
|
npm ci: npm pack (optionally
|
|
@@ -241,19 +222,19 @@ Publication: publishesToNpm=true
|
|
|
241
222
|
authentication needed by private dependencies to the npm ci step.
|
|
242
223
|
|
|
243
224
|
With false, require private: true and reject publishConfig, files, npm
|
|
244
|
-
publication/release scripts,
|
|
225
|
+
publication/release scripts, release verify steps and npm-publish actions.
|
|
245
226
|
Scan command lists and npm script aliases; arbitrary shell wrappers, reusable
|
|
246
227
|
workflows and external scripts cannot be fully inspected. Remove dedicated
|
|
247
228
|
publishing credentials and npm trusted-publisher registration separately.
|
|
248
229
|
Internal packing, prepack/build scripts, main/exports/types/bin, deployment
|
|
249
230
|
workflows, OIDC for other services, and dependency read authentication remain
|
|
250
231
|
allowed. Workflow filenames and job names alone do not imply npm publication.
|
|
251
|
-
Toolchain, hooks, PR checks and verify-
|
|
232
|
+
Toolchain, hooks, PR checks and release verify-protection still apply.
|
|
252
233
|
|
|
253
234
|
Online release policy and GitHub token setup
|
|
254
|
-
These are online installation requirements;
|
|
255
|
-
local declarations above. Use verify-
|
|
256
|
-
policy and
|
|
235
|
+
These are online installation requirements; project check only verifies the
|
|
236
|
+
local declarations above. Use release verify-protection to check the branch
|
|
237
|
+
policy and release verify before publishing to check the release itself.
|
|
257
238
|
|
|
258
239
|
Enable "Automatically delete head branches" (delete_branch_on_merge=true) in
|
|
259
240
|
the repository settings. The online release policy commands require it.
|
|
@@ -298,8 +279,8 @@ Online release policy and GitHub token setup
|
|
|
298
279
|
Fork PRs do not receive repository secrets; do not expose this token by
|
|
299
280
|
running fork code with pull_request_target.
|
|
300
281
|
|
|
301
|
-
verify-
|
|
302
|
-
PR CI. It can be run before tests in a required trusted PR job. verify
|
|
282
|
+
release verify-protection uses GITHUB_BASE_REF, or git.defaultBranch outside
|
|
283
|
+
PR CI. It can be run before tests in a required trusted PR job. release verify
|
|
303
284
|
checks matching package/tag/lockfile versions, that the tagged commit belongs
|
|
304
285
|
to the default branch and is the merge commit of a same-repository merged
|
|
305
286
|
release/v<version> PR, and the latest selected PR workflow run and required
|
|
@@ -361,7 +342,7 @@ Complete npm trusted-publishing example with Volta
|
|
|
361
342
|
env:
|
|
362
343
|
GH_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
|
|
363
344
|
RELEASE_TAG: ${{ github.ref_name }}
|
|
364
|
-
run: npm exec --no -- peacekeeper verify
|
|
345
|
+
run: npm exec --no -- peacekeeper release verify
|
|
365
346
|
- run: npm publish
|
|
366
347
|
|
|
367
348
|
Volta selects the pinned tools and its registry-url input configures npm's
|
|
@@ -375,7 +356,7 @@ Complete npm trusted-publishing example with Volta
|
|
|
375
356
|
publishing does not authenticate dependency installation. Add any necessary
|
|
376
357
|
build step before publication, keeping npm publish as its own direct step.
|
|
377
358
|
|
|
378
|
-
|
|
359
|
+
project check verifies supported local workflow structure, not the npm OIDC
|
|
379
360
|
minimum versions, trusted-publisher registration, package visibility, registry
|
|
380
361
|
credentials, or actual publishing access. Verify those external settings too.
|
|
381
362
|
Upstream references for provider-specific setup and changing prerequisites:
|
|
@@ -389,19 +370,19 @@ What a passing check does and does not establish
|
|
|
389
370
|
installed dependency versions, or check Git remotes and ignored files.
|
|
390
371
|
It cannot confirm actual GitHub branch protection, token/secret access,
|
|
391
372
|
successful workflow runs, or npm trusted publisher configuration. Those need
|
|
392
|
-
online verification;
|
|
373
|
+
online verification; release verify handles the release checks it supports.
|
|
393
374
|
|
|
394
375
|
Using this check in the test chain
|
|
395
|
-
run
|
|
396
|
-
tests.
|
|
397
|
-
Explicit
|
|
376
|
+
test run always runs project check as an implicit first step before
|
|
377
|
+
tests.all or tests.checkpoint, including when command receipts skip execution.
|
|
378
|
+
Explicit project check invocations in either test list are rejected as redundant
|
|
398
379
|
because the runner always includes this step automatically. Supported direct
|
|
399
380
|
peacekeeper, npm exec, npx and node CLI forms are checked, including commands
|
|
400
381
|
separated by shell control operators. Failure stops the run and invalidates any
|
|
401
382
|
existing receipt. This check remains entirely local.
|
|
402
383
|
|
|
403
384
|
Default-branch GitHub policy chain
|
|
404
|
-
The configured PR workflow must run verify-
|
|
385
|
+
The configured PR workflow must run release verify-protection with step GH_TOKEN
|
|
405
386
|
after npm ci and before tests in at least one job in git.releaseRequiredChecks.
|
|
406
387
|
Verification must be unconditional and must not allow failure. The existing
|
|
407
388
|
required-job validation applies to that job and its dependencies.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export default ({ configuration,
|
|
1
|
+
export default ({ configuration, releases, external: { fs, modulesRoot, output, path, runtime, semver, YAML, } }) => {
|
|
2
2
|
const { projectConfig } = configuration;
|
|
3
|
-
const { planHooks, classifyCommand } = installHooks;
|
|
4
3
|
const { inspectWorkflow, ensureLockfilesMatch } = releases;
|
|
5
4
|
function read(root, file, parse = JSON.parse) {
|
|
6
5
|
try {
|
|
@@ -18,7 +17,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
18
17
|
}
|
|
19
18
|
const testCommand = /^npm (?:test|run test(?::[\w-]+)?|pack --dry-run(?: --json)?)$/u;
|
|
20
19
|
const installCommand = /^npm ci$/u;
|
|
21
|
-
const verifyCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) verify-release$/u;
|
|
20
|
+
const verifyCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) (?:release verify|verify-release)$/u;
|
|
22
21
|
function checkProject(cwd = runtime.cwd()) {
|
|
23
22
|
const config = projectConfig(cwd);
|
|
24
23
|
const root = config.root;
|
|
@@ -44,9 +43,11 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
44
43
|
}
|
|
45
44
|
};
|
|
46
45
|
check('tests', () => {
|
|
47
|
-
const projectCheck = /(?:^|&&|\|\||;|\n)\s*(?:peacekeeper|npm\s+exec\s+--no\s+--\s+peacekeeper|npx\s+--no-install\s+peacekeeper|node\s+(?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?bin\/peacekeeper\.js)\s+check-project(?=\s|$|;|&|\|)/u;
|
|
48
|
-
for (const [
|
|
49
|
-
|
|
46
|
+
const projectCheck = /(?:^|&&|\|\||;|\n)\s*(?:peacekeeper|npm\s+exec\s+--no\s+--\s+peacekeeper|npx\s+--no-install\s+peacekeeper|node\s+(?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js)\s+(?:project\s+check|check-project)(?=\s|$|;|&|\|)/u;
|
|
47
|
+
for (const level of ['all', 'checkpoint']) {
|
|
48
|
+
for (const [index, command] of config.tests[level].entries()) {
|
|
49
|
+
requireThat(!projectCheck.test(command), `tests.${level}[${index}]: remove project check; it is redundant because Peacekeeper always includes it automatically before the configured test commands, even when reusing a test receipt.`);
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
});
|
|
52
53
|
check('package', () => {
|
|
@@ -60,10 +61,8 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
60
61
|
if (typeof approver !== 'string')
|
|
61
62
|
return;
|
|
62
63
|
const file = '.github/CODEOWNERS';
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
.filter(line => line && !line.startsWith('#'));
|
|
66
|
-
requireThat(isDeepStrictEqual(lines, [`* @${approver}`]), `${file}: use exactly one ownership rule, "* @${approver}", so only git.requiredApprover can satisfy required code-owner review.`);
|
|
64
|
+
const error = configuration.codeownersError(read(root, file, value => value), approver);
|
|
65
|
+
requireThat(!error, error || '');
|
|
67
66
|
});
|
|
68
67
|
const workflows = new Map();
|
|
69
68
|
check('CI', () => {
|
|
@@ -145,39 +144,14 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
145
144
|
});
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
|
-
check('
|
|
149
|
-
|
|
150
|
-
const document = read(root, file, TOML.parse);
|
|
151
|
-
requireThat(document.version === 1, `${file}: version must be 1.`);
|
|
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))
|
|
157
|
-
continue;
|
|
158
|
-
const script = document.setup[platform]?.script;
|
|
159
|
-
requireThat(typeof script === 'string' && script.startsWith(prefix), `${file}: setup.${platform}.script must start with the same required setup prefix.\n${prefix}`);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
check('hooks', () => {
|
|
163
|
-
const document = read(root, '.codex/hooks.json');
|
|
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;
|
|
172
|
-
});
|
|
173
|
-
requireThat(isDeepStrictEqual(owned(document.hooks?.[event] || []), owned(expected.hooks[event] || [])), `.codex/hooks.json: missing, duplicate or outdated ${event} lifecycle hooks; run peacekeeper install-hooks.`);
|
|
174
|
-
}
|
|
147
|
+
check('Codex configuration', () => {
|
|
148
|
+
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
149
|
});
|
|
176
150
|
const published = config.publishesToNpm;
|
|
177
151
|
check('publication', () => {
|
|
178
152
|
const nonblank = value => typeof value === 'string' && value.trim().length > 0;
|
|
179
153
|
const scripts = manifest.scripts || {};
|
|
180
|
-
const releaseCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) release
|
|
154
|
+
const releaseCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) release(?: publish)?$/u;
|
|
181
155
|
// Resolve npm script aliases without executing project code. Cycles stop here.
|
|
182
156
|
function commands(command, seen = new Set()) {
|
|
183
157
|
if (typeof command !== 'string')
|
|
@@ -201,7 +175,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
201
175
|
&& ['public', 'restricted'].includes(manifest.publishConfig?.access), 'package.json: publishConfig must declare registry https://registry.npmjs.org/ and access public or restricted.');
|
|
202
176
|
requireThat(Array.isArray(manifest.files) && manifest.files.length > 0 && manifest.files.every(nonblank), 'package.json: published packages require a nonempty files list.');
|
|
203
177
|
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
|
-
requireThat(typeof scripts.release === 'string' && releaseCommand.test(scripts.release.trim()), 'package.json: scripts.release must invoke peacekeeper release directly.');
|
|
178
|
+
requireThat(typeof scripts.release === 'string' && releaseCommand.test(scripts.release.trim()), 'package.json: scripts.release must invoke peacekeeper release publish directly.');
|
|
205
179
|
const testWorkflow = workflows.get(config.projectChecks.testWorkflow);
|
|
206
180
|
requireThat(testWorkflow && Object.values(testWorkflow.jobs).some((rawJob) => {
|
|
207
181
|
const job = rawJob;
|
|
@@ -262,7 +236,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
262
236
|
const steps = job.steps || [];
|
|
263
237
|
const installed = steps.findIndex(step => directCommand(step, installCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
264
238
|
const tested = steps.findIndex(step => directCommand(step, testCommand) && unconditional(step.if) && !step['continue-on-error']);
|
|
265
|
-
const policy = steps.findIndex(step => directCommand(step, /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) verify-release-protection$/u)
|
|
239
|
+
const policy = steps.findIndex(step => directCommand(step, /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) (?:release verify-protection|verify-release-protection)$/u)
|
|
266
240
|
&& unconditional(step.if) && !step['continue-on-error'] && step.env?.GH_TOKEN);
|
|
267
241
|
if (policy > installed && installed >= 0 && policy < tested && config.git.releaseRequiredChecks.includes(job.name || id))
|
|
268
242
|
policyJobs += 1;
|
|
@@ -277,7 +251,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
277
251
|
checked.clear();
|
|
278
252
|
requiredJob(...matching[0], true);
|
|
279
253
|
}
|
|
280
|
-
requireThat(policyJobs > 0, `${filename}: a job in git.releaseRequiredChecks must run unconditional verify-
|
|
254
|
+
requireThat(policyJobs > 0, `${filename}: a job in git.releaseRequiredChecks must run unconditional release verify-protection with GH_TOKEN after npm ci and before tests.`);
|
|
281
255
|
});
|
|
282
256
|
if (published)
|
|
283
257
|
check('publication', () => {
|
|
@@ -306,9 +280,9 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
306
280
|
requireThat(publish >= 0 && unconditional(steps[publish].if) && !steps[publish]['continue-on-error'], `${publishing.path}: npm publish must be unconditional and must not allow failure.`);
|
|
307
281
|
const publishEnvironment = { ...workflow.env, ...job.env, ...steps[publish]?.env };
|
|
308
282
|
requireThat(!['NPM_TOKEN', 'NODE_AUTH_TOKEN'].some(key => Object.hasOwn(publishEnvironment, key)), `${publishing.path}: remove npm publishing tokens from the publish step; use OIDC. Scope private dependency read authentication to npm ci.`);
|
|
309
|
-
requireThat(installed >= 0 && verify > installed && verify < publish && unconditional(steps[verify].if) && !steps[verify]['continue-on-error'], `${publishing.path}: run
|
|
283
|
+
requireThat(installed >= 0 && verify > installed && verify < publish && unconditional(steps[verify].if) && !steps[verify]['continue-on-error'], `${publishing.path}: run release verify unconditionally before npm publish.`);
|
|
310
284
|
const environment = { ...workflow.env, ...job.env, ...steps[verify]?.env };
|
|
311
|
-
requireThat(environment.RELEASE_TAG === '${{ github.ref_name }}' && environment.GH_TOKEN, `${publishing.path}:
|
|
285
|
+
requireThat(environment.RELEASE_TAG === '${{ github.ref_name }}' && environment.GH_TOKEN, `${publishing.path}: release verify needs RELEASE_TAG from github.ref_name and GH_TOKEN.`);
|
|
312
286
|
const permissions = job.permissions || workflow.permissions;
|
|
313
287
|
requireThat(permissions && permissions['id-token'] === 'write' && ['read', 'write'].includes(permissions.contents), `${publishing.path}: declare contents: read and id-token: write for publishing.`);
|
|
314
288
|
const selected = config.git.releaseTestWorkflow;
|
|
@@ -321,7 +295,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
321
295
|
runtime.stdout.write(fs.readFileSync(path.join(modulesRoot, 'projects/check-project-requirements.txt'), 'utf8'));
|
|
322
296
|
return;
|
|
323
297
|
}
|
|
324
|
-
output.log('Run peacekeeper
|
|
298
|
+
output.log('Run peacekeeper project check --explain for the complete expected project architecture and requirements.');
|
|
325
299
|
const { errors, published } = checkProject();
|
|
326
300
|
if (errors.length) {
|
|
327
301
|
for (const error of errors)
|
|
@@ -329,7 +303,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
|
|
|
329
303
|
runtime.exitCode = 1;
|
|
330
304
|
}
|
|
331
305
|
else
|
|
332
|
-
output.log(`Project checks passed: package, tools,
|
|
306
|
+
output.log(`Project checks passed: package, tools, Codex configuration, CI${published ? ', publication' : ' (publishesToNpm=false; publication skipped)'}.`);
|
|
333
307
|
}
|
|
334
308
|
function run(options = {}) {
|
|
335
309
|
try {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export default ({
|
|
2
|
-
const { planHooks } = installHooks;
|
|
3
|
-
const { createGithubPolicy, githubSetupPlan } = releases;
|
|
1
|
+
export default ({ external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, YAML, } }) => {
|
|
4
2
|
const TOOLCHAIN = Object.freeze({
|
|
5
3
|
node: '22.14.0',
|
|
6
4
|
npm: '11.21.0',
|
|
@@ -64,10 +62,10 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
|
|
|
64
62
|
fs.writeFileSync(target, contents, { mode });
|
|
65
63
|
}
|
|
66
64
|
function workflow(published) {
|
|
67
|
-
return `name: Test\n\non:\n pull_request:\n branches: [main]\n\npermissions:\n contents: read\n\njobs:\n test:\n runs-on: ubuntu-24.04\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n - run: npm ci\n - name: Verify strict release policy\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n run: npm exec --no -- peacekeeper verify-
|
|
65
|
+
return `name: Test\n\non:\n pull_request:\n branches: [main]\n\npermissions:\n contents: read\n\njobs:\n test:\n runs-on: ubuntu-24.04\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n - run: npm ci\n - name: Verify strict release policy\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n run: npm exec --no -- peacekeeper release verify-protection\n - run: npm test\n${published ? `\n package:\n name: Test package\n runs-on: ubuntu-24.04\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n - run: npm ci\n - run: npm run test:package\n` : ''}`;
|
|
68
66
|
}
|
|
69
67
|
function publishWorkflow() {
|
|
70
|
-
return `name: Publish\n\non:\n push:\n tags: ['v*']\n\npermissions:\n contents: read\n\njobs:\n publish:\n name: Publish to npm\n runs-on: ubuntu-24.04\n permissions:\n contents: read\n actions: read\n pull-requests: read\n id-token: write\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n with:\n registry-url: https://registry.npmjs.org\n - run: npm ci\n - name: Verify release\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n RELEASE_TAG: \${{ github.ref_name }}\n run: npm exec --no -- peacekeeper verify
|
|
68
|
+
return `name: Publish\n\non:\n push:\n tags: ['v*']\n\npermissions:\n contents: read\n\njobs:\n publish:\n name: Publish to npm\n runs-on: ubuntu-24.04\n permissions:\n contents: read\n actions: read\n pull-requests: read\n id-token: write\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n with:\n registry-url: https://registry.npmjs.org\n - run: npm ci\n - name: Verify release\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n RELEASE_TAG: \${{ github.ref_name }}\n run: npm exec --no -- peacekeeper release verify\n - run: npm publish\n`;
|
|
71
69
|
}
|
|
72
70
|
function renderTemplate(filename, replacements) {
|
|
73
71
|
let template = fs.readFileSync(path.join(modulesRoot, `projects/${filename}`), 'utf8');
|
|
@@ -81,27 +79,13 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
|
|
|
81
79
|
return template.trim();
|
|
82
80
|
}
|
|
83
81
|
function githubSetup(repositories) {
|
|
84
|
-
const prefix = renderTemplate('github-setup-prefix.sh', {});
|
|
85
|
-
const configured = repositories.map(({ owner, repositoryName,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
catch (error) {
|
|
92
|
-
throw new Error(`GitHub setup for ${owner}/${repositoryName}: ${error instanceof Error ? error.message : String(error)}`);
|
|
93
|
-
}
|
|
94
|
-
return renderTemplate('github-setup-repository-template.sh', {
|
|
95
|
-
OWNER: shellSingleQuotedContent(owner),
|
|
96
|
-
REPOSITORY_NAME: shellSingleQuotedContent(repositoryName),
|
|
97
|
-
DEFAULT_BRANCH: shellSingleQuotedContent(plan.branchPath),
|
|
98
|
-
REPOSITORY_PATCH_ARGUMENTS: plan.repositoryPatchArguments,
|
|
99
|
-
BASE_RULESET: plan.baseRuleset,
|
|
100
|
-
APPROVAL_RULESET: plan.approvalRuleset,
|
|
101
|
-
REQUIRED_APPROVER: shellSingleQuotedContent(requiredApprover),
|
|
102
|
-
REQUIRED_APPROVER_LOWER: shellSingleQuotedContent(requiredApprover.toLowerCase()),
|
|
103
|
-
});
|
|
104
|
-
});
|
|
82
|
+
const prefix = renderTemplate('github-setup-prefix.sh', { VERSION: shellSingleQuotedContent(packageVersion) });
|
|
83
|
+
const configured = repositories.map(({ owner, repositoryName, policyPr, sourceRef }) => renderTemplate('github-setup-repository-template.sh', {
|
|
84
|
+
REPOSITORY: shellSingleQuotedContent(`${owner}/${repositoryName}`),
|
|
85
|
+
PLAN_NAME: shellSingleQuotedContent(`${owner}--${repositoryName}.json`),
|
|
86
|
+
POLICY_PR: shellSingleQuotedContent(policyPr === undefined ? '' : String(policyPr)),
|
|
87
|
+
SOURCE_REF: shellSingleQuotedContent(sourceRef || ''),
|
|
88
|
+
}));
|
|
105
89
|
const argumentsValue = repositories
|
|
106
90
|
.map(({ owner, repositoryName }) => `--new-repo ${shellLiteral(`${owner}/${repositoryName}`)}`)
|
|
107
91
|
.join(' ');
|
|
@@ -126,8 +110,8 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
|
|
|
126
110
|
repository: { type: 'git', url: `git+${options.repository}` }, license: 'MIT',
|
|
127
111
|
engines: { node: '>=20' }, volta: { node: TOOLCHAIN.node, npm: TOOLCHAIN.npm },
|
|
128
112
|
main: './dist/index.js', types: './dist/index.d.ts', exports: { '.': { types: './dist/index.d.ts', import: './dist/index.js' } },
|
|
129
|
-
scripts: { build: 'tsc -p tsconfig.json', prepare: 'npm run build', typecheck: 'tsc -p tsconfig.json --noEmit', test: 'peacekeeper run
|
|
130
|
-
...(options.published ? { 'test:package': 'node scripts/test-package.cjs', prerelease: 'npm ci', release: 'peacekeeper release' } : {}) },
|
|
113
|
+
scripts: { build: 'tsc -p tsconfig.json', prepare: 'npm run build', typecheck: 'tsc -p tsconfig.json --noEmit', test: 'peacekeeper test run', 'test:unit': 'node --test test/*.test.js',
|
|
114
|
+
...(options.published ? { 'test:package': 'node scripts/test-package.cjs', prerelease: 'npm ci', release: 'peacekeeper release publish' } : {}) },
|
|
131
115
|
devDependencies: { '@jakobm/peacekeeper': version, '@types/node': TOOLCHAIN.nodeTypes, typescript: TOOLCHAIN.typescript },
|
|
132
116
|
...(options.published ? { files: ['dist/'], publishConfig: { access: 'public', registry: 'https://registry.npmjs.org/' } } : {}),
|
|
133
117
|
};
|
|
@@ -140,12 +124,9 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
|
|
|
140
124
|
const defaults = JSON.parse(JSON.stringify(projectConfigDefaults));
|
|
141
125
|
defaults.publishesToNpm = options.published;
|
|
142
126
|
defaults.git.requiredApprover = options.owner;
|
|
143
|
-
defaults.tests.
|
|
127
|
+
defaults.tests.all = ['npm run typecheck', 'npm run build', 'npm run test:unit', ...(options.published ? ['npm run test:package'] : [])];
|
|
144
128
|
defaults.tests.npmTestUsesRunner = true;
|
|
145
129
|
write(root, 'peacekeeper.config.yaml', YAML.stringify(defaults, { lineWidth: 0 }));
|
|
146
|
-
write(root, '.codex/hooks.json', json(planHooks({}).document));
|
|
147
|
-
const prefix = fs.readFileSync(path.join(modulesRoot, 'projects/codex-setup-prefix.sh'), 'utf8');
|
|
148
|
-
write(root, '.codex/environments/environment.toml', `version = 1\nname = ${JSON.stringify(options.repositoryName)}\n\n[setup]\nscript = '''\n${prefix}'''\n`);
|
|
149
130
|
write(root, '.github/workflows/test.yml', workflow(options.published));
|
|
150
131
|
write(root, '.github/CODEOWNERS', `* @${options.owner}\n`);
|
|
151
132
|
if (options.published)
|
|
@@ -1,59 +1,20 @@
|
|
|
1
|
-
export default ({
|
|
2
|
-
|
|
3
|
-
const { githubSetup, repositoryIdentity } = createProjectCore;
|
|
4
|
-
function api(endpoint, missingAllowed = false) {
|
|
5
|
-
const response = spawnSync('gh', ['api', '--hostname', 'github.com', '--method', 'GET', endpoint], {
|
|
6
|
-
encoding: 'utf8',
|
|
7
|
-
});
|
|
8
|
-
if (response.status === 0) {
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(response.stdout);
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
throw new Error(`GitHub returned invalid JSON for ${endpoint}.`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (missingAllowed && /HTTP 404\b/u.test(response.stderr || ''))
|
|
17
|
-
return undefined;
|
|
18
|
-
throw new Error(`Cannot read GitHub configuration (${endpoint}): ${response.error?.message
|
|
19
|
-
|| response.stderr?.trim() || `exit ${response.status}`}`);
|
|
20
|
-
}
|
|
21
|
-
function loadRepositorySetup(repository) {
|
|
22
|
-
const identity = repositoryIdentity(repository);
|
|
23
|
-
const slug = `${identity.owner}/${identity.repositoryName}`;
|
|
24
|
-
const metadata = api(`repos/${slug}`);
|
|
25
|
-
if (typeof metadata?.default_branch !== 'string' || !metadata.default_branch) {
|
|
26
|
-
throw new Error(`GitHub did not return a default branch for ${slug}.`);
|
|
27
|
-
}
|
|
28
|
-
const endpoint = `repos/${slug}/contents/peacekeeper.config.yaml?ref=${encodeURIComponent(metadata.default_branch)}`;
|
|
29
|
-
const file = api(endpoint, true);
|
|
30
|
-
let config;
|
|
31
|
-
if (file === undefined) {
|
|
32
|
-
const legacyEndpoint = `repos/${slug}/contents/peacekeeper.config.json?ref=${encodeURIComponent(metadata.default_branch)}`;
|
|
33
|
-
if (api(legacyEndpoint, true) !== undefined) {
|
|
34
|
-
throw new Error(`${slug}/peacekeeper.config.json: rename this legacy JSON configuration to peacekeeper.config.yaml and convert it to YAML.`);
|
|
35
|
-
}
|
|
36
|
-
config = structuredClone(projectConfigDefaults);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
if (file.type !== 'file' || file.encoding !== 'base64' || typeof file.content !== 'string') {
|
|
40
|
-
throw new Error(`${slug}/peacekeeper.config.yaml: GitHub returned invalid file contents.`);
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
config = YAML.parse(Buffer.from(file.content, 'base64').toString('utf8'));
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
throw new Error(`${slug}/peacekeeper.config.yaml: ${error instanceof Error ? error.message : String(error)}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
validateConfig(config, `${slug}/peacekeeper.config.yaml`);
|
|
50
|
-
return { ...identity, requiredChecks: config.git.releaseRequiredChecks,
|
|
51
|
-
requiredApprover: config.git.requiredApprover || identity.owner,
|
|
52
|
-
defaultBranch: metadata.default_branch };
|
|
53
|
-
}
|
|
54
|
-
function run({ repository: repositories }) {
|
|
1
|
+
export default ({ createProjectCore, releases, external: { runtime } }) => {
|
|
2
|
+
function run({ repository: repositories, policyPr, sourceRef }) {
|
|
55
3
|
try {
|
|
56
|
-
|
|
4
|
+
if (repositories.length !== 1 && (policyPr !== undefined || sourceRef !== undefined)) {
|
|
5
|
+
throw new Error('--policy-pr and --source-ref require exactly one --repository. Generate separate wrappers for different policy sources.');
|
|
6
|
+
}
|
|
7
|
+
const sources = repositories.map(repository => {
|
|
8
|
+
const identity = createProjectCore.repositoryIdentity(repository);
|
|
9
|
+
const plan = releases.planGithub({ repository: `${identity.owner}/${identity.repositoryName}`, policyPr, sourceRef });
|
|
10
|
+
if (plan.blockers.length)
|
|
11
|
+
throw new Error(`${repository}: ${plan.blockers.join('; ')}`);
|
|
12
|
+
return { ...identity, sourceRef: plan.source.sha, policyPr: plan.source.policyPr };
|
|
13
|
+
});
|
|
14
|
+
const slugs = sources.map(source => `${source.owner}/${source.repositoryName}`.toLowerCase());
|
|
15
|
+
if (new Set(slugs).size !== slugs.length)
|
|
16
|
+
throw new Error('Each repository may be specified only once.');
|
|
17
|
+
runtime.stdout.write(createProjectCore.githubSetup(sources));
|
|
57
18
|
}
|
|
58
19
|
catch (error) {
|
|
59
20
|
runtime.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
set -euo pipefail
|
|
3
3
|
|
|
4
|
-
#
|
|
5
|
-
|
|
4
|
+
# Run this script with a plan directory to review and save the GitHub changes.
|
|
5
|
+
# Run it again with --execute and the same directory to apply those saved plans.
|
|
6
|
+
# Review deletions carefully: protection on other branches will be removed.
|
|
7
|
+
mode=plan
|
|
8
|
+
if [[ "${1:-}" == --execute ]]; then
|
|
9
|
+
mode=execute
|
|
10
|
+
shift
|
|
11
|
+
fi
|
|
12
|
+
if [[ $# != 1 || -z "$1" ]]; then
|
|
13
|
+
printf 'Usage: %s [--execute] PLAN_DIRECTORY\n' "$0" >&2
|
|
14
|
+
exit 2
|
|
15
|
+
fi
|
|
16
|
+
plan_directory=$1
|
|
17
|
+
if [[ "$mode" == plan ]]; then
|
|
18
|
+
mkdir -p -- "$plan_directory"
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
configure_repository() {
|
|
22
|
+
local repository=$1 plan_name=$2 policy_pr=$3 source_ref=$4
|
|
23
|
+
local args=(github configure --plan-file "$plan_directory/$plan_name")
|
|
24
|
+
if [[ "$mode" == execute ]]; then
|
|
25
|
+
args+=(--execute --repository "$repository")
|
|
26
|
+
else
|
|
27
|
+
args+=(--repository "$repository")
|
|
28
|
+
if [[ -n "$policy_pr" ]]; then args+=(--policy-pr "$policy_pr"); fi
|
|
29
|
+
if [[ -n "$source_ref" ]]; then args+=(--source-ref "$source_ref"); fi
|
|
30
|
+
fi
|
|
31
|
+
npm exec --yes --package '@jakobm/peacekeeper@{{VERSION}}' -- peacekeeper "${args[@]}"
|
|
32
|
+
}
|