I am setting up a Node.js project in CircleCI so that for every git push it would run a basic build-and-test routine and if the commit contains a release tag “v1.2.3” it would also publish the package to NPM registry. So far, I have come to this configuration:
defaults: &defaults
docker:
- image: circleci/node:lts
working_directory: ~/repo
version: 2
jobs:
build_and_test:
<<: *defaults
steps:
- checkout
- run:
name: Login to private GitHub registry
command: npm config set //npm.pkg.github.com/:_authToken $GITHUB_TOKEN
- restore_cache:
name: Restore yarn package cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- yarn-packages-
- run:
name: Installing modules
command: yarn install --frozen-lockfile
- save_cache:
name: Save yarn package cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- node_modules
- run:
name: Building project
command: yarn run build
- run:
name: Lint & test
command: yarn run test:full
deploy:
<<: *defaults
steps:
- checkout
- run:
name: Login to private GitHub registry
command: npm config set //npm.pkg.github.com/:_authToken $GITHUB_TOKEN
- restore_cache:
name: Restore yarn package cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- yarn-packages-
- run:
name: Installing modules
command: yarn install --frozen-lockfile
- save_cache:
name: Save yarn package cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- node_modules
- run:
name: Building project
command: yarn run build
- run:
name: Publishing
command: npm publish
workflows:
version: 2
build_test_flow:
jobs:
- build_and_test
build_test_publish_flow:
jobs:
- build_and_test:
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-.*\.[0-9]+)?/
- deploy:
requires:
- build_and_test
filters:
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-.*\.[0-9]+)?/
It seems to be working just fine. However, if I choose to re-execute a build-and-test
run with SSH tunnel for debugging, I am getting the following error message
Your config file has errors and may not run correctly:
jobs: build_and_test: extraneous key [deploy] is not permitted
Note that re-running without SSH does not show this error message. What could I have possibly missed? Thanks!