sandworm-hq/sandworm-js

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1
orbs: 
  node: circleci/node@5.0.2
jobs:
  setup:
    executor:
      name: node/default
    steps:
      - checkout
      - restore_cache:
          keys:
            - deps-{{ checksum "yarn.lock" }}
            - deps-
      - node/install-packages:
          pkg-manager: yarn
      - save_cache:
          key: deps-{{ checksum "yarn.lock" }}
          paths: 
            - node_modules
      - persist_to_workspace:
          root: .
          paths:
            - '*'
  lint:
    executor:
      name: node/default
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Lint code
          command: yarn lint
  build:
    executor:
      name: node/default
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Build lib
          command: yarn build
      - persist_to_workspace:
          root: .
          paths:
            - 'dist'
  test-web:
    docker:
      - image: mcr.microsoft.com/playwright:v1.28.1-focal
    environment:
      NODE_ENV: development
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Install browsers
          command: npx playwright install
      - run:
          name: Run tests
          command: yarn test-web-capture
      - store_test_results:
          path: ./
  test-node:
    executor: node/default
    parameters:
      version:
        type: string
    steps:
      - attach_workspace:
          at: .
      - node/install:
          install-yarn: true
          node-version: << parameters.version >>
      - run:
          name: Validate Node version
          command: echo Testing on node $(node --version)
      - run:
          name: Run tests
          command: yarn test-node-ce
      - store_test_results:
          path: ./
  test-unit:
    executor: node/default
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Setup Code Climate test-reporter
          command: |
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
            chmod +x ./cc-test-reporter
      - run:
          name: Run tests
          command: |
            ./cc-test-reporter before-build
            yarn test-unit
            ./cc-test-reporter format-coverage -t lcov -o tmp/codeclimate.jsdom.json coverage/jsdom/lcov.info
            ./cc-test-reporter format-coverage -t lcov -o tmp/codeclimate.node.json coverage/node/lcov.info
            ./cc-test-reporter sum-coverage tmp/codeclimate.*.json -p 2 -o tmp/codeclimate.total.json
            ./cc-test-reporter upload-coverage -i tmp/codeclimate.total.json
      - store_test_results:
          path: ./
  release-pr:
    executor: node/default
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Install release-please
          command: yarn global add release-please
      - run:
          name: Create or update release PR
          command: release-please release-pr --token=${GH_TOKEN} --repo-url=sandworm-hq/sandworm-guard-js
  github-release:
    executor: node/default
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Install release-please
          command: yarn global add release-please
      - run:
          name: Create release
          command: release-please github-release --token=${GH_TOKEN} --repo-url=sandworm-hq/sandworm-guard-js
  publish-npm:
    executor: node/default
    steps:
      - attach_workspace:
          at: .
      - run: 
          name: Auth With NPM
          command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
      - run:
          name: Publish to NPM
          command: npm publish --access=public
        
workflows:
  test:
    jobs:
      - setup
      - lint:
          requires:
            - setup
      - build:
          requires:
            - lint
      - test-unit:
          requires:
            - build
      - test-web:
          requires:
            - build
      - test-node:
          requires:
            - build
          matrix:
            parameters:
              version:
                - "16.10"
                - "16.13"
                - "16.16"
                - "17.9"
                - "18.0"
                - "18.4"
      - github-release:
          requires:
            - test-unit
            - test-web
            - test-node
          filters:
            branches:
              only: main
      - release-pr:
          requires:
            - github-release
          filters:
            branches:
              only: main
  publish:
    jobs:
      - setup:
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^guard-v.*/
      - lint:
          requires:
            - setup
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^guard-v.*/
      - build:
          requires:
            - lint
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^guard-v.*/
      - publish-npm:
          requires:
            - build
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^guard-v.*/