-
Notifications
You must be signed in to change notification settings - Fork 271
280 lines (261 loc) · 10.9 KB
/
github-actions.yml
File metadata and controls
280 lines (261 loc) · 10.9 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
name: checks
env:
GO_VERSION: '1.26'
on:
pull_request:
branches:
- master
- stable/**
push:
branches:
- master
- stable/**
permissions:
pull-requests: write
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
base-ref:
name: base-ref
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Check base ref
# Validates the latest commit on the PR base branch (e.g. master), not PR commits.
# Use subject only: full bodies often use markdown bullets (* item), which would
# false-positive the "squash style" rule below.
# Case-insensitive matches for:
# 1. Jira references (trid-12345)
# 2. PR numbers (#1234)
# 3. GitHub squash-merge footer lines: "* ... (7-40 hex sha)" — not plain bullets like "* First pass"
run: |
git log --format=%B -n 1 | \
perl -ne 'die "Base ref has invalid commit message" if (/(?:trid|astractl)(?: |-)\d+/ig || /#\d+/ig || /^\* .*\([0-9a-f]{7,40}\)\s*$/i)'
golangci:
name: linters
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- uses: actions/checkout@v4
- name: golangci-lint
# Switch back to the official action after this bug is fixed: https://github.com/golangci/golangci-lint/issues/3107
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.11.4
$(go env GOPATH)/bin/golangci-lint run --output.text.path=github-actions --timeout=15m --verbose
go-mod-tidy:
name: go mod tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: Run go mod tidy
run: |
go mod tidy -compat=$GO_VERSION
git diff --exit-code go.mod go.sum
unit:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
runs-on: ${{matrix.os}}
name: unit tests ${{ matrix.os }}
steps:
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- if: runner.os == 'Windows'
name: Run the tests (on Windows)
run: |
Set-PSDebug -Trace 2
go version
mkdir ${{ runner.temp }}\${{ runner.os }}-coverage-binary.out
go test -v ./... -covermode=count -- -test.gocoverdir=${{ runner.temp }}\${{ runner.os }}-coverage-binary.out
go tool covdata textfmt -i=${{ runner.temp }}\${{ runner.os }}-coverage-binary.out -o ${{ runner.os }}-coverage.out
- if: runner.os == 'Linux'
name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@v1.3.1
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: true
- if: runner.os != 'Windows'
name: Run the tests (not on Windows)
run: |
set -x
go version
echo mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
go test -v ./... -covermode=count -test.gocoverdir=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
go tool covdata textfmt -i=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out -o ${{ runner.os }}-coverage.out
- if: runner.os != 'Windows'
name: Prepare the artifact
run: |
go tool cover -html=${{ runner.os }}-coverage.out -o ${{ runner.os }}-coverage.html
- name: Get run details
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "PR_Title=$PR_TITLE"
echo "Run_Number=${{ github.run_number }}"
echo "PR_Number=${{ github.event.pull_request.number }}"
- if: runner.os != 'Windows'
name: Upload the artifact
uses: actions/upload-artifact@v4
with:
name: "coverage-report-${{ runner.os }}-${{ github.run_number }}.html"
path: ${{ runner.os }}-coverage.html
coveragecomment:
name: UT Code Coverage Report
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Golang for unit test
uses: actions/setup-go@v5
with:
go-version-file: "${{ github.workspace }}/go.mod"
cache: false
- name: Install dependencies
run: |
go install github.com/boumenot/gocover-cobertura@latest
# ToDo: run tests in /cmd directory
- name: Run the tests (not on Windows)
run: |
set -x
go version
# Define packages to exclude
EXCLUDE_PACKAGES=(
"client/clientset" # Auto-generated client code
"client/informers" # Auto-generated informer code
"client/listers" # Auto-generated lister code
"storage/external_test" # Test code, excluded from production
"ontap/api/azgo" # Auto-generated code for ONTAP API (AZGO)
"ontap/api/rest" # Auto-generated code for ONTAP REST API
"astrads/api/v1alpha1" # Exclude deprecated AstraDS
"fake" # Mock code for testing purposes
"github.com/netapp/trident/mocks/" # Mock code for unit tests
"github.com/netapp/trident/operator/controllers/provisioner" # Auto-generated operator code
"github.com/netapp/trident/operator/controllers/provisioner/apis/netapp/v1" # Auto-generated API definitions
"github.com/netapp/trident/storage_drivers/astrads/api/v1beta1" # Exclude deprecated AstraDS
)
# Build regex pattern from exclusion list
EXCLUDE_REGEX=$(IFS="|"; echo "${EXCLUDE_PACKAGES[*]}")
# Run tests excluding the specified packages
echo mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
go test $(go list ./... | grep -Ev "$EXCLUDE_REGEX") -v -coverprofile=${{ runner.os }}-coverage.out
grep -v "zz_generated.deepcopy.go" ${{ runner.os }}-coverage.out > ${{ runner.os }}-coverage_filtered.out
# Display coverage using go tool cover (same as Makefile)
OVERALL_COVERAGE=$(go tool cover -func=${{ runner.os }}-coverage_filtered.out | grep total | awk '{print $3}')
echo "Overall coverage (go tool cover): $OVERALL_COVERAGE"
- name: Convert Go coverage to Cobertura XML
run: |
# Use the more actively maintained gocover-cobertura fork with file exclusions
# Exclude patterns: auto-generated files, mocks, test utilities
gocover-cobertura \
-ignore-files '.*zz_generated.*\.go$' \
-ignore-files '.*\/fake\/.*\.go$' \
-ignore-files '.*\/mocks\/.*\.go$' \
-ignore-files '.*_test\.go$' \
-ignore-files '.*\/testutils\/.*\.go$' \
< ${{ runner.os }}-coverage_filtered.out > cobertura-coverage.xml
- name: Summarize code coverage
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: cobertura-coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_complexity: true
indicators: false
output: both
thresholds: '75 100'
- name: Ensure coverage report is writable
run: |
if [[ -f code-coverage-results.md ]] && [[ ! -w code-coverage-results.md ]]; then
sudo chown "$(id -un):$(id -gn)" code-coverage-results.md
fi
- name: Wrap full coverage report in collapsible <details>
run: |
set -euo pipefail
if [[ ! -f code-coverage-results.md ]]; then
echo "::error::code-coverage-results.md not found; cannot wrap coverage output."
exit 1
fi
python3 << 'PY'
import html
import re
from pathlib import Path
path = Path("code-coverage-results.md")
text = path.read_text(encoding="utf-8").rstrip()
def line_rate_pct(src: str):
m = re.search(r"Code%20Coverage-(\d+(?:\.\d+)?)%25", src)
if m:
return m.group(1) + "%"
m = re.search(
r"\*\*Summary\*\*\s*\|\s*\*\*(\d+(?:\.\d+)?)%", src, re.I
)
if m:
return m.group(1) + "%"
return None
pct = line_rate_pct(text)
if pct:
summary = f"Code coverage report ({pct} line rate) - click to expand"
else:
summary = "Code coverage report - click to expand"
wrapped = (
"<details>\n<summary>"
+ html.escape(summary)
+ "</summary>\n\n"
+ text
+ "\n</details>\n"
)
path.write_text(wrapped, encoding="utf-8")
PY
- name: Add coverage PR comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Upload coverage as artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: code-coverage
path: |
${{ runner.os }}-coverage_filtered.out
cobertura-coverage.xml
code-coverage-results.md
retention-days: 5