version: 2
jobs:
  test:
    working_directory: ~/work
    docker:
      - image: circleci/clojure:lein-2.9.1-node-browsers
    steps:
      - checkout
      - restore_cache:
          keys:
            - lein-v1-{{ checksum "project.clj" }}
            - lein-v1
      - restore_cache:
          keys:
            - npm-v1-{{ checksum "package.json" }}
            - npm-v1
      - run: sudo npm install -g karma-cli
      - run: npm install
      - run: ./run-tests.sh lein
      - save_cache:
          paths:
            - ~/.m2
            - ~/.lein
            - ~/.cljs/.aot_cache
          key: lein-v1-{{ checksum "project.clj" }}
      - save_cache:
          paths:
            - node_modules
          key: npm-v1-{{ checksum "package.json" }}
      - store_artifacts:
          path: coverage
      - run: bash <(curl -s https://codecov.io/bash)

    environment:
      NPM_CONFIG_LOGLEVEL: warn

  test-clj:
    working_directory: ~/work
    docker:
      - image: circleci/clojure:tools-deps-1.9.0.397-node-browsers
    steps:
      - checkout
      - restore_cache:
          keys:
            - clj-v1-{{ checksum "deps.edn" }}
            - clj-v1
      - restore_cache:
          keys:
            - npm-v1-{{ checksum "package.json" }}
            - vpm-v1
      - run: sudo npm install -g karma-cli
      - run: npm install
      - run: ./run-tests.sh clj
      - save_cache:
          paths:
            - ~/.m2
            - ~/.lein
            - ~/.cljs/.aot_cache
          key: clj-v1-{{ checksum "deps.edn" }}
      - save_cache:
          paths:
            - node_modules
          key: npm-v1-{{ checksum "package.json" }}
      - store_artifacts:
          path: coverage
      - run: bash <(curl -s https://codecov.io/bash)

    environment:
      NPM_CONFIG_LOGLEVEL: warn

  update-site:
    working_directory: ~/work
    docker:
      - image: circleci/clojure:lein-2.9.1-node
    steps:
      - checkout
      - add_ssh_keys
      - restore_cache:
          keys:
            - lein-v1-{{ checksum "project.clj" }}
            - lein-v1
      - restore_cache:
          keys:
            - npm-v1-{{ checksum "package.json" }}
            - npm-v1
      - run: npm install
      - deploy:
          command: ./build-example-site.sh

  update-tagged-docs:
    working_directory: ~/work
    docker:
      - image: circleci/clojure:lein-2.9.1
    steps:
      - checkout
      - add_ssh_keys
      - restore_cache:
          keys:
            - lein-v1-{{ checksum "project.clj" }}
            - lein-v1
      - deploy:
          command: ./build-docs.sh
workflows:
  version: 2
  test-and-update-site:
    jobs:
      - test:
          filters:
            tags:
              only: /v.*/
      - test-clj:
          filters:
            tags:
              only: /v.*/
      - update-site:
          requires:
            - test
            - test-clj
          filters:
            branches:
              only:
                - master
      - update-tagged-docs:
          requires:
            - test
            - test-clj
          filters:
            branches:
              ignore:
                - /.*/
            tags:
              only: /v.*/