Skip to content

Commit

Permalink
feat(core): add CI generation to create-nx-workspace (#9611)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Apr 20, 2022
1 parent 4b7bc90 commit 5fe8d84
Show file tree
Hide file tree
Showing 18 changed files with 706 additions and 37 deletions.
10 changes: 10 additions & 0 deletions docs/generated/cli/create-nx-workspace.md
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
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
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
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
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
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
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
@@ -0,0 +1 @@
export const ciList = ['github', 'circleci', 'azure'] as const;

1 comment on commit 5fe8d84

@vercel
Copy link

@vercel vercel bot commented on 5fe8d84 Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.