From 3c3704fa88821c3345cbdfc8e5afafadea7cff98 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 29 Oct 2021 00:27:31 +0100 Subject: [PATCH] fix: github test workflow (#10325) ## Description Closes: #10319 @odeke-em reported that `db/memdb` doesn't build: https://github.com/cosmos/cosmos-sdk/issues/10319 The problem is not detected by the Github CI. Here we try to fix this. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- .github/workflows/test.yml | 30 ++++++++++++++++--------- scripts/module-tests.sh | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 scripts/module-tests.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 325305e4f5e4..099817208d38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,39 +38,43 @@ jobs: with: PATTERNS: | **/**.go - go.mod - go.sum + **/go.mod + **/go.sum - name: Build run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make build - test-cosmovisor: + - name: Build cosmovisor + run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make cosmovisor + + test-submodules: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2.1.4 with: go-version: 1.17 - - name: Display go version - run: go version - uses: technote-space/get-diff-action@v5 id: git_diff with: - PREFIX_FILTER: | - cosmovisor PATTERNS: | **/**.go go.mod go.sum - - name: Run cosmovisor tests - run: cd cosmovisor; make + - name: Run submodule tests and create test coverage profile. + # GIT_DIFF is passed to the scripts + run: bash scripts/module-tests.sh if: env.GIT_DIFF + - uses: actions/upload-artifact@v2 + with: + name: "${{ github.sha }}-go-submodules-coverage" + path: ./coverage-go-submod-profile.out split-test-files: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Create a file with all the pkgs - run: go list ./... > pkgs.txt + - name: Create a file with all core Cosmos SDK 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 @@ -149,6 +153,10 @@ jobs: with: name: "${{ github.sha }}-03-coverage" if: env.GIT_DIFF + - uses: actions/download-artifact@v2 + with: + name: "${{ github.sha }}-go-submodules-coverage" + if: env.GIT_DIFF - run: | cat ./*profile.out | grep -v "mode: atomic" >> coverage.txt if: env.GIT_DIFF diff --git a/scripts/module-tests.sh b/scripts/module-tests.sh new file mode 100644 index 000000000000..c34ec9106886 --- /dev/null +++ b/scripts/module-tests.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# this script is used by Github CI to tranverse all modules an run module tests. +# the script expects a diff to be generated in order to skip some modules. + +# Executes go module tests and merges the coverage profile. +# If GIT_DIFF variable is set then it's used to test if a module has any file changes - if +# it doesn't have any file changes then we will ignore the module tests. +execute_mod_tests() { + go_mod=$1; + mod_dir=$(dirname "$go_mod"); + mod_dir=${mod_dir:2}; # remove "./" prefix + root_dir=$(pwd); + + # TODO: in the future we will need to disable it once we go into multi module setup, because + # we will have cross module dependencies. + if [ -n "$GIT_DIFF" ] && ! grep $mod_dir <<< $GIT_DIFF; then + echo "ignoring module $mod_dir - no changes in the module"; + return; + fi; + + echo "executing $go_mod tests" + cd $mod_dir; + go test -mod=readonly -timeout 30m -coverprofile=${root_dir}/${coverage_file}.tmp -covermode=atomic -tags='norace ledger test_ledger_mock' ./... + local ret=$? + echo "test return: " $ret; + cd -; + # strip mode statement + tail -n +1 ${coverage_file}.tmp >> ${coverage_file} + rm ${coverage_file}.tmp; + return $ret; +} + +GIT_DIFF=`git status --porcelain` + +coverage_file=coverage-go-submod-profile.out +return_val=0; + +for f in $(find -name go.mod -not -path "./go.mod") "./container/go.mod"; do + execute_mod_tests $f; + if [[ $? -ne 0 ]] ; then + return_val=2; + fi; +done + +exit $return_val;