Skip to content

Commit 472842b

Browse files
authored
Merge pull request #1845 from constructive-io/feat/pgpm-init-ci-matrix
feat(pgpm): init adds each new module to the workspace CI matrix, sorted
2 parents 41de688 + 689657b commit 472842b

8 files changed

Lines changed: 980 additions & 1 deletion

File tree

.agents/skills/pgpm/references/cli.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ Non-interactive init requires every question to be answered by flags; see
175175
`--name --fullName --email --username --repoName --license`, plus module
176176
`--moduleName --packageIdentifier --moduleDesc --access`.
177177
178+
When a module is created, `pgpm init` also adds its workspace-relative path to
179+
each `jobs.<job>.strategy.matrix.package` list in the workspace's
180+
`.github/workflows/*.yml` (sorted, in place). The workflow is parsed with `yaml`
181+
to address that path, and only the matrix list's own byte range is rewritten, so
182+
comments and formatting survive where they can be preserved. A matrix whose
183+
comments cannot be preserved is left untouched. The list stays a plain YAML
184+
array you can hand-edit; workflows without such a matrix — or whose matrix isn't
185+
a plain list of strings — or that can't be read or written — are left alone
186+
silently; the update is best-effort and never warns.
187+
178188
### Workspace Inspection
179189
180190
**pgpm ls** — List the pgpm modules in the current workspace

pgpm/cli/__tests__/init.test.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ process.env.PGPM_SKIP_UPDATE_CHECK = 'true';
33
process.env.PGPM_SKIP_SKILL_INSTALL = 'true';
44

55
import { PgpmPackage, TEMPLATE_REPOS } from '@pgpmjs/core';
6-
import { existsSync, mkdirSync, readFileSync } from 'fs';
6+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
77
import { sync as glob } from 'glob';
88
import { Inquirerer, ParsedArgs } from 'inquirerer';
99
import * as path from 'path';
@@ -538,6 +538,72 @@ describe('cmds:init', () => {
538538
expect(existsSync(path.join(modDir, 'pgpm.plan'))).toBe(true);
539539
expect(existsSync(path.join(modDir, 'package.json'))).toBe(true);
540540
});
541+
542+
it('adds each new module to the CI matrix, sorted', async () => {
543+
const { mockInput, mockOutput } = environment;
544+
const prompter = new Inquirerer({
545+
input: mockInput,
546+
output: mockOutput,
547+
noTty: true
548+
});
549+
550+
const wsName = 'ws-ci-matrix';
551+
const wsRoot = path.join(fixture.tempDir, wsName);
552+
553+
await commands(withInitDefaults({
554+
_: ['init', 'workspace'],
555+
cwd: fixture.tempDir,
556+
name: wsName,
557+
workspace: true
558+
}), prompter, {
559+
noTty: true,
560+
input: mockInput,
561+
output: mockOutput,
562+
version: '1.0.0',
563+
minimistOpts: {}
564+
});
565+
566+
const workflow = path.join(wsRoot, '.github', 'workflows', 'ci.yml');
567+
mkdirSync(path.dirname(workflow), { recursive: true });
568+
writeFileSync(workflow, [
569+
'jobs:',
570+
' test:',
571+
' strategy:',
572+
' matrix:',
573+
' # kept sorted by pgpm init',
574+
' package: []',
575+
' steps:',
576+
' - run: cd ./${{ matrix.package }} && pnpm test',
577+
''
578+
].join('\n'));
579+
580+
for (const modName of ['zeta', 'alpha']) {
581+
await commands(withInitDefaults({
582+
_: ['init'],
583+
cwd: wsRoot,
584+
moduleName: modName,
585+
name: modName
586+
}), prompter, {
587+
noTty: true,
588+
input: mockInput,
589+
output: mockOutput,
590+
version: '1.0.0',
591+
minimistOpts: {}
592+
});
593+
}
594+
595+
expect(readFileSync(workflow, 'utf8')).toBe([
596+
'jobs:',
597+
' test:',
598+
' strategy:',
599+
' matrix:',
600+
' # kept sorted by pgpm init',
601+
' package: [packages/alpha, packages/zeta]',
602+
' steps:',
603+
' - run: cd ./${{ matrix.package }} && pnpm test',
604+
''
605+
].join('\n'));
606+
});
541607
});
542608

543609
describe('--create-workspace flag', () => {

pgpm/cli/src/commands/init/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
addToCiMatrix,
23
BoilerplateSkill,
34
DEFAULT_TEMPLATE_REPO,
45
DEFAULT_TEMPLATE_TOOL_NAME,
@@ -866,6 +867,16 @@ async function handleModuleInit(
866867
});
867868
}
868869

870+
if (resolvedWorkspacePath) {
871+
const matrixFiles = addToCiMatrix(
872+
resolvedWorkspacePath,
873+
path.relative(resolvedWorkspacePath, modulePath)
874+
);
875+
for (const file of matrixFiles) {
876+
process.stdout.write(`Added ${modName} to the CI matrix in ${file}\n`);
877+
}
878+
}
879+
869880
const motdPath = path.join(modulePath, '.motd');
870881
let motd = DEFAULT_MOTD;
871882
if (fs.existsSync(motdPath)) {

0 commit comments

Comments
 (0)