diff --git a/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts b/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts index 50342c6b69ffb..8c8bbea665e61 100644 --- a/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts +++ b/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts @@ -244,4 +244,34 @@ describe('CI Workflow generator', () => { '{workspaceRoot}/.gitlab-ci.yml', ]); }); + + it('should add workflow files to namedInputs.sharedGlobals and update default', async () => { + await ciWorkflowGenerator(tree, { ci: 'github', name: 'CI' }); + + const nxJson = readJson(tree, 'nx.json'); + expect(nxJson.namedInputs.sharedGlobals).toEqual([ + '{workspaceRoot}/.github/workflows/ci.yml', + ]); + expect(nxJson.namedInputs.default).toEqual(['sharedGlobals']); + }); + + it('should append sharedGlobals to existing default namedInput', async () => { + // Set up initial nx.json with existing default namedInput + const initialNxJson = readJson(tree, 'nx.json'); + initialNxJson.namedInputs = { + default: ['existing'], + }; + writeJson(tree, 'nx.json', initialNxJson); + + await ciWorkflowGenerator(tree, { ci: 'github', name: 'CI' }); + + const updatedNxJson = readJson(tree, 'nx.json'); + expect(updatedNxJson.namedInputs.sharedGlobals).toEqual([ + '{workspaceRoot}/.github/workflows/ci.yml', + ]); + expect(updatedNxJson.namedInputs.default).toEqual([ + 'existing', + 'sharedGlobals', + ]); + }); }); diff --git a/packages/workspace/src/generators/ci-workflow/ci-workflow.ts b/packages/workspace/src/generators/ci-workflow/ci-workflow.ts index 388e601468b6c..7c05499702cb3 100644 --- a/packages/workspace/src/generators/ci-workflow/ci-workflow.ts +++ b/packages/workspace/src/generators/ci-workflow/ci-workflow.ts @@ -125,4 +125,14 @@ function addWorkflowFileToSharedGlobals( nxJson.namedInputs ??= {}; nxJson.namedInputs.sharedGlobals ??= []; nxJson.namedInputs.sharedGlobals.push(input); + + // Ensure 'default' named input exists and includes 'sharedGlobals' + if (!nxJson.namedInputs.default) { + nxJson.namedInputs.default = ['sharedGlobals']; + } else if ( + Array.isArray(nxJson.namedInputs.default) && + !nxJson.namedInputs.default.includes('sharedGlobals') + ) { + nxJson.namedInputs.default.push('sharedGlobals'); + } }