diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4a3b89074..b4d4496fd 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -9,32 +9,6 @@ on: - release/** jobs: - split-test-files: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2.3.4 - - name: Create a file with all the pkgs - run: go list ./... > pkgs.txt - - name: Split pkgs into 4 files - run: split -d -n l/4 pkgs.txt pkgs.txt.part. - # cache multiple - - uses: actions/upload-artifact@v2 - with: - name: "${{ github.sha }}-00" - path: ./pkgs.txt.part.00 - - uses: actions/upload-artifact@v2 - with: - name: "${{ github.sha }}-01" - path: ./pkgs.txt.part.01 - - uses: actions/upload-artifact@v2 - with: - name: "${{ github.sha }}-02" - path: ./pkgs.txt.part.02 - - uses: actions/upload-artifact@v2 - with: - name: "${{ github.sha }}-03" - path: ./pkgs.txt.part.03 - build-linux: name: Build runs-on: ubuntu-latest @@ -55,13 +29,13 @@ jobs: "!test/" go.mod go.sum + Makefile - name: install run: GOOS=linux GOARCH=${{ matrix.goarch }} make build if: "env.GIT_DIFF != ''" tests: runs-on: ubuntu-latest - needs: split-test-files strategy: fail-fast: false matrix: @@ -78,22 +52,15 @@ jobs: "!test/" go.mod go.sum - - uses: actions/download-artifact@v2 - with: - name: "${{ github.sha }}-${{ matrix.part }}" - if: env.GIT_DIFF - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: "1.17" + Makefile - name: test & coverage report creation run: | - cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 8m -race -coverprofile=${{ matrix.part }}profile.out + make test-group-${{ matrix.part }} NUM_SPLIT=4 if: env.GIT_DIFF - uses: actions/upload-artifact@v2 with: name: "${{ github.sha }}-${{ matrix.part }}-coverage" - path: ./${{ matrix.part }}profile.out + path: ./build/${{ matrix.part }}.profile.out upload-coverage-report: runs-on: ubuntu-latest @@ -107,6 +74,7 @@ jobs: "!test/" go.mod go.sum + Makefile - uses: actions/download-artifact@v2 with: name: "${{ github.sha }}-00-coverage" diff --git a/Makefile b/Makefile index 73ab548f1..1176ea844 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ #!/usr/bin/make -f -PACKAGES=$(shell go list ./...) BUILDDIR ?= $(CURDIR)/build BUILD_TAGS?=tendermint @@ -122,7 +121,7 @@ install_abci: .PHONY: install_abci ############################################################################### -### Privval Server ### +### Privval Server ### ############################################################################### build_privval_server: @@ -307,3 +306,23 @@ build-reproducible: --name latest-build cosmossdk/rbuilder:latest docker cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/ .PHONY: build-reproducible + +# Implements test splitting and running. This is pulled directly from +# the github action workflows for better local reproducibility. + +GO_TEST_FILES != find $(CURDIR) -name "*_test.go" + +# default to four splits by default +NUM_SPLIT ?= 4 + +$(BUILDDIR): + mkdir -p $@ + +# the format statement filters out all packages that don't have tests. +$(BUILDDIR)/packages.txt:$(GO_TEST_FILES) $(BUILDDIR) + go list -f "{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}" ./... | sort > $@ + +split-test-packages:$(BUILDDIR)/packages.txt + split -d -n l/$(NUM_SPLIT) $< $<. +test-group-%:split-test-packages + cat $(BUILDDIR)/packages.txt.$* | xargs go test -mod=readonly -timeout=15m -race -coverprofile=$(BUILDDIR)/$*.profile.out