version: 2
jobs:
  test:
    docker:
      - image: circleci/node:10-browsers
    steps:
      - checkout
      # Install dependencies for cypress -- https://docs.cypress.io/guides/guides/continuous-integration.html#Ubuntu-Debian
      - run: sudo apt-get install libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
      - run: npm config set prefix "$HOME/.local"
      - run: npm i -g origami-build-tools@^9
      - run: $HOME/.local/bin/obt install
      - run: $HOME/.local/bin/obt build
      - run: $HOME/.local/bin/obt verify
      - run: npm run checksizes
      # `obt test` doesn't work because of custom karma config, so we run:
      - run: npm run test-unit

      # We need to delete bower stuff and check that the package works on npm only
      - run: rm -rf bower_components
      - run: npx occ 0.0.0
      - run: $HOME/.local/bin/obt install --ignore-bower
      - run: npm run test-unit
  publish_to_npm:
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - run: npm install
      - run: npx occ ${CIRCLE_TAG##v}
      - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > $HOME/.npmrc
      - run: npx snyk monitor --org=financial-times --project-name=Financial-Times/o-ads
      - run: npm publish --access public

workflows:
  version: 2
  test:
    jobs:
      - test
      - publish_to_npm:
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
