-
Notifications
You must be signed in to change notification settings - Fork 0
347 lines (286 loc) · 8.78 KB
/
ci.yaml
File metadata and controls
347 lines (286 loc) · 8.78 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
338
339
340
341
342
343
344
345
346
347
name: Continuous Integration
on:
push:
branches: ["main", "develop"]
pull_request:
branches: ["main", "develop"]
env:
GO_VERSION: "1.25.3"
GOLANGCI_LINT_VERSION: "v2.5.0"
jobs:
lint:
name: Lint and Vet
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Run go vet
run: go vet ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: --timeout=5m
- name: Check code formatting
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "The following files are not formatted:"
gofmt -s -l .
exit 1
fi
- name: Run security scan with govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: Run gosec security scanner
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec -fmt sarif -out gosec.sarif ./...
continue-on-error: true
- name: Upload gosec results
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: gosec.sarif
test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Run unit tests
run: make test
- name: Generate test coverage
run: |
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
build:
name: Build and Verify
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Generate code
run: make generate
- name: Generate manifests
run: make manifests
- name: Verify generated code
run: |
if ! git diff --quiet; then
echo "Generated code is out of date. Please run 'make generate' and 'make manifests'"
git diff
exit 1
fi
- name: Build operator binary
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o manager cmd/main.go
- name: Verify binary
run: |
./manager --help || true
ls -la manager
docker-build:
name: Docker Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: |
make docker-build IMG=ghcr.io/helios-operator/helios-operator:ci-${{ github.sha }}
- name: Verify Docker image
run: |
docker images | grep helios-operator
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: "-fmt sarif -out gosec.sarif ./..."
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: gosec.sarif
helm-lint:
name: Helm Chart Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: "v4.3.1"
- name: Lint Helm chart
run: |
helm lint helm/helios-operator/
- name: Template Helm chart
run: |
helm template helios-operator helm/helios-operator/ --dry-run
- name: Package Helm chart
run: |
helm package helm/helios-operator/
e2e-tests:
name: End-to-End Tests
runs-on: ubuntu-latest
needs: [lint, test, build, docker-build]
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Set up kubectl
uses: azure/setup-kubectl@v4
with:
version: "v4.0.1"
- name: Set up Minikube
uses: medyagh/setup-minikube@latest
with:
driver: docker
memory: 4096
cpus: 2
- name: Install dependencies
run: |
# Install Tekton
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
# Install ArgoCD
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm upgrade --install argocd argo/argo-cd --namespace argocd --create-namespace --wait
- name: Run E2E tests
run: |
make test-e2e
- name: Collect logs on failure
if: failure()
run: |
kubectl get pods --all-namespaces
kubectl describe pods --all-namespaces | head -1000
security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Build operator
run: make build
- name: Build Docker image
run: |
docker build -t helios-operator:latest .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "helios-operator:latest"
format: "sarif"
output: "trivy-results.sarif"
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-results.sarif"
release:
name: Create Release
runs-on: ubuntu-latest
needs:
[lint, test, build, docker-build, helm-lint, e2e-tests, security-scan]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Generate changelog
id: changelog
run: |
if [ -f CHANGELOG.md ]; then
echo "changelog<<EOF" >> $GITHUB_OUTPUT
head -50 CHANGELOG.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "changelog=No changelog available" >> $GITHUB_OUTPUT
fi
- name: Create Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.run_number }}
name: Release v${{ github.run_number }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false