Skip to content

Commit

Permalink
fix(core): make sure sharedGlobals is referenced in default namedInpu…
Browse files Browse the repository at this point in the history
…ts (nrwl#27813)
  • Loading branch information
juristr authored Sep 10, 2024
1 parent 72432d6 commit e4a9650
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});
});
10 changes: 10 additions & 0 deletions packages/workspace/src/generators/ci-workflow/ci-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit e4a9650

Please sign in to comment.