simonmittag/punycoder

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
  build:
    working_directory: ~/repo
    # Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
    # See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
    docker:
      - image: cimg/go:1.20
    # Add steps to the job
    # See: https://circleci.com/docs/2.0/configuration-reference/#steps
    steps:
      - checkout
      - restore_cache:
          keys:
            - go-mod-v4-{{ checksum "go.sum" }}
      - run:
          name: Install Dependencies
          command: go mod download
      - save_cache:
          key: go-mod-v4-{{ checksum "go.sum" }}
          paths:
            - "/go/pkg/mod"
      - run:
          name: Run tests
          command: |
            mkdir -p /tmp/test-reports
            gotestsum --junitfile /tmp/test-reports/unit-tests.xml
      - store_test_results:
          path: /tmp/test-reports
  metrics:
    docker:
      - image: cimg/go:1.20
    environment:
      TEST_RESULTS: /tmp/test-results
      LOGLEVEL: TRACE
      LOGCOLOR: TRUE
      CC_TEST_REPORTER_ID: 2dd75c9c35c35e1f03e57e23e1273e2122980d68bfc4d55c6af858c43763295f
    steps:
      - checkout # check out source code to working directory
      - run:
          name: "Create a temp directory for artifacts"
          command: |
            mkdir -p /tmp/artifacts
      - run:
          name: "Create a temp directory for tests"
          command: |
            mkdir -p /tmp/test-results
      - run:
          name: Setup Code Climate test-reporter
          command: |
            # download test reporter as a static binary
            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 with coverage report
          command: |
            export GIT_COMMITTED_AT="$(date +%s)"
            export CIRCLE_SHA="$CIRCLE_SHA1"
            export CIRCLE_BRANCH=`git rev-parse --abbrev-ref HEAD`
            ./cc-test-reporter before-build
            go test -cover -coverprofile=c.out ./...
            go tool cover -html=c.out -o coverage.html
            ./cc-test-reporter after-build --coverage-input-type gocov -p "github.com/simonmittag/punycoder"
            mv coverage.html /tmp/artifacts

      - store_artifacts:
          path: /tmp/artifacts

      - run:
          name: Test Summary for CircleCI
          command: |
            gotestsum --junitfile /tmp/test-results/unit-tests.xml

      - store_test_results:
          path: /tmp/test-results

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
  ci: # This is the name of the workflow, feel free to change it to better match your workflow.
    # Inside the workflow, you define the jobs you want to run.
    jobs:
      - build
      - metrics