# This file gets used by ./tasks/node/build-circleci-config.js
# to build the real file in ./.circleci/config.yml

version: 2.1

jobs:
  check_circle_config:
    docker:
      - image: "circleci/node:10"
    steps:
      - "checkout"
      - run: "npm ci"
      - run: "cd ./.circleci/ && shasum -a 256 config.yml > checksum"
      - run: "npm run build-circleci-config"
      - run: "cd ./.circleci/ && shasum -a 256 -c checksum || (echo \"oh no, it looks like the circleci is out of date. Please run `npm run build-circleci-config` and commit the changes it has made.\" && exit 1)"
  lint_js:
    docker:
      - image: "circleci/node:10"
    steps:
      - "checkout"
      - run: "npm ci"
      - run: "npm run lint"
  unit_tests:
    docker:
      - image: "circleci/node:10"
    steps:
      - "checkout"
      - run: "npm ci"
      - run: "npm run test-library"
  publish_to_npm:
    docker:
      - image: "circleci/node:10"
    steps:
      - "checkout"
      - run: "npm ci"
      - run: "echo \"//registry.npmjs.org/:_authToken=$NPM_TOKEN\" > ~/.npmrc"
      - run: "npm publish"

workflows:
  test:
    jobs:
      - check_circle_config:
          filters:
            tags:
              ignore: /^v.*/
            branches:
              ignore: master
      - lint_js:
          filters:
            tags:
              ignore: /^v.*/
            branches:
              ignore: master
      - unit_tests:
          filters:
            tags:
              ignore: /^v.*/
            branches:
              ignore: master
      - publish_to_npm:
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
