version: 2.1 # Set the CI version.

# Several steps in this config use the same, specialized node module caching steps. Commands
# can be used to extract a common set of steps into a reusable-block. In this case, whenever
# you see `- node-deps` as a "step" in the config below, it is executing a command to restore
# the cache, install/update deps if needed, and save the cache.
commands:
  node-deps:
    description: "Runs specialized steps to fetch/install|update/save node_modules."
    steps:
      # Download cached dependencies
      - restore_cache:
          keys:
            - twyr-announce-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - twyr-announce-dependencies-
      - run:
          name: Install node dependencies
          command: npm i

      # Cache dependencies
      - save_cache:
          paths:
            - node_modules

          key: twyr-announce-dependencies-{{ checksum "package.json" }}

# Workflows orchestrate a set of jobs to be run;
# the jobs for this pipeline are # configured below
workflows:
  version: 2

  workflow-build-and-test:
    jobs:
      - job-build-and-test

jobs:
  job-build-and-test:
    docker:
      - image: circleci/node:14-browsers
        environment:
          CHROME_BIN: "/usr/bin/google-chrome"

    steps:
      - checkout
      - node-deps

      - run:
          name: install graphviz
          command: |
            sudo apt-get install graphviz

      - run:
          command: npm run build
