-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into eslint-plugin-refactor
- Loading branch information
Showing
42 changed files
with
811 additions
and
323 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
# Configuring CI Using Bitbucket Pipelines and Nx | ||
|
||
Below is an example of an Bitbucket Pipelines, building and testing only what is affected. | ||
Below is an example of a Bitbucket Pipelines, building and testing only what is affected. | ||
|
||
```yaml {% fileName="bitbucket-pipelines.yml" %} | ||
image: node:20 | ||
|
||
clone: | ||
depth: full | ||
|
||
pipelines: | ||
pull-requests: | ||
'**': | ||
- step: | ||
name: 'Build and test affected apps on Pull Requests' | ||
caches: # optional | ||
- node | ||
script: | ||
- npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # this line enables distribution | ||
# This line enables distribution | ||
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested | ||
- npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" | ||
- npm ci | ||
|
||
- npx nx-cloud record -- nx format:check | ||
- npx nx affected -t lint test build --base=origin/master --head=HEAD | ||
- npx nx affected -t lint test build e2e-ci --base=origin/main | ||
|
||
branches: | ||
main: | ||
- step: | ||
name: "Build and test affected apps on 'main' branch changes" | ||
caches: # optional | ||
- node | ||
script: | ||
- npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # this line enables distribution | ||
- export NX_BRANCH=$BITBUCKET_PR_ID | ||
# This line enables distribution | ||
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested | ||
- npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" | ||
- npm ci | ||
|
||
- npx nx-cloud record -- nx format:check | ||
- npx nx affected -t lint test build --base=HEAD~1 | ||
- npx nx affected -t lint test build e2e-ci --base=HEAD~1 | ||
``` | ||
The `pull-requests` and `main` jobs implement the CI workflow. | ||
|
||
### Get the Commit of the Last Successful Build | ||
|
||
Unlike `GitHub Actions` and `CircleCI`, you don't have the metadata to help you track the last successful run on `main`. In the example below, the base is set to `HEAD~1` (for push) or branching point (for pull requests), but a more robust solution would be to tag an SHA in the main job once it succeeds and then use this tag as a base. See the [nx-tag-successful-ci-run](https://github.com/nrwl/nx-tag-successful-ci-run) and [nx-set-shas](https://github.com/nrwl/nx-set-shas) (version 1 implements tagging mechanism) repositories for more information. | ||
|
||
We also have to set `NX_BRANCH` explicitly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
# Configuring CI Using Circle CI and Nx | ||
|
||
Below is an example of an Circle CI setup, building and testing only what is affected. | ||
Below is an example of a Circle CI setup, building, and testing only what is affected. | ||
|
||
```yaml {% fileName=".circleci/config.yml" %} | ||
version: 2.1 | ||
|
||
orbs: | ||
nx: nrwl/[email protected] | ||
nx: nrwl/[email protected] | ||
|
||
jobs: | ||
main: | ||
docker: | ||
- image: cimg/node:lts-browsers | ||
steps: | ||
- checkout | ||
- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # this line enables distribution | ||
# This line enables distribution | ||
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested | ||
- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" | ||
- run: npm ci | ||
|
||
- nx/set-shas | ||
|
||
- run: npx nx-cloud record -- nx format:check | ||
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build --parallel=3 | ||
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build e2e-ci | ||
workflows: | ||
build: | ||
jobs: | ||
|
@@ -26,13 +31,13 @@ workflows: | |
### Get the Commit of the Last Successful Build | ||
`CircleCI` can track the last successful run on the `main` branch and use this as a reference point for the `BASE`. The `Nx Orb` provides a convenient implementation of this functionality which you can drop into your existing CI config. Specifically, `nx/set-shas` populates the `$NX_BASE` environment variable with the commit SHA of the last successful run. | ||
`CircleCI` can track the last successful run on the `main` branch and use this as a reference point for the `BASE`. The [Nx Orb](https://github.com/nrwl/nx-orb) provides a convenient implementation of this functionality, which you can drop into your existing CI workflow. Specifically, for push commits, `nx/set-shas` populates the `$NX_BASE` environment variable with the commit SHA of the last successful run. | ||
|
||
To understand why knowing the last successful build is important for the affected command, check out the [in-depth explanation in Orb's docs](https://github.com/nrwl/nx-orb#background). | ||
|
||
### Using CircleCI in a private repository | ||
|
||
To use the [Nx Orb](https://github.com/nrwl/nx-orb) with a private repository on your main branch, you need to grant the orb access to your CircleCI API. You can do this by creating an environment variable called `CIRCLE_API_TOKEN` in the context or the project. | ||
To use the [Nx Orb](https://github.com/nrwl/nx-orb) with a private repository on your main branch, you need to grant the orb access to your CircleCI API. Create an environment variable called `CIRCLE_API_TOKEN` in the context of the project. | ||
|
||
{% callout type="warning" title="Caution" %} | ||
It should be a user token, not the project token. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.