Skip to content

Commit

Permalink
docs(circleci): Update CircleCI recipes config (#2018)
Browse files Browse the repository at this point in the history
Updates the included CircleCI config file example.

* Now uses 2.1 style config
* Uses Node Orb
* Use pre-defined node/test job
* Uses Matrix jobs to test multiple node versions.
* Updated Node versions
* Using new CircleCI docker images (from node executor)
* Updated language/terminology in description
  • Loading branch information
KyleTryon committed Jul 8, 2021
1 parent 143c898 commit 413ffd2
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions docs/recipes/circleci-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,39 @@ Alternatively, the default `NPM_TOKEN` and `GH_TOKEN` can be easily [setup with

### `.circleci/config.yml` configuration for multiple Node jobs

This example is a minimal configuration for **semantic-release** with a build running Node 6 and 8. See [CircleCI documentation](https://circleci.com/docs/2.0) for additional configuration options.
This example is a minimal configuration for **semantic-release** with tests running against Node 16 and 14. See [CircleCI documentation](https://circleci.com/docs/2.0) for additional configuration options.

This example create the workflows `test_node_4`, `test_node_6`, `test_node_8` and `release`. The release workflows will [run `semantic-release` only after the all the `test_node_*` are successful](../usage/ci-configuration.md#run-semantic-release-only-after-all-tests-succeeded).
In this example, the [`circleci/node`](https://circleci.com/developer/orbs/orb/circleci/node) orb is imported (Which makes some node operations easier), then a `release` job is defined which will run `semantic-release`.

To run our `release` job, we have created a workflow named `test_and_release` which will run two jobs, `node/test`, which comes from the node orb and will test our application, and our release job. Here, we are actually making use of [matrix jobs](https://circleci.com/blog/circleci-matrix-jobs/) so that our single `node/test` job will actually be executed twice, once for Node version 16, and once for version 14. Finally, we call our release job with a `requires` parameter so that `release` will only run after `node/test` has successfully tested against v14 and v16.

```yaml
version: 2
version: 2.1
orbs:
node: circleci/node@4.5
jobs:
test_node_6:
docker:
- image: circleci/node:6
steps:
# Configure your test steps here (checkout, npm install, cache management, tests etc...)

test_node_8:
docker:
- image: circleci/node:8
steps:
# Configure your test steps here (checkout, npm install, cache management, tests etc...)

release:
docker:
- image: circleci/node:8
executor: node/default
steps:
- checkout
- run: npm install
- node/install-packages # Install and automatically cache packages
# Run optional required steps before releasing
# - run: npm run build-script
- run: npx semantic-release

workflows:
version: 2
test_and_release:
# Run the test jobs first, then the release only when all the test jobs are successful
jobs:
- test_node_6
- test_node_8
- node/test:
matrix:
parameters:
version:
- 16.1.0
- 14.7.0
- release:
requires:
- test_node_6
- test_node_8
- node/test
```

### `package.json` configuration for multiple Node jobs
Expand Down

0 comments on commit 413ffd2

Please sign in to comment.