.circleci/config.yml
version: 2
jobs:
checkout_code:
working_directory: /home/circleci/generic-model-bookshelf
docker:
- image: circleci/node:12
steps:
- checkout
- save_cache:
key : repo-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
paths :
- ./
node_dependencies:
working_directory: /home/circleci/generic-model-bookshelf
docker:
- image: circleci/node:12
steps:
- restore_cache:
key: repo-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
key: node-cache-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name : Authenticating with github registry
command : npm config set '//npm.pkg.github.com/:_authToken' "${GH_TOKEN}"
- run:
name : Installing npm dependencies
command : npm install
- save_cache:
key : node-cache-{{ .Branch }}-{{ checksum "package.json" }}
paths :
- ./node_modules
tests:
working_directory: /home/circleci/generic-model-bookshelf
docker:
- image: circleci/node:12
- image: postgres:9.5
environment:
POSTGRES_USER : ubuntu
POSTGRES_PASSWORD : randomPasswd
POSTGRES_DB : test_generic_model
steps:
- restore_cache:
key: repo-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
key: node-cache-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name : Waiting for Postgres
command : dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name : Running tests
command : npm run test
environment :
PG_HOST : localhost
PG_USER : ubuntu
PG_PASSWORD : randomPasswd
TEST_HOST : 127.0.0.1
TEST_DB : test_generic_model
- store_artifacts:
path : test-results.xml
prefix : tests
- store_artifacts:
path : coverage
prefix : coverage
- store_test_results:
path: test-results.xml
- save_cache:
key : test-coverage-cache-{{ .Environment.CIRCLE_SHA1 }}
paths : ./coverage
npm_version:
working_directory: /home/circleci/generic-model-bookshelf
docker:
- image: circleci/node:12
steps:
- restore_cache:
key: repo-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
key: node-cache-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name : Updating version
command : npm run update-version
npm_release:
working_directory: /home/circleci/generic-model-bookshelf
docker:
- image: circleci/node:12
steps:
- restore_cache:
key: repo-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
key: node-cache-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name : Releasing and publishing version
command : npm run release-version
npm_publish:
working_directory: /home/circleci/generic-model-bookshelf
docker:
- image: circleci/node:12
steps:
- restore_cache:
key: repo-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
key: node-cache-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name: Authenticating with registry
command: echo "//registry.npmjs.org/:_authToken=$GH_TOKEN" > .npmrc
- run:
name: Publishing package
command: npm publish
workflows:
version: 2
build-and-deploy:
jobs:
- checkout_code
- node_dependencies:
context:
- github
requires:
- checkout_code
- tests:
requires:
- node_dependencies
- approval:
filters:
branches:
ignore: master
type: approval
requires:
- tests
- npm_version:
context:
- github
requires:
- approval
- npm_release:
filters:
branches:
only: master
context:
- github
requires:
- tests
- npm_publish:
requires:
- npm_release