-
Notifications
You must be signed in to change notification settings - Fork 378
244 lines (237 loc) · 7.68 KB
/
ci-it.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# Copyright (c) 2021 Terminus, Inc.
#
# This program is free software: you can use, redistribute, and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# or later ("AGPL"), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
name: CI AND IT
on:
push:
tags:
- v*
branches:
- develop
- master
- release/*
paths:
- '**.go'
- '**/go.mod'
- '**/go.sum'
- '**/*.proto'
pull_request:
paths:
- '**.go'
- '**/go.mod'
- '**/go.sum'
- '**/*.proto'
jobs:
PREPARE:
runs-on: ubuntu-latest
container:
image: registry.erda.cloud/erda/gohub:1.0.9
steps:
- name: Clone repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Calculate Go Cache Path
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/cache@v3
with:
path: |
${{ steps.go-cache-paths.outputs.go-build }}
${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-4 # add '-1' to refresh cache
- name: Gen proto-go
run: |
HOME=/root make proto-go-in-local
- name: Upload proto-go As Artifact
uses: actions/upload-artifact@v3
with:
name: proto-go
path: ./api/proto-go
retention-days: 1
- name: Go generate # refresh cache
run: make prepare && go mod tidy
CI:
runs-on: ubuntu-latest
container:
image: registry.erda.cloud/erda/erda-base:20240607
needs:
- PREPARE
steps:
- name: Clone repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch proto-go
uses: actions/download-artifact@v3
with:
name: proto-go
path: ./api/proto-go
- name: Calculate Go Cache Path
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/cache@v3
with:
path: |
${{ steps.go-cache-paths.outputs.go-build }}
${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-4
restore-keys: |
${{ runner.os }}-go-
- name: Run Build
run: make build-all
CODE-CHECK:
runs-on: ubuntu-latest
container:
image: registry.erda.cloud/erda/erda-base:20240607
needs:
- PREPARE
steps:
- name: Clone repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch proto-go
uses: actions/download-artifact@v3
with:
name: proto-go
path: ./api/proto-go
- name: Calculate Go Cache Path
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/cache@v3
with:
path: |
${{ steps.go-cache-paths.outputs.go-build }}
${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-4
restore-keys: |
${{ runner.os }}-go-
- name: Go generate files # it's faster than download artifact
run: make prepare
- name: Check Go Imports
run: make check-imports
- name: Run SQL Lint
run: make miglint
- name: Run Go Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49.0
args: --timeout=30m
#skip-go-installation: true # not available in v1.49.0
#skip-cache: true # not available in v1.49.0
skip-pkg-cache: true
skip-build-cache: true
CODE-TEST:
runs-on: ubuntu-latest
container:
image: registry.erda.cloud/erda/erda-base:20240607
needs:
- PREPARE
strategy:
fail-fast: true
matrix:
package-paths:
- ./internal/pkg/... ./apistructs/... ./bundle/...
- ./pkg/...
- ./internal/tools/orchestrator/...
- ./internal/tools/pipeline/...
- ./internal/tools/cluster-manager/... ./internal/tools/cluster-agent/... ./internal/tools/cluster-ops/...
- ./internal/tools/gittar/... ./internal/tools/kms/... ./internal/tools/volume-provisioner/...
- ./internal/tools/monitor/...
- ./internal/core/...
- ./internal/apps/dop/...
- ./internal/apps/admin/... ./internal/apps/devflow/... ./internal/apps/gallery/...
- ./internal/apps/msp/...
# - ./internal/apps/cmp/...
steps:
- name: Clone repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch proto-go
uses: actions/download-artifact@v3
with:
name: proto-go
path: ./api/proto-go
- name: Calculate Go Cache Path
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/cache@v3
with:
path: |
${{ steps.go-cache-paths.outputs.go-build }}
${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-4
restore-keys: |
${{ runner.os }}-go-
- name: Go generate files
run: make prepare
- name: Gen coverage report name
shell: bash
id: cov-report-name
run: |
pkg_paths="${{ matrix.package-paths }}"
name=$(sed 's^\.\/^^g; s^\/\.\.\.^^g; s^\/^-^g; s^ ^_^g' <<< ${pkg_paths})
echo ${name}.txt
echo "::set-output name=name::coverage-${name}"
echo "::set-output name=path::coverage-${name}.txt"
- name: Run Go Test
env:
GOLANG_PROTOBUF_REGISTRATION_CONFLICT: ignore
run: |
mkdir -p ./coverage
go test -work -timeout=10s -failfast -race -cover -coverprofile=./coverage/${{ steps.cov-report-name.outputs.path }} -covermode=atomic -gcflags='-l -N' ${{ matrix.package-paths }}
- name: Upload coverage As Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.cov-report-name.outputs.name }}
path: ./coverage/${{ steps.cov-report-name.outputs.path }}
retention-days: 1
CODE-COV:
runs-on: ubuntu-latest
needs:
- CODE-TEST
steps:
- name: Clone repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download coverage reports
uses: actions/download-artifact@v3
with:
path: ./coverage/
- name: Handle coverage reports
run: |
rm -fr ./coverage/proto-go
rm -fr ./coverage/pure-coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/
fail_ci_if_error: true
flags: by-github-actions
- name: Upload combined coverage reports to artifact
uses: actions/upload-artifact@v3
with:
name: pure-coverage
path: ./coverage/
retention-days: 30