version: 2

defaults: &defaults
  docker:
    - image: circleci/node:10-browsers
  working_directory: ~/axe-cli

jobs:
  dependencies:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          key: v1-npm-cache-{{ checksum "package-lock.json" }}
      - run: npm ci
      - run: npm install chromedriver@latest
      - save_cache:
          key: v1-npm-cache-{{ checksum "package-lock.json" }}
          paths:
            - node_modules
  tests:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-npm-cache-{{ checksum "package-lock.json" }}
            - v1-npm-cache-
      - run: npm run lint
      - run: npm test

  release:
    <<: *defaults
    steps:
      - checkout
      - run: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
      - run: npm publish

  github_release:
    docker:
      - image: circleci/golang:1.10
    steps:
      - checkout
      - run: go get gopkg.in/aktau/github-release.v0
      - run:
          name: Download and run GitHub release script
          command: |
            curl https://raw.githubusercontent.com/dequelabs/attest-release-scripts/develop/src/node-github-release.sh -s -o ./node-github-release.sh
            chmod +x ./node-github-release.sh
            ./node-github-release.sh

workflows:
  version: 2
  build:
    jobs:
      - dependencies
      - tests:
          requires:
            - dependencies
      - release:
          requires:
            - dependencies
            - tests
          filters:
            branches:
              only: master
      - github_release:
          requires:
            - release
