yasshi2525/RushHour

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1

jobs:
  pre-test:
    machine: 
      image: circleci/classic:latest
    steps: 
      - 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

      - persist_to_workspace:
          root: .
          paths: [cc-test-reporter]

  test-client:
    docker:
      - image: circleci/node:latest-browsers

    steps:
      - checkout

      # load cc-test-reporter
      - attach_workspace:
          at: client

      # reuse node_modules
      - restore_cache:
          key: v1-dependencies-{{ checksum "client/package-lock.json" }}

      - run:
          command: npm install
          working_directory: client

      - save_cache:
          paths: [client/node_modules]
          key: v1-dependencies-{{ checksum "client/package-lock.json" }}

      - run: 
          command: npm test
          environment:
            JEST_JUNIT_OUTPUT_DIR: "reports/jest"
            JEST_JUNIT_OUTPUT_NAME: "results.xml"
          working_directory: client
          
      - run: 
          name: Collect Coverage
          command: ./cc-test-reporter format-coverage -t lcov -o "codeclimate.client.json" coverage/lcov.info
          working_directory: client
      
      # reuse compiled js file
      - run: 
          command: |
            curl -LsS https://github.com/yasshi2525/RushHourResource/archive/v${RES_VRS}.tar.gz | tar zx
            mkdir -p ./src/static/import
            cp -r RushHourResource-${RES_VRS}/dist/* ./src/static/import/
            npm run build
          environment:
            RES_VRS: "0.1.0"
          working_directory: client

      - persist_to_workspace:
          root: .
          paths: 
            - client/reports
            - client/dist
            - client/codeclimate.client.json

  test-server:
    working_directory: /go/src/github.com/yasshi2525/RushHour
    environment:
      CC_TEST_REPORTER_ID: d089f5de52d5f084943cffbf7281df1a041a0926cf1d184ec90ebafdbdfd3f42
    docker:
      - image: circleci/golang:latest

    steps:
      - checkout

      # load cc-test-reporter
      - attach_workspace:
          at: .

      - restore_cache: 
          keys:
            - v1-pkg-cache

      - run:
          name: Module download
          command: |
            go mod download
            go get -u github.com/jstemmer/go-junit-report
      
      - run: 
          name: Run Test
          command: |
            ./cc-test-reporter before-build
            mkdir -p reports/golang
            mkdir -p assets/bundle
            cp -r client/dist/ assets/bundle/
            go test -coverprofile ./c.out -v ./... | tee /dev/tty | go-junit-report > ./reports/golang/results.xml
            ./cc-test-reporter after-build

      - save_cache:
          key: v1-pkg-cache
          paths:
            - "/go/pkg"

      - persist_to_workspace:
          root: .
          paths: 
            - reports

  upload-coverage:
    machine: 
      image: circleci/classic:latest
    environment:
      CC_TEST_REPORTER_ID: d089f5de52d5f084943cffbf7281df1a041a0926cf1d184ec90ebafdbdfd3f42
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Upload coverage results to Code Climate
          command: |
            ./cc-test-reporter sum-coverage client/codeclimate.*.json -p 1
            ./cc-test-reporter upload-coverage

      - store_test_results:
          path: reports

workflows:
  version: 2
  workflow:
    jobs:
      - pre-test
      - test-client:
          requires: [pre-test]
      - test-server:
          requires: [pre-test, test-client]
      - upload-coverage:
          requires: [test-server, test-client]