14nrv/buefy-shop

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2

jobs:
  test:
    docker:
      - image: circleci/node:12.18.2-browsers
    working_directory: ~/repo
    steps:
      - checkout
      - restore_cache:
          key: yarn-{{ checksum "yarn.lock" }}
      - run:
          name: Install all dependencies
          command: yarn install
      - save_cache:
          key: yarn-{{ checksum "yarn.lock" }}
          paths:
            - "node_modules"
      - 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: JavaScript Linter
          command: yarn lint -f ./node_modules/eslint-junit/index.js
          environment:
            ESLINT_JUNIT_OUTPUT: "coverage/junit/js-eslint-results.xml"
      - run:
          name: Unit tests with coverage
          command: |
            ./cc-test-reporter before-build
            yarn test --coverage
            ./cc-test-reporter after-build --exit-code $?
          environment:
            JEST_JUNIT_OUTPUT: "coverage/junit/js-test-results.xml"
      - store_test_results:
          path: coverage/junit
      - store_artifacts:
          path: coverage/junit

  deploy:
    docker:
      - image: circleci/node:12.18.2-browsers
    working_directory: ~/repo
    steps:
      - checkout
      - run:
          name: Install vercel globally with yarn
          command: yarn global add vercel
      - run:
          name: Deploy if tests pass and branch is Master
          command: |
            export PATH="$PATH:$HOME/.config/yarn/global/node_modules/.bin"
             vercel --confirm --force --no-clipboard --public --token ${NOW_TOKEN} && vercel alias buefy-shop-pi --token ${NOW_TOKEN}

  deploy-dev:
    docker:
      - image: circleci/node:12.18.2-browsers
    working_directory: ~/repo
    steps:
      - checkout
      - run:
          name: Install vercel globally with yarn
          command: yarn global add vercel
      - run:
          name: Deploy if tests pass and branch start with dev
          command: |
            export PATH="$PATH:$HOME/.config/yarn/global/node_modules/.bin"
            vercel --confirm --force --no-clipboard --public --token ${NOW_TOKEN} && vercel alias buefy-shop-pi-dev --token ${NOW_TOKEN}

workflows:
  version: 2
  deploy:
    jobs:
      - test
      - deploy:
          requires:
            - test
          filters:
            branches:
              only: master
      - deploy-dev:
          requires:
            - test
          filters:
            branches:
              ignore: master