Spent 2 hours to figure out how to automate Coveralls checking in CircleCI, the online articles are really outdated and not working…
Solution
You will need this library github.com/mattn/goveralls
The idea is to run test coverage and save it into a file, then use the above lib to post it to Coveralls.
Don’t forget to put $COVERALLS_TOKEN
in your CircleCI.
The tricky part is to find out how to save the output file and how to pick it up using goveralls
lib…
Here is the compete config.yml
version: 2.1
jobs:
build:
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run:
name: run build
command: |
go build -v
test:
working_directory: ~/test
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run:
name: run test
command: |
GO111MODULE=off go get github.com/mattn/goveralls
go test -v -cover -race -coverprofile=coverage.out
$GOPATH/bin/goveralls -coverprofile=/home/circleci/test/coverage.out -service=circle-ci -repotoken=$COVERALLS_TOKEN
workflows:
version: 2.1
build_and_test:
jobs:
- build
- test