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