Repository navigation
83 lines (69 loc) · 2.34 KB
/
Copy pathtest.yml
File metadata and controls
83 lines (69 loc) · 2.34 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
name: Plexaubnet Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
name: Plexaubnet Tests (Go 1.24)
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go 1.24.2
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
check-latest: true
cache: true
- name: Install setup-envtest and download binaries
id: setup-envtest
run: |
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
ENVTEST_VERSION=1.32
echo "KUBEBUILDER_ASSETS=$(setup-envtest use ${ENVTEST_VERSION} -p path)" >> $GITHUB_ENV
- name: Run tests
run: |
make test
env:
KUBEBUILDER_ASSETS: ${{ env.KUBEBUILDER_ASSETS }}
- name: Run tests with race detector
run: |
make test-race
env:
KUBEBUILDER_ASSETS: ${{ env.KUBEBUILDER_ASSETS }}
- name: Generate coverage report
run: |
make coverage
env:
KUBEBUILDER_ASSETS: ${{ env.KUBEBUILDER_ASSETS }}
- name: Check coverage threshold
run: |
# Get total coverage
COVERAGE=$(go tool cover -func=coverage.out | grep total: | awk '{print $3}' | sed 's/%//')
echo "Total coverage: ${COVERAGE}%"
# Compare with threshold (60%)
THRESHOLD=60
if (( $(echo "$COVERAGE < $THRESHOLD" | awk '{print ($1 < $3)}') )); then
echo "Error: Coverage ${COVERAGE}% is below the threshold of ${THRESHOLD}%"
exit 1
fi
echo "Coverage check passed: ${COVERAGE}% >= ${THRESHOLD}%"
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.os }}
path: coverage.html
if-no-files-found: error
- name: Check for flaky tests
run: |
echo "::notice::Running flaky test detection..."
# Using -count=5 to detect timing dependencies in asynchronous tests
# If errors occur, it's recommended to create a GitHub issue for flaky tests
go test -count=5 ./internal/controller/... || echo "::warning::Potential flaky tests detected, consider creating a GitHub issue"
env:
KUBEBUILDER_ASSETS: ${{ env.KUBEBUILDER_ASSETS }}