| 1 |
version: 2.1 |
| 2 |
|
| 3 |
references: |
| 4 |
images: |
| 5 |
go: &GOLANG_IMAGE circleci/golang:latest |
| 6 |
environments: |
| 7 |
tmp: &TEST_RESULTS_PATH /tmp/test-results # path to where test results are saved |
| 8 |
|
| 9 |
# reusable 'executor' object for jobs |
| 10 |
executors: |
| 11 |
go: |
| 12 |
docker: |
| 13 |
- image: *GOLANG_IMAGE |
| 14 |
environment: |
| 15 |
- TEST_RESULTS: *TEST_RESULTS_PATH |
| 16 |
|
| 17 |
jobs: |
| 18 |
go-test: |
| 19 |
executor: go |
| 20 |
steps: |
| 21 |
- checkout |
| 22 |
- run: mkdir -p $TEST_RESULTS |
| 23 |
|
| 24 |
- restore_cache: # restore cache from dev-build job |
| 25 |
keys: |
| 26 |
- go-version-modcache-v1-{{ checksum "go.mod" }} |
| 27 |
|
| 28 |
- run: go mod download |
| 29 |
|
| 30 |
# Save go module cache if the go.mod file has changed |
| 31 |
- save_cache: |
| 32 |
key: go-version-modcache-v1-{{ checksum "go.mod" }} |
| 33 |
paths: |
| 34 |
- "/go/pkg/mod" |
| 35 |
|
| 36 |
# check go fmt output because it does not report non-zero when there are fmt changes |
| 37 |
- run: |
| 38 |
name: check go fmt |
| 39 |
command: | |
| 40 |
files=$(go fmt ./...) |
| 41 |
if [ -n "$files" ]; then |
| 42 |
echo "The following file(s) do not conform to go fmt:" |
| 43 |
echo "$files" |
| 44 |
exit 1 |
| 45 |
fi |
| 46 |
|
| 47 |
# run go tests with gotestsum |
| 48 |
- run: | |
| 49 |
PACKAGE_NAMES=$(go list ./...) |
| 50 |
gotestsum --format=short-verbose --junitfile $TEST_RESULTS/gotestsum-report.xml -- $PACKAGE_NAMES |
| 51 |
- store_test_results: |
| 52 |
path: *TEST_RESULTS_PATH |
| 53 |
- store_artifacts: |
| 54 |
path: *TEST_RESULTS_PATH |
| 55 |
|
| 56 |
workflows: |
| 57 |
version: 2 |
| 58 |
test-and-build: |
| 59 |
jobs: |
| 60 |
- go-test |