version: 2
jobs:
  test:
    docker:
      - image: circleci/node:6
    steps:
      - checkout
      - run:
          name: Add Wine repository
          command: |
            sudo apt-get update -qq
            export TZ=America/Los_Angeles
            export DEBIAN_FRONTEND=noninteractive
            sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && sudo sh -c 'echo $TZ > /etc/timezone'
            sudo apt-get install -y wine-development mono-devel
            sudo dpkg --add-architecture i386
            sudo apt-get update -qq
            sudo apt-get install -y wine32-development
      - restore_cache:
          keys:
            - v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
            - v1-dependencies-{{ arch }}-
      - run: yarn install --ignore-engines
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
      - run: yarn test
  release:
    docker:
      - image: circleci/node:10.15
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
            - v1-dependencies-{{ arch }}-
      - run: yarn install
      - run: yarn build
      - run: npx semantic-release
workflows:
  version: 2
  test_and_release:
    # Run the test jobs first, then the release only when all the test jobs are successful
    jobs:
      - test
      - release:
          requires:
            - test
          filters:
            branches:
              only:
                - master
