Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add CI generation to create-nx-workspace #9611

Merged
merged 12 commits into from
Apr 20, 2022
10 changes: 10 additions & 0 deletions docs/generated/cli/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ Type: string

The name of the application when a preset with pregenerated app is selected

### ci

Type: array

Choices: [github, circleci, azure]

Default: []

Generate a CI workflow file

### cli

Type: string
Expand Down
42 changes: 42 additions & 0 deletions docs/generated/packages/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,48 @@
"aliases": [],
"hidden": false,
"path": "/packages/workspace/src/generators/npm-package/schema.json"
},
{
"name": "ci-workflow",
"factory": "./src/generators/ci-workflow/ci-workflow#ciWorkflowGenerator",
"schema": {
"$schema": "http://json-schema.org/schema",
"$id": "NxWorkspaceCIWorkflow",
"title": "Generate a CI workflow.",
"description": "Generate a CI workflow.",
"cli": "nx",
"type": "object",
"properties": {
"ci": {
"type": "string",
"description": "CI provider.",
"enum": ["github", "circleci", "azure"],
"x-prompt": {
"message": "What is your target CI provider?",
"type": "list",
"items": [
{ "value": "github", "label": "Github Actions" },
{ "value": "circleci", "label": "Circle CI" },
{ "value": "azure", "label": "Azure DevOps" }
]
}
},
"name": {
"type": "string",
"description": "Workflow name.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "How should we name your workflow?",
"pattern": "^[a-zA-Z].*$"
}
},
"required": ["ci"],
"presets": []
},
"description": "Generete a CI workflow.",
"implementation": "/packages/workspace/src/generators/ci-workflow/ci-workflow#ciWorkflowGenerator.ts",
"aliases": [],
"hidden": false,
"path": "/packages/workspace/src/generators/ci-workflow/schema.json"
}
],
"executors": [
Expand Down
5 changes: 5 additions & 0 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@
"id": "workspace-generator",
"path": "/packages/workspace/generators/workspace-generator"
},
{
"name": "ci-workflow generator",
"id": "ci-workflow-generator",
"path": "/packages/workspace/generators/ci-workflow"
},
{
"name": "convert-to-nx-project generator",
"id": "convert-to-nx-project-generator",
Expand Down
3 changes: 2 additions & 1 deletion docs/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@
"workspace-generator",
"run-commands",
"convert-to-nx-project",
"npm-package"
"npm-package",
"ci-workflow"
]
}
}
Expand Down
17 changes: 11 additions & 6 deletions docs/shared/monorepo-ci-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ variables:
value: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(git rev-parse HEAD~1)
- name: HEAD_SHA
value: $(git rev-parse HEAD)

jobs:
- job: main
Expand Down Expand Up @@ -88,12 +90,13 @@ variables:
value: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(git rev-parse HEAD~1)
- name: HEAD_SHA
value: $(git rev-parse HEAD)

jobs:
- job: agents
strategy:
matrix:
agent: [1, 2, 3]
parallel: 3
displayName: 'Agent $(imageName)'
pool:
vmImage: 'ubuntu-latest'
Expand All @@ -109,13 +112,15 @@ jobs:
- script: npx nx-cloud start-ci-run

- script: npx nx workspace-lint
- script: npx nx format:check
- script: npx nx affected --base=$(BASE_SHA) --target=lint --parallel=3
- script: npx nx affected --base=$(BASE_SHA) --target=test --parallel=3 --ci --code-coverage
- script: npx nx affected --base=$(BASE_SHA) --target=build --parallel=3
- script: npx nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=test --parallel=3 --ci --code-coverage
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=build --parallel=3

- script: npx nx-cloud stop-all-agents
condition: always()
```

You can also use our [ci-workflow generator](https://nx.app/packages/workspace/generators/ci-workflow) to generate the pipeline file.

Learn more about [configuring your CI](https://nx.app/docs/configuring-ci) environment using Nx Cloud with [Distributed Caching](https://nx.app/docs/distributed-caching) and [Distributed Task Execution](https://nx.app/docs/distributed-execution) in the Nx Cloud docs.
5 changes: 3 additions & 2 deletions docs/shared/monorepo-ci-circle-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jobs:
ordinal:
type: integer
steps:
- run: echo "export NX_RUN_GROUP=\"run-group-$CIRCLE_WORKFLOW_ID\";" >> $BASH_ENV
- checkout
- run: npm ci
- run:
Expand All @@ -83,7 +82,6 @@ jobs:
environment:
NX_CLOUD_DISTRIBUTED_EXECUTION: 'true'
steps:
- run: echo "export NX_RUN_GROUP=\"run-group-$CIRCLE_WORKFLOW_ID\";" >> $BASH_ENV
- checkout
- run: npm ci
- nx/set-shas
Expand All @@ -96,6 +94,7 @@ jobs:
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3

- run: npx nx-cloud stop-all-agents
when: always
workflows:
build:
jobs:
Expand All @@ -106,4 +105,6 @@ workflows:
- main
```

You can also use our [ci-workflow generator](https://nx.app/packages/workspace/generators/ci-workflow) to generate the configuration file.

Learn more about [configuring your CI](https://nx.app/docs/configuring-ci) environment using Nx Cloud with [Distributed Caching](https://nx.app/docs/distributed-caching) and [Distributed Task Execution](https://nx.app/docs/distributed-execution) in the Nx Cloud docs.
2 changes: 2 additions & 0 deletions docs/shared/monorepo-ci-github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ jobs:
number-of-agents: 3
```

You can also use our [ci-workflow generator](https://nx.app/packages/workspace/generators/ci-workflow) to generate the workflow file.

Learn more about [configuring your CI](https://nx.app/docs/configuring-ci) environment using Nx Cloud with [Distributed Caching](https://nx.app/docs/distributed-caching) and [Distributed Task Execution](https://nx.app/docs/distributed-execution) in the Nx Cloud docs.
1 change: 1 addition & 0 deletions packages/create-nx-workspace/bin/ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ciList = ['github', 'circleci', 'azure'] as const;