version: 2
jobs:
  test:
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - run: yarn --no-progress
      - run: ./node_modules/.bin/eslint --max-warnings=0 .
      - run: sed -i.tmp -e 's/^; \(suppress_comment=.*FlowFB.*\)$/\1/' .flowconfig
      - run: ./node_modules/.bin/flow check --show-all-errors

  release:
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - run: yarn --no-progress
      - run: ./scripts/oss-publish.sh

  publish-modules:
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - run: yarn --no-progress
      - run: bash -x ./scripts/modules-publish.sh

workflows:
  version: 2
  build_and_test:
    jobs:
      - test
  deployment:
    jobs:
      - release:
          filters:
            tags:
              ignore: /.*/
            branches:
              # pull request have their branch name in `pull/xxxx` format
              # so they won't trigger the build
              only: /^release-v[0-9]+\.[0-9]+\.[0-9]+$/
      - publish-modules:
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /modules-v.*/
