version: 2
jobs:
  build:
    docker:
      - image: circleci/node:8.16@sha256:1fad5860c7b4a0057aae4fb9c0d273c6d7452c0c24a33931941358b546f3e424

    working_directory: ~/repo

    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: Build
          command: yarn build

      - run:
          name: Test
          command: yarn test

      - run:
          name: Post Slack message
          command: ./bin/ci.js slack

      - run:
          name: Post GitHub message
          command: ./bin/ci.js github-post

      - run:
          name: Print env vars
          command: npx cross-ci printenv

