diff --git a/.circleci/config.yml b/.circleci/config.yml index aca4dd6f..848723a8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,14 +1,37 @@ version: 2 jobs: - build: - working_directory: /go/src/github.com/opencontrol/oscalkit + test: docker: - - image: circleci/golang:1.10 + - image: circleci/golang:1.11 + working_directory: /go/src/github.com/opencontrol/oscalkit + environment: + TEST_RESULTS: /tmp/test-results steps: - checkout + - run: mkdir -p $TEST_RESULTS - restore_cache: keys: - v1-pkg-cache + - run: + name: Run unit tests + command: | + trap "go-junit-report <${TEST_RESULTS}/go-test.out > ${TEST_RESULTS}/go-test-report.xml" EXIT + make test | tee ${TEST_RESULTS}/go-test.out + - save_cache: + key: v1-pkg-cache + paths: + - "/go/pkg" + - store_artifacts: + path: /tmp/test-results + destination: raw-test-output + - store_test_results: + path: /tmp/test-results + + deploy: + docker: + - image: circleci/golang:1.11 + working_directory: /go/src/github.com/opencontrol/oscalkit + steps: - setup_remote_docker: docker_layer_caching: true - run: sudo apt-get install -y rpm @@ -19,7 +42,17 @@ jobs: if [[ -n ${CIRCLE_TAG} ]]; then curl -sL https://git.io/goreleaser | bash fi + -deployment: - trigger_tag: - tag: /.*/ +workflows: + test_and_deploy: + jobs: + - test + - deploy: + requires: + - test + filters: + tags: + only: /.*/ + branches: + only: master diff --git a/Makefile b/Makefile index 33f59b49..88d71324 100644 --- a/Makefile +++ b/Makefile @@ -28,12 +28,8 @@ generate: $(NAMESPACE)/$(REPO):generate \ sh -c "go generate" -test: generate - docker container run \ - -v $$PWD:/go/src/github.com/opencontrol/oscalkit \ - -w /go/src/github.com/opencontrol/oscalkit \ - golang:1.11 \ - sh -c "go test \$$(go list ./... | grep -v /vendor/)" +test: + @go test -v $(shell go list ./... | grep -v /vendor/) build-docker: docker image build --build-arg VERSION=$(VERSION) --build-arg BUILD=$(BUILD) --build-arg DATE=$(DATE) -t $(NAMESPACE)/$(REPO):$(VERSION)-$(BUILD) .