From 5493e06a2dbda370a8bbac2c25df1a8eef73cc78 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Mon, 22 Jun 2020 20:32:31 +0200 Subject: [PATCH] feat: add report-ci --- .github/workflows/ci.yml | 14 ++++++++++++-- .gitignore | 6 ++++++ rules.mk | 28 +++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a06b21..de6543f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -132,14 +132,14 @@ jobs: restore-keys: | ${{ runner.os }}-go-${{ matrix.golang }}- - name: Compile the project - run: make go.install + run: make go.install CI=true - name: Check go.mod and go.sum run: | go mod tidy -v git --no-pager diff go.mod go.sum git --no-pager diff --quiet go.mod go.sum - name: Run tests on Unix-like operating systems - run: make unittest + run: make unittest CI=true - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: @@ -149,3 +149,13 @@ jobs: env_vars: OS,GOLANG name: codecov-umbrella fail_ci_if_error: true + - name: Upload to Report.ci + if: always() && matrix.golang == 1.14 + env: + REPORT_CI_TOKEN: ${{ secrets.REPORT_CI_TOKEN }} + run: | + ls -la go-install.log go-build.log go-test.json || true + # merge build logs + (cat go-install.log go-build.log > go-annotate.log) || true + curl -s https://report.ci/annotate.py | python - --input="go-annotate.log" --tool=go || true + curl -s https://report.ci/upload.py | python - --include="go-test.json" --framework=go || true diff --git a/.gitignore b/.gitignore index 53b035e..898c062 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,15 @@ +go-test.json + # Temporary files *~ *# .#* coverage.txt +go-build.log +go-install.log +go-test.json + # Vendors package-lock.json node_modules/ diff --git a/rules.mk b/rules.mk index 9ff2c02..70fad4d 100644 --- a/rules.mk +++ b/rules.mk @@ -72,14 +72,26 @@ GO_INSTALL_OPTS ?= GO_TEST_OPTS ?= -test.timeout=30s GOMOD_DIR ?= . GOCOVERAGE_FILE ?= ./coverage.txt +GOTESTJSON_FILE ?= ./go-test.json +GOBUILDLOG_FILE ?= ./go-build.log +GOINSTALLLOG_FILE ?= ./go-install.log ifdef GOBINS .PHONY: go.install go.install: +ifeq ($(CI),true) + @rm -f /tmp/goinstall.log + @set -e; for dir in $(GOBINS); do ( set -xe; \ + cd $$dir; \ + $(GO) install -v $(GO_INSTALL_OPTS) .; \ + ); done 2>&1 | tee $(GOINSTALLLOG_FILE) + +else @set -e; for dir in $(GOBINS); do ( set -xe; \ cd $$dir; \ $(GO) install $(GO_INSTALL_OPTS) .; \ ); done +endif INSTALL_STEPS += go.install .PHONY: go.release @@ -92,15 +104,29 @@ endif .PHONY: go.unittest go.unittest: +ifeq ($(CI),true) + @echo "mode: atomic" > /tmp/gocoverage + @rm -f $(GOTESTJSON_FILE) + @set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do (set -e; (set -euf pipefail; \ + cd $$dir; \ + ($(GO) test ./... $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race -json | tee -a $(GOTESTJSON_FILE) 3>&1 1>&2 2>&3 | tee -a $(GOBUILDLOG_FILE); \ + ); \ + if [ -f /tmp/profile.out ]; then \ + cat /tmp/profile.out | sed "/mode: atomic/d" >> /tmp/gocoverage; \ + rm -f /tmp/profile.out; \ + fi)); done + @mv /tmp/gocoverage $(GOCOVERAGE_FILE) +else @echo "mode: atomic" > /tmp/gocoverage @set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do (set -e; (set -xe; \ cd $$dir; \ - $(GO) test $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...); \ + $(GO) test ./... $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race); \ if [ -f /tmp/profile.out ]; then \ cat /tmp/profile.out | sed "/mode: atomic/d" >> /tmp/gocoverage; \ rm -f /tmp/profile.out; \ fi); done @mv /tmp/gocoverage $(GOCOVERAGE_FILE) +endif .PHONY: go.checkdoc go.checkdoc: