version: 2.0
jobs:
  test:
    docker:
      - image: circleci/node:12-browsers
    steps:
      - checkout
      - run: npm ci
      - run: npm run lint
      - run: npm test
      - store_artifacts:
          path: coverage
  integration_tests:
    docker:
      - image: circleci/node:12-browsers
    steps:
      - checkout
      - run: npm ci
      - run:
          name: Run integration test
          command: ./scripts/bin/run-integration-test-circleci.sh
  deploy_dev:
    docker:
      - image: circleci/node:12
    steps:
      - checkout
      - setup_remote_docker
      - run: docker login -u $DOCKER_USER -p $DOCKER_PASS
      - run: docker build -t mozilla/send:latest .
      - run: docker push mozilla/send:latest
  deploy_vnext:
    docker:
      - image: circleci/node:12
    steps:
      - checkout
      - setup_remote_docker
      - run: docker login -u $DOCKER_USER -p $DOCKER_PASS
      - run: docker build -t mozilla/send:vnext .
      - run: docker push mozilla/send:vnext
  deploy_stage:
    docker:
      - image: circleci/node:12
    steps:
      - checkout
      - setup_remote_docker
      - run: docker login -u $DOCKER_USER -p $DOCKER_PASS
      - run: docker build -t mozilla/send:$CIRCLE_TAG .
      - run: docker push mozilla/send:$CIRCLE_TAG
workflows:
  version: 2
  test_pr:
    jobs:
      - test:
          filters:
            branches:
              ignore:
                - master
                - vnext
      - integration_tests:
          filters:
            branches:
              ignore: master
  build_and_deploy_dev:
    jobs:
      - deploy_dev:
          filters:
            branches:
              only: master
            tags:
              ignore: /^v.*/
      - deploy_vnext:
          filters:
            branches:
              only: vnext
            tags:
              ignore: /^v.*/
  build_and_deploy_stage:
    jobs:
      - test:
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^v.*/
      - integration_tests:
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^v.*/
      - deploy_stage:
          requires:
            - test
            - integration_tests
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^v.*/