-
Notifications
You must be signed in to change notification settings - Fork 1
337 lines (293 loc) · 10.3 KB
/
Copy pathCI.yaml
File metadata and controls
337 lines (293 loc) · 10.3 KB
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
name: CI
on:
push:
branches:
- main
pull_request:
merge_group:
env:
# Ensure that a cached go version is used:
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md#go
GO_VERSION: 1.26.6
GOPRIVATE: github.com/smartcontractkit/capabilities
jobs:
affected:
runs-on: ubuntu-latest
outputs:
nx: ${{ steps.affected.outputs.affected }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
# There's no need to setup Node as it is pre-installed:
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
- name: Cache NX
uses: actions/cache@v4
with:
path: |
.nx
~/.npm
key: ${{ runner.os }}-nx
# Outputs:
# {
# "base": "main",
# "projects": [
# "project_name_1",
# "project_name_2",
# ],
# "project_name_1": {
# "root": "project_1_root",
# "go_sum": "project_1_root/go.sum"
# },
# "project_name_2": {
# "root": "project_2_root",
# "go_sum": "project_2_root/go.sum"
# }
# "run_checks": true
# }
- name: Setup nodejs and install nx
uses: smartcontractkit/.github/actions/setup-nodejs@setup-nodejs/v1
- name: Get affected projects
id: affected
run: |
if [[ "${GITHUB_REF_NAME}" == "main" ]]; then
BASE="origin/main~1"
else
BASE="origin/main"
fi
echo "affected=$(./.github/scripts/affected-projects.sh $BASE)" >> $GITHUB_OUTPUT
build:
needs: affected
if: ${{fromJson(needs.affected.outputs.nx).projects_with_build != null && contains(fromJson(needs.affected.outputs.nx).projects_with_build, fromJson(needs.affected.outputs.nx).projects_with_build[0])}}
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
projects: ${{fromJson(needs.affected.outputs.nx).projects_with_build}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up project environment
uses: ./.github/actions/setup
with:
project: ${{ matrix.projects }}
go-module-file: ${{ fromJson(needs.affected.outputs.nx)[matrix.projects].go_sum }}
task: "build"
- name: Support private Go modules
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./.github/scripts/support-private-gomods.sh
- name: Build ${{ matrix.projects }}
run: ./.github/scripts/nx-run-if-exists.sh ${{ matrix.projects }} build
test:
needs: affected
if: ${{fromJson(needs.affected.outputs.nx).projects_with_test != null && contains(fromJson(needs.affected.outputs.nx).projects_with_test, fromJson(needs.affected.outputs.nx).projects_with_test[0])}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projects: ${{fromJson(needs.affected.outputs.nx).projects_with_test}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up project environment
uses: ./.github/actions/setup
with:
project: ${{ matrix.projects }}
go-module-file: ${{ fromJson(needs.affected.outputs.nx)[matrix.projects].go_sum }}
task: "test"
- name: Support private Go modules
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./.github/scripts/support-private-gomods.sh
- name: Install Solana CLI
if: matrix.projects == 'solana'
run: ./.github/scripts/install-solana-ci.sh
- name: Setup Test DB
if: matrix.projects == 'solana'
id: setup-testdb
uses: ./.github/actions/setup-testdb
- name: Unit Test solana
if: matrix.projects == 'solana'
run: ./nx run solana:test
env:
CL_DATABASE_URL: ${{ steps.setup-testdb.outputs.cl-db-url }}
- name: Unit Test ${{ matrix.projects }}
if: matrix.projects != 'solana'
run: ./nx run ${{ matrix.projects }}:test
- name: Upload Unit Tests Artifacts
if: always()
uses: actions/upload-artifact@v4.4.3
with:
# name artifacts differently per each report
name: ${{ matrix.projects }}_go_test_results
# the path to a generated report (per directory)
path: |
./${{fromJson(needs.affected.outputs.nx)[matrix.projects].root}}/coverage.txt
race:
needs: affected
if: ${{fromJson(needs.affected.outputs.nx).projects_with_race != null && contains(fromJson(needs.affected.outputs.nx).projects_with_race, fromJson(needs.affected.outputs.nx).projects_with_race[0])}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projects: ${{fromJson(needs.affected.outputs.nx).projects_with_race}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up project environment
uses: ./.github/actions/setup
with:
project: ${{ matrix.projects }}
go-module-file: ${{ fromJson(needs.affected.outputs.nx)[matrix.projects].go_sum }}
task: "race"
- name: Support private Go modules
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./.github/scripts/support-private-gomods.sh
- name: Install Solana CLI
if: matrix.projects == 'solana'
run: ./.github/scripts/install-solana-ci.sh
- name: Setup Test DB
if: matrix.projects == 'solana'
id: setup-testdb
uses: ./.github/actions/setup-testdb
- name: Race Test solana
if: matrix.projects == 'solana'
run: ./nx run solana:race
env:
CL_DATABASE_URL: ${{ steps.setup-testdb.outputs.cl-db-url }}
- name: Race Test ${{ matrix.projects }}
if: matrix.projects != 'solana'
run: ./nx run ${{ matrix.projects }}:race
integration-tests:
uses: ./.github/workflows/integration-tests.yml
tidy-and-generate:
needs: affected
if: ${{fromJson(needs.affected.outputs.nx).run_checks}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projects: ${{fromJson(needs.affected.outputs.nx).projects}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up project environment
uses: ./.github/actions/setup
with:
project: ${{ matrix.projects }}
go-module-file: ${{ fromJson(needs.affected.outputs.nx)[matrix.projects].go_sum }}
task: "tidy-and-generate"
- name: Support private Go modules
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./.github/scripts/support-private-gomods.sh
- name: Install mockery
run: go install github.com/vektra/mockery/v2/...@v2.53.5
- name: Run "tidy" and "generate"
run: |
./nx run ${{ matrix.projects }}:tidy
./.github/scripts/nx-run-if-exists.sh ${{ matrix.projects }} generate
- name: Ensure no diff
run: |
git diff
git diff --stat --exit-code
lint:
needs: affected
if: ${{fromJson(needs.affected.outputs.nx).run_checks}}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
actions: read
strategy:
fail-fast: false
matrix:
projects: ${{fromJson(needs.affected.outputs.nx).projects}}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
persist-credentials: false
- name: Set up project environment
id: setup
uses: ./.github/actions/setup
with:
project: ${{ matrix.projects }}
go-module-file: ${{ fromJson(needs.affected.outputs.nx)[matrix.projects].go_sum }}
task: "lint"
- name: Support private Go modules
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./.github/scripts/support-private-gomods.sh
- name: Get golangci-lint version from asdf
id: get-version
run: |
version=$(grep '^golangci-lint ' .tool-versions | awk '{print $2}')
echo "version=${version}" | tee -a "$GITHUB_OUTPUT"
- name: golangci-lint (${{ matrix.projects }})
uses: smartcontractkit/.github/actions/ci-lint-go@ci-lint-go/4.2.1
with:
checkout-repo: false
golangci-lint-config: ${{ github.workspace }}/.golangci.yml
golangci-lint-version: v${{ steps.get-version.outputs.version }}
go-directory: ${{fromJson(needs.affected.outputs.nx)[matrix.projects].root}}
modgraph:
runs-on: ubuntu-latest
name: modgraph
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@v5
- name: Support private Go modules
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./.github/scripts/support-private-gomods.sh
- run: make modgraph
- name: Ensure clean modgraph
run: git diff --minimal --exit-code
checks:
runs-on: ubuntu-latest
needs:
- lint
- build
- test
- race
- tidy-and-generate
- integration-tests
- modgraph
if: always()
steps:
- name: All tests ok
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
run: exit 0
- name: Some tests failed or were cancelled
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
sonarqube:
name: SonarQube Scan
needs: [test, lint]
if: ${{ always() && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- name: SonarQube Scan
uses: smartcontractkit/.github/actions/ci-sonarqube-go@5f4a9c9c3407dd499a1ebbc658a45b9beb9bf675 # v0.3.0
with:
include-lint: "true"
sonar-token: ${{ secrets.SONAR_TOKEN }}
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}