.circleci/config.yml
# Define common configurations
working_directory: &working_directory
working_directory: /tmp/app
# Filter template: only tags, release/* and hotfix/* branches
filter_only_tags_releases_hotfixes: &filter_only_tags_releases_hotfixes
filters:
tags:
only: /.*/
branches:
only:
- /release\/.*$/
- /hotfix\/.*$/
# Filter template: allow all
filter_all: &filter_all
filters:
tags:
only: /.*/
branches:
only: /.*/
# Filter template: only tags
filter_only_tags: &filter_only_tags
filters:
tags:
only: /.*/
branches:
ignore: /.*/
# Define node build configurations
node_config: &node_config
docker:
- image: circleci/node:8.5
<<: *working_directory
parallelism: 1
# Define Terraform configurations
terraform_config: &terraform_config
docker:
- image: exaprint/gitlab-ci-terraform:0.9.11
<<: *working_directory
parallelism: 1
# Download cached dependencies
restore_npm_cache: &restore_npm_cache
restore_cache:
keys:
- node-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- node-dependencies-
# Save cache dependencies
save_npm_cache: &save_npm_cache
save_cache:
paths:
- node_modules
key: node-dependencies-{{ checksum "package.json" }}
# Download cached workspace
restore_workspace: &restore_workspace
attach_workspace:
# Must be absolute path or relative path from working_directory
at: .
# Save all actual files
save_workspace: &save_workspace
persist_to_workspace:
# Must be relative path from working_directory
root: .
# Must be relative path from root
paths:
- .
version: 2
jobs:
install_dependencies:
<<: *node_config
steps:
- checkout
- *restore_npm_cache
- run:
name: Install Node Dependencies
command: yarn install
- *save_npm_cache
- *save_workspace
unit_tests:
<<: *node_config
steps:
- *restore_workspace
- run:
name: Run Unit Tests and Generate lcov & html reports
command: yarn test-report
- store_artifacts:
path: coverage
destination: coverage
- run:
name: Publish code coverage
command: yarn publish-coverage
code_lint:
<<: *node_config
steps:
- *restore_workspace
- run:
name: Code Linting
command: yarn lint
- run:
name: Security check
command: yarn security-check
check_npm_package_version:
<<: *node_config
steps:
- *restore_workspace
- run:
name: Check NPM Package Version
command: yarn check-version
build_artifacts:
<<: *node_config
steps:
- *restore_workspace
- run:
name: Build Doc & Static Analysis
command: yarn static-analysis
- store_artifacts:
path: artifacts
destination: artifacts
publish_package:
<<: *node_config
steps:
- *restore_workspace
- run:
name: Build production bundle
command: yarn build && yarn build-min
- run:
name: Deploy package to NPM Registry
command: |
echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" > ~/.npmrc
npm publish --access public
workflows:
version: 2
build_and_test:
jobs:
- install_dependencies:
<<: *filter_all
- code_lint:
<<: *filter_all
requires:
- install_dependencies
- unit_tests:
<<: *filter_all
requires:
- install_dependencies
- build_artifacts:
<<: *filter_all
requires:
- install_dependencies
- check_npm_package_version:
<<: *filter_only_tags_releases_hotfixes
requires:
- install_dependencies
- publish_package:
requires:
- check_npm_package_version
- unit_tests
<<: *filter_only_tags