version: 2.1

orbs:
  sixrs-gke: sixriversystems/sixrs-gke@7

aliases:
  - &node_image cimg/node:16.19.1

jobs:
  install:
    docker:
      - image: *node_image
        environment:
          NODE_ENV: test
    steps:
      - checkout
      - run:
          name: npm ci
          command: |
            npm ci
      - persist_to_workspace:
          root: ./
          paths:
            - .
  test:
    docker:
      - image: *node_image
        environment:
          NODE_ENV: test
          MOCHA_OPTS: --reporter mocha-junit-reporter --reporter-options mochaFile=./reports/junit/mocha/mocha.xml
          ESLINT_OPTS: --quiet --format junit -o ./reports/junit/eslint/eslint.xml
    steps:
      - attach_workspace:
          at: ./
      - run: npm test
      - run: npm run coverage
      - sixrs-gke/codecov
      - store_artifacts:
          path: coverage
      - store_artifacts:
          path: reports/junit/
      - store_test_results:
          path: reports/junit/

  publish:
    docker:
      - image: *node_image
        environment:
          NODE_ENV: test
    steps:
      - attach_workspace:
          at: ./
      # pure-js, no build step
      - sixrs-gke/run-release
      - sixrs-gke/npm-public-publish

workflows:
  version: 2

  test_and_publish:
    jobs:
      - install:
          context: 6rs-public-npm
      - test:
          context: 6rs-public-npm
          requires:
            - install
      - publish:
          context: 6rs-public-npm
          requires:
            - test
