| 1 |
version: 2.1 |
| 2 |
|
| 3 |
jobs: |
| 4 |
test: |
| 5 |
parameters: |
| 6 |
version: |
| 7 |
type: string |
| 8 |
default: latest |
| 9 |
docker: |
| 10 |
- image: cimg/go:<<parameters.version>> |
| 11 |
environment: |
| 12 |
TEST_RESULTS: /tmp/test-results |
| 13 |
working_directory: ~/gods |
| 14 |
steps: |
| 15 |
- run: |
| 16 |
name: Print Go version (go version) |
| 17 |
command: | |
| 18 |
go version |
| 19 |
- checkout |
| 20 |
- run: |
| 21 |
name: Run tests |
| 22 |
command: | |
| 23 |
mkdir -p $TEST_RESULTS |
| 24 |
go install gotest.tools/gotestsum@latest |
| 25 |
go test -v ./... | go tool test2json > $TEST_RESULTS/test2json-output.json |
| 26 |
gotestsum --junitfile $TEST_RESULTS/gotestsum-report.xml |
| 27 |
- run: |
| 28 |
name: Calculate test coverage |
| 29 |
command: | |
| 30 |
mkdir -p $TEST_RESULTS |
| 31 |
go test -coverprofile=coverage.out ./... > /dev/null |
| 32 |
go test -race -coverprofile=coverage.txt -covermode=atomic ./... > /dev/null |
| 33 |
go tool cover -html=coverage.out -o coverage.html |
| 34 |
mv coverage.html $TEST_RESULTS |
| 35 |
- run: |
| 36 |
name: Upload test coverage |
| 37 |
command: | |
| 38 |
bash <(curl -s https://codecov.io/bash) |
| 39 |
- run: |
| 40 |
name: Lint (golint) |
| 41 |
command: | |
| 42 |
go install golang.org/x/lint/golint@latest |
| 43 |
golint -set_exit_status ./... |
| 44 |
- run: |
| 45 |
name: Enforce formatted code (go fmt) |
| 46 |
command: | |
| 47 |
! go fmt ./... 2>&1 | read |
| 48 |
- run: |
| 49 |
name: Examine and report suspicious constructs (go vet) |
| 50 |
command: | |
| 51 |
go vet -v ./... |
| 52 |
- run: |
| 53 |
name: Calculate cyclomatic complexity (gocyclo) |
| 54 |
command: | |
| 55 |
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest |
| 56 |
gocyclo -avg -over 15 ../gods |
| 57 |
- run: |
| 58 |
name: Check for unchecked errors (errcheck) |
| 59 |
command: | |
| 60 |
go install github.com/kisielk/errcheck@latest |
| 61 |
errcheck ./... |
| 62 |
- store_artifacts: |
| 63 |
path: /tmp/test-results |
| 64 |
destination: raw-test-output |
| 65 |
- store_test_results: |
| 66 |
path: /tmp/test-results |
| 67 |
|
| 68 |
workflows: |
| 69 |
test: |
| 70 |
jobs: |
| 71 |
- test: |
| 72 |
matrix: |
| 73 |
parameters: |
| 74 |
|
| 75 |
version: [ "1.18", "1.17" ] |