-
Notifications
You must be signed in to change notification settings - Fork 41
225 lines (215 loc) · 9.54 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Tests / Code Coverage
# Tests / Code Coverage workflow runs unit tests and uploads a code coverage report
# This workflow is run on pushes to master & every Pull Request,
# if no *.go, go.mod or go.sum file is changed it will pass without running as these are required checks
on:
pull_request:
push:
branches:
- main
# Set concurrency for this workflow to cancel in-progress jobs if retriggered.
# The github.ref is only available when triggered by a PR so fall back to github.run_id for other cases.
# The github.run_id is unique for each run, giving each such invocation it's own unique concurrency group.
# Basically, if you push to a PR branch, jobs that are still running for that PR will be cancelled.
# But jobs started because of a merge to main or a release tag push are not cancelled.
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
jobs:
setup-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
.github/workflows/test.yml
- name: Define Variables
id: def-vars
run: |
file_prefix="${GITHUB_SHA:0:7}-${GITHUB_RUN_ATTEMPT}"
echo "Setting output: file-prefix=$file_prefix"
echo "file-prefix=$file_prefix" >> "$GITHUB_OUTPUT"
- name: Create a file with all the pkgs
run: go list ./... > pkgs.txt
- uses: actions/upload-artifact@v4
with:
name: "${{ steps.def-vars.outputs.file-prefix }}-pkgs.txt"
path: ./pkgs.txt
- name: Split pkgs into parts
# With a standard split, test-race (03) takes the longest of all these at around 6m35s.
# and test-race (00) is the shortest (of the race tests) at around 4m00s.
# The x/sanction/simulation test-race is one of the longer ones (at almost 2 minutes), and ends up in part 03.
# By forcing that one into 00, it ends up reducing the overall run-time of this whole workflow by about a minute.
# The x/marker/client/cli tests take around 30s (35s for race), and would be in 01.
# Moving it to 00 ends up leveling out the times a bit more.
run: |
grep -vF \
-e 'github.com/provenance-io/provenance/x/sanction/simulation' \
-e 'github.com/provenance-io/provenance/x/marker/client/cli' \
pkgs.txt > pkgs.txt.tmp
split -d -n l/4 pkgs.txt.tmp pkgs.txt.part.
printf '%s\n' \
'github.com/provenance-io/provenance/x/sanction/simulation' \
'github.com/provenance-io/provenance/x/marker/client/cli' \
>> pkgs.txt.part.00
- uses: actions/upload-artifact@v4
with:
name: "${{ steps.def-vars.outputs.file-prefix }}-pkgs.txt.part.00"
path: ./pkgs.txt.part.00
- uses: actions/upload-artifact@v4
with:
name: "${{ steps.def-vars.outputs.file-prefix }}-pkgs.txt.part.01"
path: ./pkgs.txt.part.01
- uses: actions/upload-artifact@v4
with:
name: "${{ steps.def-vars.outputs.file-prefix }}-pkgs.txt.part.02"
path: ./pkgs.txt.part.02
- uses: actions/upload-artifact@v4
with:
name: "${{ steps.def-vars.outputs.file-prefix }}-pkgs.txt.part.03"
path: ./pkgs.txt.part.03
outputs:
should-run: ${{ env.GIT_DIFF }}
go-version: '1.21'
file-prefix: ${{ steps.def-vars.outputs.file-prefix }}
tests:
needs: setup-tests
# Note: There's a required check on this, and it must pass. A skip doesn't count as a pass.
# So instead of a job-level if: needs.setup-tests.outputs.should-run on this job,
# it's in the steps below (except the checkout step).
strategy:
fail-fast: false
matrix:
part: ["00", "01", "02", "03"]
runs-on: ubuntu-latest
env:
LD_LIBRARY_PATH: /usr/local/lib:/usr/local/lib/x86_64-linux-gnu
steps:
- uses: actions/checkout@v4
with:
# CodeCov requires fetch-depth > 1
fetch-depth: 2
- uses: actions/setup-go@v5
if: needs.setup-tests.outputs.should-run
with:
go-version: ${{ needs.setup-tests.outputs.go-version }}
- uses: actions/download-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-pkgs.txt.part.${{ matrix.part }}"
- name: test & coverage report creation
if: needs.setup-tests.outputs.should-run
run: |
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'
- uses: actions/upload-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-${{ matrix.part }}-coverage"
path: ./${{ matrix.part }}profile.out
build-tests:
# TODO[1760]: Delete this build-tests action once the tests reliably pass again.
needs: setup-tests
strategy:
fail-fast: false
matrix:
part: ["00", "01", "02", "03"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
if: needs.setup-tests.outputs.should-run
with:
go-version: ${{ needs.setup-tests.outputs.go-version }}
- uses: actions/download-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-pkgs.txt.part.${{ matrix.part }}"
- name: build tests
if: needs.setup-tests.outputs.should-run
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -tags='norace ledger test_ledger_mock' -run='ZYX_NOPE_NOPE_XYZ'
# This action performs a code coverage assessment but filters out generated code from proto based types
# and grpc services
upload-coverage-report:
needs: [setup-tests, tests]
# Note: There's a required check on this, and it must pass. A skip doesn't count as a pass.
# So instead of a job-level if: needs.setup-tests.outputs.should-run on this job,
# it's in the steps below (except the checkout step).
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# CodeCov requires fetch-depth > 1
fetch-depth: 2
- uses: actions/download-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-00-coverage"
- uses: actions/download-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-01-coverage"
- uses: actions/download-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-02-coverage"
- uses: actions/download-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-03-coverage"
- name: Combine profiles
if: needs.setup-tests.outputs.should-run
run: |
cat ./*profile.out | grep -v "mode: atomic" >> coverage.txt
- name: filter out DONTCOVER
if: needs.setup-tests.outputs.should-run
run: |
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
excludelist+=" $(find ./ -type f -name '*.pb.go')"
excludelist+=" $(find ./ -type f -name '*.pb.gw.go')"
excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/cosmos-sdk/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
- uses: codecov/codecov-action@v4
if: needs.setup-tests.outputs.should-run
with:
file: ./coverage.txt
test-race:
needs: setup-tests
# Note: There's a required check on this, and it must pass. A skip doesn't count as a pass.
# So instead of a job-level if: needs.setup-tests.outputs.should-run on this job,
# it's in the steps below (except the checkout step).
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
part: ["00", "01", "02", "03"]
env:
LD_LIBRARY_PATH: /usr/local/lib:/usr/local/lib/x86_64-linux-gnu
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
if: needs.setup-tests.outputs.should-run
with:
go-version: ${{ needs.setup-tests.outputs.go-version }}
- uses: actions/download-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-pkgs.txt.part.${{ matrix.part }}"
- name: test & coverage report creation
if: needs.setup-tests.outputs.should-run
run: |
xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -timeout 30m -race -tags='cgo ledger test_ledger_mock' | tee ${{ matrix.part }}-race-output.txt
exit "${PIPESTATUS[0]}"
- uses: actions/upload-artifact@v4
if: needs.setup-tests.outputs.should-run
with:
name: "${{ needs.setup-tests.outputs.file-prefix }}-${{ matrix.part }}-race-output"
path: ./${{ matrix.part }}-race-output.txt