From b3be1d7d7a1e5c8fef96e964c52aa1a3b502f734 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Thu, 2 Dec 2021 16:22:27 -0500 Subject: [PATCH] ci: move test execution to makefile (#7372) --- .github/workflows/coverage.yml | 42 ++++------------------------------ Makefile | 23 +++++++++++++++++-- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 491836106..960598ad6 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.4.0 - - 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 15m -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 d091b9d48..851521d5b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ #!/usr/bin/make -f -PACKAGES=$(shell go list ./...) BUILDDIR ?= $(CURDIR)/build BUILD_TAGS?=tendermint @@ -103,7 +102,7 @@ install_abci: .PHONY: install_abci ############################################################################### -### Privval Server ### +### Privval Server ### ############################################################################### build_privval_server: @@ -288,3 +287,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