@jakobm/peacekeeper 0.28.0 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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, verifyReleaseCore, external: { clock, fs, os, path, runtime, url: Url, YAML: yaml, } }) => {
2
2
  const { bypassWarning, githubApi, requiredPolicy, verifyProtection } = releaseProtection;
3
3
  const { projectConfig } = configuration;
4
4
  const requiredCondition = "${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}";
@@ -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 (!Array.isArray(job.steps) || !job.steps.some((step) => step?.run === 'npm publish')) {
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}.`);
@@ -236,11 +245,24 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
236
245
  throw new ReleaseError('GitHub did not provide the default branch.');
237
246
  }
238
247
  verifyProtection({ api: githubApi(exec, cwd, host), slug, branch: defaultBranch, ...requiredPolicy(cwd) });
239
- checked(exec, 'git', ['fetch', 'origin', defaultBranch], cwd);
240
- const manifest = JSON.parse(checkedOutput(exec, 'git', ['show', `origin/${defaultBranch}:package.json`], cwd));
248
+ checked(exec, 'git', ['fetch', 'origin', `+refs/heads/${defaultBranch}:refs/remotes/origin/${defaultBranch}`], cwd);
249
+ const sourceSha = checked(exec, 'git', ['rev-parse', `origin/${defaultBranch}`], cwd);
250
+ const configFile = checked(exec, 'git', ['ls-tree', '--name-only', sourceSha, '--', 'peacekeeper.config.yaml'], cwd);
251
+ const sourceConfig = configFile
252
+ ? yaml.parse(checkedOutput(exec, 'git', ['show', `${sourceSha}:peacekeeper.config.yaml`], cwd)) : {};
253
+ if (sourceConfig?.strictVersionHistory === true && bump) {
254
+ throw new ReleaseError('strictVersionHistory requires versions to be assigned before merging. Run npm run release without --bump.');
255
+ }
256
+ const manifest = JSON.parse(checkedOutput(exec, 'git', ['show', `${sourceSha}:package.json`], cwd));
241
257
  const packageInfo = { name: manifest.name, version: manifest.version };
242
- const version = nextVersion(packageInfo.version, bump);
258
+ if (typeof packageInfo.name !== 'string' || !packageInfo.name
259
+ || typeof packageInfo.version !== 'string' || !stableVersion.test(packageInfo.version) || manifest.workspaces) {
260
+ throw new ReleaseError('Default branch needs a named root package with a stable MAJOR.MINOR.PATCH version and no workspaces.');
261
+ }
262
+ const version = bump ? nextVersion(packageInfo.version, bump) : packageInfo.version;
243
263
  const tag = `v${version}`;
264
+ const details = { host, slug, defaultBranch, sourceSha, name: packageInfo.name, version, tag, mergeMethod };
265
+ ensureUnpublished(exec, cwd, details);
244
266
  const localTag = exec('git', ['show-ref', '--verify', '--quiet', `refs/tags/${tag}`], { cwd });
245
267
  if (localTag.status === 0)
246
268
  throw new ReleaseError(`Local tag ${tag} already exists.`);
@@ -252,7 +274,31 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
252
274
  if (remoteTag.status !== 2)
253
275
  throw new ReleaseError(`Could not check origin tag ${tag}: ${remoteTag.stderr.trim()}`);
254
276
  log(`Validated ${packageInfo.name}: ${packageInfo.version} -> ${version} on ${defaultBranch}.`);
255
- return { host, slug, defaultBranch, name: packageInfo.name, version, tag, mergeMethod };
277
+ return details;
278
+ }
279
+ function ensureUnpublished(exec, cwd, details) {
280
+ const cache = fs.mkdtempSync(path.join(os.tmpdir(), 'peacekeeper-registry-'));
281
+ try {
282
+ const result = exec('npm', ['view', `${details.name}@${details.version}`, '--json',
283
+ '--registry', 'https://registry.npmjs.org/', '--prefer-online', '--cache', cache], { cwd });
284
+ let metadata;
285
+ try {
286
+ metadata = JSON.parse(result.stdout);
287
+ }
288
+ catch { /* Report the command failure below. */ }
289
+ if (result.status !== 0) {
290
+ if (metadata?.error?.code === 'E404')
291
+ return;
292
+ throw new ReleaseError(`Cannot check npm publication: ${result.stderr.trim() || result.stdout.trim() || `exit ${result.status}`}`);
293
+ }
294
+ if (metadata?.name !== details.name || metadata?.version !== details.version) {
295
+ throw new ReleaseError('npm returned unexpected package metadata while checking publication.');
296
+ }
297
+ throw new ReleaseError(`${details.name}@${details.version} is already published. Assign a new version before merging when strictVersionHistory is enabled; otherwise use npm run release -- --bump patch, minor, or major.`);
298
+ }
299
+ finally {
300
+ fs.rmSync(cache, { recursive: true, force: true });
301
+ }
256
302
  }
257
303
  function makeVersionCommit(exec, cwd, bump, version) {
258
304
  checked(exec, 'npm', ['version', bump, '--no-git-tag-version', '--ignore-scripts'], cwd);
@@ -363,6 +409,8 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
363
409
  return github(exec, cwd, details.host, `repos/${details.slug}/pulls/${details.pr}`, {});
364
410
  }
365
411
  async function mergeRelease(exec, cwd, details, now, sleep, log) {
412
+ if (details.mergeMethod && details.mergeMethod !== 'merge')
413
+ throw new ReleaseError('Release must use merge commits on the default branch; restart this release.');
366
414
  const deadline = now() + workflowTimeoutMs;
367
415
  while (now() < deadline) {
368
416
  const pr = pullRequest(exec, cwd, details);
@@ -376,19 +424,18 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
376
424
  throw new ReleaseError(`Release PR #${details.pr} has conflicts; inspect it before continuing.`);
377
425
  verifyProtection({ api: githubApi(exec, cwd, details.host), slug: details.slug,
378
426
  branch: details.defaultBranch, ...requiredPolicy(cwd) });
379
- if (details.mergeMethod && details.mergeMethod !== 'merge')
380
- throw new ReleaseError('Release must use merge commits on the default branch; restart this release.');
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;
427
+ if (pr.auto_merge && pr.auto_merge.merge_method !== 'merge') {
428
+ throw new ReleaseError('Release PR auto-merge must use merge commits.');
389
429
  }
390
- else if (!/HTTP (405|409)/u.test(result.stderr)) {
391
- throw new ReleaseError(`Cannot merge release PR: ${result.stderr.trim()}`);
430
+ if (!pr.auto_merge) {
431
+ if (typeof pr.node_id !== 'string' || !pr.node_id)
432
+ throw new ReleaseError('GitHub did not provide the release PR node ID.');
433
+ // Enable auto-merge; GitHub applies all required reviews, checks and freshness gates.
434
+ checked(exec, 'gh', ['api', '--hostname', details.host, '--method', 'POST', 'graphql',
435
+ '-f', 'query=mutation($pullRequestId: ID!, $expectedHeadOid: GitObjectID!) { enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, expectedHeadOid: $expectedHeadOid, mergeMethod: MERGE}) { pullRequest { id } } }',
436
+ '-f', `pullRequestId=${pr.node_id}`, '-f', `expectedHeadOid=${details.sha}`], cwd);
437
+ log(`Enabled auto-merge for release PR #${details.pr}.`);
438
+ continue;
392
439
  }
393
440
  log(`Waiting for release PR #${details.pr} to satisfy merge requirements.`);
394
441
  await sleep(pollIntervalMs);
@@ -424,7 +471,7 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
424
471
  if (fs.existsSync(statePath)) {
425
472
  details = JSON.parse(fs.readFileSync(statePath, 'utf8'));
426
473
  if (details.bump !== bump)
427
- throw new ReleaseError(`An unfinished ${details.bump} release exists; retry that release type.`);
474
+ throw new ReleaseError(`An unfinished release exists; retry with ${details.bump ? `--bump ${details.bump}` : 'no --bump'}.`);
428
475
  const origin = originRepository(checked(exec, 'git', ['remote', 'get-url', 'origin'], cwd));
429
476
  if (origin.host !== details.host || origin.slug !== details.slug)
430
477
  throw new ReleaseError('Origin differs from the unfinished release repository.');
@@ -442,21 +489,25 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
442
489
  break;
443
490
  }
444
491
  details.bump = bump;
445
- details.branch = `release/${details.tag}`;
492
+ if (bump)
493
+ details.branch = `release/${details.tag}`;
494
+ checked(exec, 'git', ['update-ref', `refs/peacekeeper/releases/${details.tag}`, details.sourceSha], cwd);
446
495
  saveState(statePath, details);
447
496
  }
448
497
  temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'peacekeeper-release-worktree-'));
449
498
  worktree = path.join(temporary, 'repo');
450
499
  if (!details.sha) {
451
- checked(exec, 'git', ['worktree', 'add', '--detach', worktree, `origin/${details.defaultBranch}`], cwd);
500
+ checked(exec, 'git', ['worktree', 'add', '--detach', worktree, details.sourceSha], cwd);
452
501
  const baseline = readPackage(worktree);
453
- if (baseline.name !== details.name || nextVersion(baseline.version, bump) !== details.version)
502
+ if (baseline.name !== details.name || (bump ? nextVersion(baseline.version, bump) : baseline.version) !== details.version)
454
503
  throw new ReleaseError('Default branch version changed before release preparation completed; inspect release state.');
504
+ if (projectConfig(worktree).strictVersionHistory && bump)
505
+ throw new ReleaseError('strictVersionHistory on the default branch requires releasing without --bump.');
455
506
  ensureLockfilesMatch(worktree, baseline.version);
456
507
  inspectWorkflow(worktree, details.tag);
457
508
  const sourceSha = checked(exec, 'git', ['rev-parse', 'HEAD'], worktree);
458
509
  log(`Preparing release from origin/${details.defaultBranch} at ${sourceSha}.`);
459
- details.sha = makeVersionCommit(exec, worktree, bump, details.version);
510
+ details.sha = bump ? makeVersionCommit(exec, worktree, bump, details.version) : sourceSha;
460
511
  // Keep the commit reachable if interrupted before the remote push.
461
512
  checked(exec, 'git', ['update-ref', `refs/peacekeeper/releases/${details.tag}`, details.sha], cwd);
462
513
  saveState(statePath, details);
@@ -464,7 +515,7 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
464
515
  else {
465
516
  checked(exec, 'git', ['worktree', 'add', '--detach', worktree, details.sha], cwd);
466
517
  }
467
- if (!details.pr) {
518
+ if (bump && !details.pr) {
468
519
  checked(exec, 'git', ['push', 'origin', `${details.sha}:refs/heads/${details.branch}`], cwd);
469
520
  const existing = github(exec, cwd, details.host, `repos/${details.slug}/pulls`, {
470
521
  state: 'all', head: `${details.slug.split('/')[0]}:${details.branch}`, base: details.defaultBranch,
@@ -488,9 +539,12 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
488
539
  }
489
540
  saveState(statePath, details);
490
541
  }
491
- log(`Release PR: https://${details.host}/${details.slug}/pull/${details.pr}`);
492
- const sha = await mergeRelease(exec, cwd, details, now, sleep, log);
493
- checked(exec, 'git', ['fetch', 'origin', details.defaultBranch], cwd);
542
+ let sha = details.sha;
543
+ if (bump) {
544
+ log(`Release PR: https://${details.host}/${details.slug}/pull/${details.pr}`);
545
+ sha = await mergeRelease(exec, cwd, details, now, sleep, log);
546
+ }
547
+ checked(exec, 'git', ['fetch', 'origin', `+refs/heads/${details.defaultBranch}:refs/remotes/origin/${details.defaultBranch}`], cwd);
494
548
  checked(exec, 'git', ['merge-base', '--is-ancestor', sha, `origin/${details.defaultBranch}`], cwd);
495
549
  checked(exec, 'git', ['checkout', '--detach', sha], worktree);
496
550
  const manifest = readPackage(worktree);
@@ -498,10 +552,15 @@ export default ({ configuration, releaseProtection, external: { clock, fs, os, p
498
552
  throw new ReleaseError('Merged package does not match the intended release.');
499
553
  ensureLockfilesMatch(worktree, details.version);
500
554
  details.workflow = inspectWorkflow(worktree, details.tag);
555
+ const config = projectConfig(worktree);
556
+ verifyReleaseCore.verifyRelease({ api: githubApi(exec, cwd, details.host), slug: details.slug,
557
+ sha, tag: details.tag, branch: details.defaultBranch, ...requiredPolicy(worktree),
558
+ workflow: config.git.releaseTestWorkflow, warn: log });
501
559
  const remote = checked(exec, 'git', ['ls-remote', '--tags', 'origin', `refs/tags/${details.tag}`, `refs/tags/${details.tag}^{}`], cwd);
502
560
  if (remote && !remote.split('\n').some((line) => line.startsWith(`${sha}\t`)))
503
561
  throw new ReleaseError(`Origin tag ${details.tag} points to another commit.`);
504
562
  if (!remote) {
563
+ ensureUnpublished(exec, worktree, details);
505
564
  const local = exec('git', ['rev-parse', '--verify', `refs/tags/${details.tag}^{commit}`], { cwd });
506
565
  if (local.status === 0 && local.stdout.trim() !== sha)
507
566
  throw new ReleaseError(`Local tag ${details.tag} points to another commit.`);
@@ -1,3 +1,4 @@
1
+ // --- Implementation ---
1
2
  export default ({ releaseCore, external: { clock, output, runtime, spawnSync } }) => {
2
3
  const { release } = releaseCore;
3
4
  async function main(bump) {
@@ -10,7 +11,7 @@ export default ({ releaseCore, external: { clock, output, runtime, spawnSync } }
10
11
  log: (message) => output.log(`${clock.date().toTimeString().slice(0, 8)} ${message}`),
11
12
  });
12
13
  }
13
- async function run(bump) {
14
+ async function run({ bump } = {}) {
14
15
  try {
15
16
  await main(bump);
16
17
  }
@@ -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
+ "071a6102729107f4f4f01851e0b661355985a676"
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
+ }
@@ -24,18 +24,18 @@ export default ({ releaseProtection }) => {
24
24
  const pulls = list(api, `${base}/commits/${commit.sha}/pulls`);
25
25
  const pull = pulls.find(pr => pr.merged_at && pr.merge_commit_sha === commit.sha &&
26
26
  pr.base.ref === branch && pr.base.repo.full_name === slug &&
27
- pr.head.repo?.full_name === slug && pr.head.ref === `release/${tag}`);
27
+ pr.head.repo?.full_name === slug);
28
28
  if (!pull)
29
- throw new Error('Tag must point to a merged release PR');
29
+ throw new Error('Tag must point to a merged PR');
30
30
  const runs = list(api, `${base}/actions/workflows/${encodeURIComponent(workflow)}/runs?event=pull_request&head_sha=${pull.head.sha}`, 'workflow_runs');
31
31
  const run = runs.sort((a, b) => b.run_number - a.run_number)[0];
32
32
  if (!run || run.conclusion !== 'success')
33
- throw new Error('Release PR must have a successful CI run');
33
+ throw new Error('Tagged PR must have a successful CI run');
34
34
  const jobs = list(api, `${base}/actions/runs/${run.id}/jobs?filter=latest`, 'jobs');
35
35
  for (const name of checks) {
36
36
  const matching = jobs.filter(job => job.name === name);
37
37
  if (!matching.length || matching.some(job => job.conclusion !== 'success')) {
38
- throw new Error(`Release PR requires successful ${name} check`);
38
+ throw new Error(`Tagged PR requires successful ${name} check`);
39
39
  }
40
40
  }
41
41
  }
@@ -0,0 +1,26 @@
1
+ // --- Implementation ---
2
+ export default ({ external: { buffer: Buffer, fs, path, semver } }) => {
3
+ function verifyVersionHistory({ api, slug, branch, root }) {
4
+ const base = `repos/${slug}`;
5
+ const commit = api(`${base}/commits/${encodeURIComponent(branch)}`);
6
+ if (typeof commit.sha !== 'string' || !/^[a-f0-9]{40}$/u.test(commit.sha)) {
7
+ throw new Error('Cannot determine the default branch commit for version history verification.');
8
+ }
9
+ // Pin the file lookup so a concurrent merge cannot change its source revision.
10
+ const file = api(`${base}/contents/package.json?ref=${commit.sha}`);
11
+ if (file.type !== 'file' || file.encoding !== 'base64' || typeof file.content !== 'string') {
12
+ throw new Error('Cannot read package.json from the default branch for version history verification.');
13
+ }
14
+ const previous = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')).version;
15
+ const current = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version;
16
+ for (const [source, version] of [['Default branch', previous], ['Incoming', current]]) {
17
+ if (typeof version !== 'string' || semver.valid(version) !== version.split('+')[0]) {
18
+ throw new Error(`${source} package.json must have a valid exact semver version.`);
19
+ }
20
+ }
21
+ if (!semver.gt(current, previous)) {
22
+ throw new Error(`strictVersionHistory requires package.json version ${current} to be greater than ${previous} on default branch ${branch} (${commit.sha}). Bump the version before merging.`);
23
+ }
24
+ }
25
+ return { verifyVersionHistory };
26
+ };
@@ -1,4 +1,5 @@
1
- export const porticoFacade = ({ checkConventions, checkTestReceipt, recordTestReceipt, runTests }) => ({
1
+ export const porticoFacade = ({ prepareTests, checkConventions, checkTestReceipt, recordTestReceipt, runTests }) => ({
2
+ prepareTests: prepareTests.run,
2
3
  checkConventions: checkConventions.run,
3
4
  checkTestReceipt: checkTestReceipt.run,
4
5
  recordTestReceipt: recordTestReceipt.run,
@@ -0,0 +1,33 @@
1
+ // --- Implementation ---
2
+ export default ({ configuration, external: { output, runtime, spawnSync } }) => {
3
+ function prepare() {
4
+ const { tests, root } = configuration.projectConfig();
5
+ function run(command, args) {
6
+ const result = spawnSync(command, args, { cwd: root, stdio: 'inherit' });
7
+ if (result.error)
8
+ throw result.error;
9
+ if (result.status !== 0)
10
+ throw new Error(`CI command failed (${result.status ?? result.signal}): ${command}`);
11
+ }
12
+ if (tests.aptPackages.length) {
13
+ if (runtime.platform !== 'linux')
14
+ throw new Error('tests.aptPackages requires a Linux environment with apt-get.');
15
+ run('sudo', ['apt-get', 'update']);
16
+ run('sudo', ['apt-get', 'install', '--yes', '--no-install-recommends', '--', ...tests.aptPackages]);
17
+ }
18
+ if (tests.playwrightBrowsers.length) {
19
+ run('npm', ['exec', '--no', '--', 'playwright', 'install', '--with-deps', ...tests.playwrightBrowsers]);
20
+ }
21
+ }
22
+ return {
23
+ run: () => {
24
+ try {
25
+ prepare();
26
+ }
27
+ catch (error) {
28
+ output.error(error instanceof Error ? error.message : String(error));
29
+ runtime.exitCode = 1;
30
+ }
31
+ },
32
+ };
33
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakobm/peacekeeper",
3
- "version": "0.28.0",
3
+ "version": "0.30.1",
4
4
  "description": "Shared repository test, Git worktree, and Codex hook commands",
5
5
  "license": "MIT",
6
6
  "author": "Jakob Mattsson",
@@ -40,8 +40,8 @@
40
40
  "node": "^22.14.0"
41
41
  },
42
42
  "dependencies": {
43
- "@jakobm/cmdabra": "^0.7.0",
44
- "@jakobm/portico": "^0.8.1",
43
+ "@jakobm/cmdabra": "^0.9.0",
44
+ "@jakobm/portico": "^0.10.1",
45
45
  "glob": "^14.0.4",
46
46
  "semver": "^7.8.5",
47
47
  "yaml": "^2.9.1"
@@ -1,25 +0,0 @@
1
- export default ({ configuration, releaseCore, releaseProtection, external: { output, runtime, spawnSync, } }) => {
2
- const { projectConfig } = configuration;
3
- const { originRepository } = releaseCore;
4
- const { githubApi, requiredPolicy, verifyProtection } = releaseProtection;
5
- function main(cwd = runtime.cwd()) {
6
- const config = projectConfig(cwd);
7
- const remote = spawnSync('git', ['remote', 'get-url', config.git.remote], { encoding: 'utf8' });
8
- if (remote.status !== 0)
9
- throw new Error(remote.stderr);
10
- const { host, slug } = originRepository(remote.stdout.trim());
11
- const api = githubApi((command, args, options) => spawnSync(command, args, { ...options, encoding: 'utf8' }), cwd, host);
12
- verifyProtection({ api, slug, branch: api(`repos/${slug}`).default_branch,
13
- ...requiredPolicy(cwd), warn: message => output.warn(message) });
14
- }
15
- function run() {
16
- try {
17
- main();
18
- }
19
- catch (error) {
20
- output.error(error instanceof Error ? error.message : String(error));
21
- runtime.exitCode = 1;
22
- }
23
- }
24
- return { run };
25
- };