.circleci: build: save go cache

This commit is contained in:
Yousong Zhou
2019-07-03 10:51:47 +00:00
parent 62621d461d
commit 9896ac1bec
3 changed files with 56 additions and 24 deletions
+24 -4
View File
@@ -6,6 +6,8 @@ jobs:
build:
docker:
- image: yunionio/onecloud-ci:v1.0.2
environment:
ONECLOUD_CI_BUILD: "1"
#### TEMPLATE_NOTE: go expects specific checkout path representing url
#### expecting it in the form of
@@ -15,27 +17,45 @@ jobs:
parallelism: 4
steps:
- checkout
- restore_cache:
key: onecloud-build-cache-{{ checksum "go.mod" }}-{{ checksum "Makefile" }}
paths:
- /home/build/.cache/go-build
- run:
command: |
targets="$(circleci tests glob "cmd/*" | grep -v cmd/host-image | circleci tests split)"
echo $targets | tr ' ' '\n'
make $targets
ls -lh _output/bin/
- save_cache:
key: onecloud-build-cache-{{ checksum "go.mod" }}-{{ checksum "Makefile" }}
paths:
- /home/build/.cache/go-build
- store_artifacts:
path: _output/
test:
docker:
- image: yunionio/onecloud-ci:v1.0.2
environment:
GO111MODULE: "on"
working_directory: /home/build/go/src/yunion.io/x/onecloud
steps:
- checkout
- restore_cache:
key: onecloud-test-cache-{{ checksum "go.mod" }}-{{ checksum "Makefile" }}
paths:
- /home/build/.cache/go-build
- run:
name: unit_test
command: make test
- run:
name: generate_code_coverage
command: ./scripts/coverage.sh --codecov
command: |
pkgs="$((go list -mod vendor ./... || true) | grep -vE '/(host-image|hostimage)\>' | circleci tests split)"
go test -v -mod vendor -ldflags '-w' $pkgs
pkgs="$pkgs" ./scripts/coverage.sh --codecov
- save_cache:
key: onecloud-test-cache-{{ checksum "go.mod" }}-{{ checksum "Makefile" }}
paths:
- /home/build/.cache/go-build
workflows:
version: 2
+15 -7
View File
@@ -7,11 +7,19 @@ BUILD_DIR := $(ROOT_DIR)/_output
BIN_DIR := $(BUILD_DIR)/bin
BUILD_SCRIPT := $(ROOT_DIR)/build/build.sh
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_VERSION := $(shell git describe --tags --abbrev=14 $(GIT_COMMIT)^{commit})
GIT_TREE_STATE := $(shell s=`git status --porcelain 2>/dev/null`; if [ -z "$$s" ]; then echo "clean"; else echo "dirty"; fi)
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
ifeq ($(ONECLOUD_CI_BUILD),)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_VERSION := $(shell git describe --tags --abbrev=14 $(GIT_COMMIT)^{commit})
GIT_TREE_STATE := $(shell s=`git status --porcelain 2>/dev/null`; if [ -z "$$s" ]; then echo "clean"; else echo "dirty"; fi)
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
else
GIT_COMMIT:=x
GIT_BRANCH:=x
GIT_VERSION:=x
BUILD_TREE_STATE:=clean
BUILD_DATE=2099-07-01T07:11:09Z
endif
LDFLAGS := "-w \
-X $(VERSION_PKG).gitVersion=$(GIT_VERSION) \
@@ -104,8 +112,8 @@ clean:
fmt:
@find . -type f -name "*.go" -not -path "./_output/*" \
-not -path "./vendor/*" | xargs gofmt -s -w
@$(if $(ONECLOUD_CI_BUILD),:,find) . -type f -name "*.go" -not -path "./_output/*" \
-not -path "./vendor/*" | xargs --no-run-if-empty gofmt -s -w
define depDeprecated
OneCloud now requires using go-mod for dependency management. dep target,
+17 -13
View File
@@ -14,18 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
covermode=${COVERMODE:-atomic}
coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX)
profile="${coverdir}/profile.out"
function get_test_pkgs() {
go list ./... | egrep -v 'host-image|hostimage'
}
function generate_coverage_data() {
echo "mode: $covermode" > "$profile"
go test -coverprofile="$profile" -covermode="$covermode" $(get_test_pkgs)
}
set -o errexit
set -o pipefail
function push_to_codecov() {
if [ -z "$CODECOV_TOKEN" ]; then
@@ -36,7 +26,21 @@ function push_to_codecov() {
curl -s https://codecov.io/bash | bash -s -- -c -F aFlag -f "$profile"
}
generate_coverage_data
covermode=${COVERMODE:-atomic}
coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX)
profile="${coverdir}/profile.out"
if [ -z "$pkgs" ]; then
pkgs="$(go list ./... | egrep -v 'host-image|hostimage')"
fi
echo "mode: $covermode" >"$profile"
go test -v \
-coverprofile="$profile" \
-covermode="$covermode" \
-mod vendor \
-ldflags '-w' \
$pkgs
go tool cover -func "$profile"
case "${1-}" in