github.com/Finschia/finschia-sdk@v0.48.1/.github/workflows/test.yml (about) 1 name: Tests / Code Coverage 2 # Tests / Code Coverage workflow runs unit tests and uploads a code coverage report 3 # This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum have been changed 4 5 on: 6 pull_request: 7 push: 8 branches: 9 - main 10 - rc*/* 11 - release/* 12 jobs: 13 cleanup-runs: 14 runs-on: ubuntu-latest 15 steps: 16 - uses: rokroskar/workflow-run-cleanup-action@master 17 env: 18 GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 19 if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'" 20 21 install-tparse: 22 runs-on: ubuntu-latest 23 steps: 24 - uses: actions/setup-go@v4.0.1 25 with: 26 go-version: '1.20' 27 - name: Display go version 28 run: go version 29 - name: install tparse 30 run: | 31 go install github.com/mfridman/tparse@v0.8.3 32 - uses: actions/cache@v3.3.1 33 with: 34 path: ~/go/bin 35 key: ${{ runner.os }}-go-tparse-binary 36 37 build: 38 runs-on: ubuntu-latest 39 strategy: 40 matrix: 41 include: 42 - goarch: "amd64" 43 gcc: "gcc" 44 package: "" 45 - goarch: "arm64" 46 gcc: "aarch64-linux-gnu-gcc" 47 package: "g++-aarch64-linux-gnu" 48 steps: 49 - run: sudo apt update && sudo apt install -y ${{ matrix.package }} qemu-user-binfmt 50 if: "matrix.package != ''" 51 - uses: actions/checkout@v3 52 - uses: actions/setup-go@v4.0.1 53 with: 54 go-version: '1.20' 55 - uses: technote-space/get-diff-action@v6.1.2 56 id: git_diff 57 with: 58 PATTERNS: | 59 **/**.go 60 go.mod 61 go.sum 62 .github/workflows/test.yml 63 - name: Build 64 run: GOOS=linux CGO_ENABLED=1 GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} LEDGER_ENABLED=false make build 65 66 67 test-cosmovisor: 68 runs-on: ubuntu-latest 69 steps: 70 - uses: actions/checkout@v3 71 - uses: actions/setup-go@v4.0.1 72 with: 73 go-version: '1.20' 74 - name: Display go version 75 run: go version 76 - uses: technote-space/get-diff-action@v6.1.2 77 id: git_diff 78 with: 79 PATTERNS: | 80 **/**.go 81 go.mod 82 go.sum 83 tools/cosmovisor/** 84 - name: Run cosmovisor tests 85 run: make cosmovisor 86 if: env.GIT_DIFF 87 88 split-test-files: 89 runs-on: ubuntu-latest 90 steps: 91 - uses: actions/checkout@v3 92 - name: Create a file with all the pkgs 93 run: go list ./... > pkgs.txt 94 - name: Split pkgs into 4 files 95 run: split -d -n l/4 pkgs.txt pkgs.txt.part. 96 # cache multiple 97 - uses: actions/upload-artifact@v3 98 with: 99 name: "${{ github.sha }}-00" 100 path: ./pkgs.txt.part.00 101 - uses: actions/upload-artifact@v3 102 with: 103 name: "${{ github.sha }}-01" 104 path: ./pkgs.txt.part.01 105 - uses: actions/upload-artifact@v3 106 with: 107 name: "${{ github.sha }}-02" 108 path: ./pkgs.txt.part.02 109 - uses: actions/upload-artifact@v3 110 with: 111 name: "${{ github.sha }}-03" 112 path: ./pkgs.txt.part.03 113 114 tests: 115 runs-on: ubuntu-latest 116 needs: split-test-files 117 strategy: 118 fail-fast: false 119 matrix: 120 part: ["00", "01", "02", "03"] 121 steps: 122 - uses: actions/checkout@v3 123 - uses: actions/setup-go@v4.0.1 124 with: 125 go-version: '1.20' 126 - uses: technote-space/get-diff-action@v6.1.2 127 with: 128 PATTERNS: | 129 **/**.go 130 go.mod 131 go.sum 132 .github/workflows/test.yml 133 - uses: actions/download-artifact@v3 134 with: 135 name: "${{ github.sha }}-${{ matrix.part }}" 136 if: env.GIT_DIFF 137 - name: test & coverage report creation 138 env: 139 USE_PRELOAD: 1,4 140 SAVE_BRANCH_LAUNCH_DEPTH: 1 141 run: | 142 cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='norace ledger test_ledger_mock goleveldb' 143 if: env.GIT_DIFF 144 - uses: actions/upload-artifact@v3 145 with: 146 name: "${{ github.sha }}-${{ matrix.part }}-coverage" 147 path: ./${{ matrix.part }}profile.out 148 149 upload-coverage-report: 150 runs-on: ubuntu-latest 151 needs: tests 152 steps: 153 - uses: actions/checkout@v3 154 - uses: technote-space/get-diff-action@v6.1.2 155 with: 156 PATTERNS: | 157 **/**.go 158 go.mod 159 go.sum 160 .github/workflows/test.yml 161 - uses: actions/download-artifact@v3 162 with: 163 name: "${{ github.sha }}-00-coverage" 164 if: env.GIT_DIFF 165 - uses: actions/download-artifact@v3 166 with: 167 name: "${{ github.sha }}-01-coverage" 168 if: env.GIT_DIFF 169 - uses: actions/download-artifact@v3 170 with: 171 name: "${{ github.sha }}-02-coverage" 172 if: env.GIT_DIFF 173 - uses: actions/download-artifact@v3 174 with: 175 name: "${{ github.sha }}-03-coverage" 176 if: env.GIT_DIFF 177 - run: | 178 cat ./*profile.out | grep -v "mode: atomic" >> coverage.txt 179 if: env.GIT_DIFF 180 - name: filter out DONTCOVER 181 run: | 182 excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')" 183 excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')" 184 for filename in ${excludelist}; do 185 filename=$(echo $filename | sed 's/^./github.com\/Finschia\/finschia-sdk/g') 186 echo "Excluding ${filename} from coverage report..." 187 sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt 188 done 189 if: env.GIT_DIFF 190 - uses: codecov/codecov-action@v3.1.4 191 with: 192 token: ${{ secrets.CODECOV_TOKEN }} 193 file: ./coverage.txt 194 if: env.GIT_DIFF 195 196 test-race: 197 runs-on: ubuntu-latest 198 needs: split-test-files 199 strategy: 200 fail-fast: false 201 matrix: 202 part: ["00", "01", "02", "03"] 203 steps: 204 - uses: actions/checkout@v3 205 - uses: actions/setup-go@v4.0.1 206 with: 207 go-version: '1.20' 208 - uses: technote-space/get-diff-action@v6.1.2 209 with: 210 PATTERNS: | 211 **/**.go 212 go.mod 213 go.sum 214 .github/workflows/test.yml 215 - uses: actions/download-artifact@v3 216 with: 217 name: "${{ github.sha }}-${{ matrix.part }}" 218 if: env.GIT_DIFF 219 - name: test & coverage report creation 220 env: 221 USE_PREFETCH: NO 222 USE_PRELOAD: 1,4 223 SAVE_BRANCH_LAUNCH_DEPTH: 1 224 run: | 225 xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -timeout 30m -race -tags='cgo ledger test_ledger_mock goleveldb' 226 if: env.GIT_DIFF 227 - uses: actions/upload-artifact@v3 228 with: 229 name: "${{ github.sha }}-${{ matrix.part }}-race-output" 230 path: ./${{ matrix.part }}-race-output.txt 231 232 # TODO finschia: enable this test 233 # test-rosetta: 234 # runs-on: ubuntu-latest 235 # timeout-minutes: 10 236 # steps: 237 # - uses: actions/checkout@v2 238 # - uses: technote-space/get-diff-action@v4 239 # id: git_diff 240 # with: 241 # PATTERNS: | 242 # **/**.go 243 # go.mod 244 # go.sum 245 # - name: test rosetta 246 # run: | 247 # make test-rosetta 248 # if: env.GIT_DIFF 249 250 # TODO ebony: enable this test 251 # liveness-test: 252 # runs-on: ubuntu-latest 253 # timeout-minutes: 10 254 # steps: 255 # - uses: actions/checkout@v3 256 # - uses: actions/setup-go@v2.1.3 257 # with: 258 # go-version: '1.20' 259 # - uses: technote-space/get-diff-action@v6.1.2 260 # id: git_diff 261 # with: 262 # PATTERNS: | 263 # **/**.go 264 # go.mod 265 # go.sum 266 # - name: start localnet 267 # run: | 268 # make clean build-simd-linux localnet-start 269 # if: env.GIT_DIFF 270 # - name: test liveness 271 # run: | 272 # ./contrib/localnet_liveness.sh 100 5 50 localhost 273 # if: env.GIT_DIFF 274 275 # TODO ebony: fix module download error in docker 276 # docker-build: 277 # runs-on: ubuntu-latest 278 # timeout-minutes: 10 279 # steps: 280 # - uses: actions/checkout@v3 281 # - name: build docker image 282 # run: | 283 # docker build --pull --rm -f "Dockerfile" -t simapp:latest "."