Skip to content

Commit

Permalink
fix(core): fix workflow naming
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Apr 19, 2022
1 parent 0bf70b4 commit f14e8c3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ jobs:
command: yarn nx-cloud start-ci-run
- run:
name: Run workspace lint
command: nx workspace-lint
command: yarn nx workspace-lint
- run:
name: Check format
command: nx format:check
command: yarn nx format:check
- run:
name: Run lint
command: yarn nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3
Expand Down Expand Up @@ -167,3 +167,33 @@ jobs:
number-of-agents: 3
"
`;
exports[`lib should generate github CI config with custom name 1`] = `
"name: My custom-workflow
on:
push:
branches:
- main
pull_request:
jobs:
main:
name: Nx Cloud - Main Job
uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.2
with:
parallel-commands: |
yarn nx workspace-lint
yarn nx format:check
parallel-commands-on-agents: |
yarn nx affected --target=lint --parallel=3
yarn nx affected --target=test --parallel=3 --ci --code-coverage
yarn nx affected --target=build --parallel=3
agents:
name: Nx Cloud - Agents
uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.2
with:
number-of-agents: 3
"
`;
11 changes: 11 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 @@ -26,4 +26,15 @@ describe('lib', () => {

expect(tree.read('azure-pipelines.yml', 'utf-8')).toMatchSnapshot();
});

it('should generate github CI config with custom name', async () => {
await ciWorkflowGenerator(tree, {
ci: 'github',
name: 'My custom-workflow',
});

expect(
tree.read('.github/workflows/my-custom-workflow.yml', 'utf-8')
).toMatchSnapshot();
});
});
6 changes: 5 additions & 1 deletion packages/workspace/src/generators/ci-workflow/ci-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ export async function ciWorkflowGenerator(host: Tree, schema: Schema) {
interface Substitutes {
mainBranch: string;
workflowName: string;
workflowFileName: string;
packageManagerInstall: string;
packageManagerPrefix: string;
tmpl: '';
}

function normalizeOptions(options: Schema): Substitutes {
const { name: workflowName } = names(options.name || 'build');
const { name: workflowName, fileName: workflowFileName } = names(
options.name || 'build'
);
const { exec: packageManagerPrefix, ciInstall: packageManagerInstall } =
getPackageManagerCommand();
return {
workflowName,
workflowFileName,
packageManagerInstall,
packageManagerPrefix,
mainBranch: deduceDefaultBase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
command: <%= packageManagerPrefix %> nx-cloud start-ci-run
- run:
name: Run workspace lint
command: <% packageManagerPrefix %> nx workspace-lint
command: <%= packageManagerPrefix %> nx workspace-lint
- run:
name: Check format
command: <% packageManagerPrefix %> nx format:check
command: <%= packageManagerPrefix %> nx format:check
- run:
name: Run lint
command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3
Expand All @@ -64,7 +64,7 @@ jobs:
workflows:
version: 2

<%= workflowName %>:
<%= workflowFileName %>:
jobs:
- agent:
matrix:
Expand Down

0 comments on commit f14e8c3

Please sign in to comment.