-
Notifications
You must be signed in to change notification settings - Fork 0
307 lines (264 loc) · 9.74 KB
/
build.yml
File metadata and controls
307 lines (264 loc) · 9.74 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
name: Build & Test
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'src/**'
- 'go.mod'
- 'go.sum'
- '.golangci.yml'
- '.github/workflows/build.yml'
pull_request:
branches: [ main ]
paths:
- 'src/**'
- 'go.mod'
- 'go.sum'
- '.golangci.yml'
- '.github/workflows/build.yml'
permissions:
contents: read
checks: write # Required for golangci-lint annotations
jobs:
golangci-lint:
name: Lint (${{ matrix.goos }})
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin, windows]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.6.2
working-directory: src
args: --timeout=5m --config=../.golangci.yml
env:
GOOS: ${{ matrix.goos }}
- name: Verify no linting issues
if: success()
run: echo "✅ All linting checks passed for ${{ matrix.goos }} (errcheck, govet, ineffassign, unused, misspell, dupl, goconst, gocyclo, errorlint)"
go-mod:
name: Dependencies Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Check go.mod and go.sum are tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum
if [ $? -ne 0 ]; then
echo "❌ go.mod or go.sum is not tidy"
echo "Please run: go mod tidy"
exit 1
fi
echo "✅ go.mod and go.sum are tidy"
race-detection:
name: Race Detection
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Get dependencies
run: go mod download
- name: Run tests with race detector
run: |
echo "Running tests with Go race detector enabled..."
echo "This detects data races in concurrent code (requires cgo)"
go test -race -v ./src/... 2>&1 | tee race-test-output.log
TEST_EXIT_CODE=${PIPESTATUS[0]}
exit $TEST_EXIT_CODE
- name: Generate race detection summary
if: always()
run: |
echo "## Race Detection Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if grep -q "WARNING: DATA RACE" race-test-output.log 2>/dev/null; then
echo "❌ **Data races detected!**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Race Details" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
grep -A 50 "WARNING: DATA RACE" race-test-output.log >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "✅ **No data races detected**" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>Full Test Output</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat race-test-output.log >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
build:
needs: [golangci-lint, go-mod, race-detection]
name: Build ${{ matrix.platform }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Linux - current
- os: ubuntu-latest # Ubuntu 22.04
goos: linux
goarch: amd64
platform: linux-amd64
# macOS Intel - current
- os: macos-latest # macOS 12
goos: darwin
goarch: amd64
platform: macos-amd64
# macOS ARM - current
- os: macos-latest # macOS 12
goos: darwin
goarch: arm64
platform: macos-arm64
# Windows - current
- os: windows-latest # Windows Server 2022
goos: windows
goarch: amd64
platform: windows-amd64
- os: windows-latest # Windows Server 2022
goos: windows
goarch: arm64
platform: windows-arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true # Explicitly enable caching (suppresses some warnings)
- name: Get dependencies
run: go mod download
- name: Build main CLI
run: |
go build -v -ldflags="-s -w" -o dist/dtvem${{ matrix.goos == 'windows' && '.exe' || '' }} ./src
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
- name: Build shim executable
run: |
go build -v -ldflags="-s -w" -o dist/dtvem-shim${{ matrix.goos == 'windows' && '.exe' || '' }} ./src/cmd/shim
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
- name: Verify build - Check version
if: matrix.platform != 'windows-arm64'
run: |
./dist/dtvem${{ matrix.goos == 'windows' && '.exe' || '' }} version
shell: bash
- name: Verify build - Check help
if: matrix.platform != 'windows-arm64'
run: |
./dist/dtvem${{ matrix.goos == 'windows' && '.exe' || '' }} help
shell: bash
- name: Run tests with coverage
run: |
# Run tests with coverage and capture output (from root, test src packages)
go test -v -coverprofile=coverage.out -covermode=atomic ./src/... 2>&1 | tee test-output.log
TEST_EXIT_CODE=${PIPESTATUS[0]}
# Generate HTML coverage report
go tool cover -html=coverage.out -o coverage.html
# Exit with test result code
exit $TEST_EXIT_CODE
shell: bash
- name: Generate test summary
if: always()
run: |
echo "## Test Results - ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Check if test output file exists
if [ ! -f test-output.log ]; then
echo "⚠️ Test output file not found" >> $GITHUB_STEP_SUMMARY
exit 0
fi
# Count individual test results (not packages)
# grep -c returns a number or fails; capture and sanitize
PASS_COUNT=$(grep -c "^--- PASS:" test-output.log 2>/dev/null) || PASS_COUNT=0
FAIL_COUNT=$(grep -c "^--- FAIL:" test-output.log 2>/dev/null) || FAIL_COUNT=0
SKIP_COUNT=$(grep -c "^--- SKIP:" test-output.log 2>/dev/null) || SKIP_COUNT=0
# Sanitize: take only the first number, remove any extra characters
PASS_COUNT=$(echo "$PASS_COUNT" | head -n1 | tr -cd '0-9')
FAIL_COUNT=$(echo "$FAIL_COUNT" | head -n1 | tr -cd '0-9')
SKIP_COUNT=$(echo "$SKIP_COUNT" | head -n1 | tr -cd '0-9')
# Default to 0 if empty after sanitization
PASS_COUNT=${PASS_COUNT:-0}
FAIL_COUNT=${FAIL_COUNT:-0}
SKIP_COUNT=${SKIP_COUNT:-0}
# Calculate total
TOTAL_COUNT=$((PASS_COUNT + FAIL_COUNT + SKIP_COUNT))
if [ "$FAIL_COUNT" = "0" ]; then
echo "✅ **All tests passed!**" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Some tests failed**" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "- 📊 Total: $TOTAL_COUNT test(s)" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Passed: $PASS_COUNT test(s)" >> $GITHUB_STEP_SUMMARY
echo "- ❌ Failed: $FAIL_COUNT test(s)" >> $GITHUB_STEP_SUMMARY
if [ "$SKIP_COUNT" != "0" ]; then
echo "- ⏭️ Skipped: $SKIP_COUNT test(s)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
# Show test details
echo "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>Test Output</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
tail -100 test-output.log >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Generate coverage report
run: |
# Calculate total coverage percentage
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}')
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
# Generate summary
echo "## Test Coverage Report - ${{ matrix.platform }}" > coverage-summary.md
echo "" >> coverage-summary.md
echo "**Total Coverage:** \`$COVERAGE\`" >> coverage-summary.md
echo "" >> coverage-summary.md
echo "### Coverage by Package" >> coverage-summary.md
echo '```' >> coverage-summary.md
go tool cover -func=coverage.out | grep -v "total:" >> coverage-summary.md
echo '```' >> coverage-summary.md
echo "" >> coverage-summary.md
echo "📊 Full HTML coverage report available in workflow artifacts" >> coverage-summary.md
shell: bash
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.os }}-${{ matrix.platform }}
path: |
coverage.out
coverage.html
coverage-summary.md
retention-days: 30
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dtvem-${{ matrix.os }}-${{ matrix.platform }}
path: |
dist/dtvem*
retention-days: 7