From dc958afc43c147b868b8d6705b42eda97c0ae070 Mon Sep 17 00:00:00 2001 From: "R.B. Boyer" Date: Mon, 2 Nov 2020 15:08:29 -0600 Subject: [PATCH] add circle --- .circleci/config.yml | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..5468b36 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,70 @@ +version: 2.1 + +references: + images: + go: &GOLANG_IMAGE circleci/golang:1.15.3 + +# reusable 'executor' object for jobs +executors: + go: + docker: + - image: *GOLANG_IMAGE + environment: + - TEST_RESULTS: /tmp/test-results # path to where test results are saved + +jobs: + go-fmt-and-vet: + executor: go + steps: + - checkout + + # Restore go module cache if there is one + - restore_cache: + keys: + - go-mod-v1-{{ checksum "go.mod" }} + + - run: go mod download + + # Save go module cache if the go.mod file has changed + - save_cache: + key: go-mod-v1-{{ checksum "go.mod" }} + paths: + - "/go/pkg/mod" + + # check go fmt output because it does not report non-zero when there are fmt changes + - run: + name: check go fmt + command: | + files=$(go fmt ./...) + if [ -n "$files" ]; then + echo "The following file(s) do not conform to go fmt:" + echo "$files" + exit 1 + fi + - run: go vet ./... + + go-test: + executor: go + steps: + - checkout + - run: mkdir -p $TEST_RESULTS + + - restore_cache: # restore cache from dev-build job + keys: + - go-mod-v1-{{ checksum "go.mod" }} + + # run go tests with gotestsum + - run: | + PACKAGE_NAMES=$(go list ./...) + gotestsum --format=short-verbose --junitfile $TEST_RESULTS/gotestsum-report.xml -- $PACKAGE_NAMES + - store_test_results: + path: /tmp/test-results + - store_artifacts: + path: /tmp/test-results + +workflows: + version: 2 + test-and-build: + jobs: + - go-fmt-and-vet + - go-test