@@ -3,7 +3,7 @@ process.env.PGPM_SKIP_UPDATE_CHECK = 'true';
33process . env . PGPM_SKIP_SKILL_INSTALL = 'true' ;
44
55import { PgpmPackage , TEMPLATE_REPOS } from '@pgpmjs/core' ;
6- import { existsSync , mkdirSync , readFileSync } from 'fs' ;
6+ import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'fs' ;
77import { sync as glob } from 'glob' ;
88import { Inquirerer , ParsedArgs } from 'inquirerer' ;
99import * 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' , ( ) => {
0 commit comments