version: 2

refs:
  container: &container
    docker:
      - image: circleci/node:8.11@sha256:af0ffb60afc34736f30fd8ce6662175ca29009835308fb7786e27ecfce424f20
    working_directory: ~/repo

jobs:
  all:
    <<: *container
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run:
          name: Versions
          command: node -v && npm -v && yarn -v
      - run:
          name: Install dependencies
          command: yarn install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - run:
          name: Test
          command: yarn test
      - run:
          name: Post to GitHub
          command: npx ci-scripts github-post
      - run:
          name: Post to Slack
          command: npx ci-scripts slack

  master:
    <<: *container
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run:
          name: Versions
          command: node -v && npm -v && yarn -v
      - run:
          name: Install dependencies
          command: yarn install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - run:
          name: Test
          command: yarn test
      - run:
          name: Post to GitHub
          command: npx ci-scripts github-post
      - run:
          name: Post to Slack
          command: npx ci-scripts slack
      - run:
          name: Release
          command: npx semantic-release

workflows:
  version: 2
  all:
    jobs:
      - all:
          filters:
            branches:
              ignore:
                - master
  master:
    jobs:
      - master:
          filters:
            branches:
              only: master
