-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadaptivetelemetryprocessor-tests.yml
More file actions
190 lines (154 loc) · 6.07 KB
/
adaptivetelemetryprocessor-tests.yml
File metadata and controls
190 lines (154 loc) · 6.07 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
name: AdaptiveTelemetryProcessor Tests
on:
pull_request:
paths:
- 'processor/adaptivetelemetryprocessor/**'
- '.github/workflows/adaptivetelemetryprocessor-tests.yml'
push:
branches: [main]
paths:
- 'processor/adaptivetelemetryprocessor/**'
permissions:
contents: read
pull-requests: write
env:
MIN_COVERAGE: 75
jobs:
test-and-coverage:
name: Test with Coverage
runs-on: ubuntu-24.04
if: ${{ github.actor != 'dependabot[bot]' }}
defaults:
run:
working-directory: processor/adaptivetelemetryprocessor
steps:
- name: Checkout code
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
- name: Set up Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6
with:
go-version: oldstable
cache-dependency-path: "processor/adaptivetelemetryprocessor/go.sum"
- name: Download dependencies
run: go mod download
- name: Run tests with coverage
run: |
go test -v -race -coverprofile=coverage.out -covermode=atomic ./... 2>&1 | tee test-output.txt
echo "TEST_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV
- name: Check test results
run: |
if [ "$TEST_EXIT_CODE" != "0" ]; then
echo "❌ Tests failed!"
exit 1
fi
echo "✅ All tests passed!"
- name: Generate coverage report
run: |
go tool cover -func=coverage.out | tee coverage-summary.txt
# Extract total coverage percentage
COVERAGE=$(go tool cover -func=coverage.out | grep total: | awk '{print $3}' | sed 's/%//')
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
echo "Total coverage: $COVERAGE%"
- name: Check coverage threshold
run: |
echo "📊 Coverage: ${{ env.COVERAGE }}%"
echo "📏 Minimum required: ${{ env.MIN_COVERAGE }}%"
# Use bc for floating point comparison
if (( $(echo "${{ env.COVERAGE }} < ${{ env.MIN_COVERAGE }}" | bc -l) )); then
echo ""
echo "❌ Coverage is below the minimum threshold!"
echo ""
echo "Current coverage: ${{ env.COVERAGE }}%"
echo "Required minimum: ${{ env.MIN_COVERAGE }}%"
echo ""
echo "Please add more tests to increase coverage."
exit 1
else
echo ""
echo "✅ Coverage meets the minimum threshold!"
fi
- name: Generate HTML coverage report
if: always()
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage artifacts
if: always()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: coverage-report
path: |
processor/adaptivetelemetryprocessor/coverage.out
processor/adaptivetelemetryprocessor/coverage.html
processor/adaptivetelemetryprocessor/coverage-summary.txt
retention-days: 30
- name: Add coverage comment to PR
if: github.event_name == 'pull_request'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const fs = require('fs');
const coverageSummary = fs.readFileSync('processor/adaptivetelemetryprocessor/coverage-summary.txt', 'utf8');
const coverage = process.env.COVERAGE;
const minCoverage = process.env.MIN_COVERAGE;
const status = parseFloat(coverage) >= parseFloat(minCoverage) ? '✅' : '❌';
const body = `## 📊 AdaptiveTelemetryProcessor Coverage Report
| Metric | Value |
|--------|-------|
| **Total Coverage** | ${status} ${coverage}% |
| **Minimum Required** | ${minCoverage}% |
<details>
<summary>📋 Detailed Coverage by Function</summary>
\`\`\`
${coverageSummary}
\`\`\`
</details>
---
*Coverage report generated by [adaptivetelemetryprocessor-tests.yml](/.github/workflows/adaptivetelemetryprocessor-tests.yml)*`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('AdaptiveTelemetryProcessor Coverage Report')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
# Cross-platform tests to ensure compatibility
test-cross-platform:
name: Test on ${{ matrix.os }}
needs: test-and-coverage
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: processor/adaptivetelemetryprocessor
steps:
- name: Checkout code
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
- name: Set up Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6
with:
go-version: oldstable
cache-dependency-path: "processor/adaptivetelemetryprocessor/go.sum"
- name: Download dependencies
run: go mod download
- name: Run tests
run: go test -v -race ./...