-
Notifications
You must be signed in to change notification settings - Fork 3
219 lines (196 loc) · 7.37 KB
/
vstar-UT.yml
File metadata and controls
219 lines (196 loc) · 7.37 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
# This workflow will build a Java project with Ant and run VStar's unit tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-ant
name: VStar Unit Tests
on:
push:
branches:
- "**"
pull_request:
branches: [ master ]
permissions:
contents: write
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '17', '21', '23' ]
name: Java ${{ matrix.java }} VStar UTs
steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
- name: Create plugin dir
run:
mkdir -p ~/vstar_plugins
- name: Create plugin libs dir
run:
mkdir -p ~/vstar_plugin_libs
- name: Run tests with coverage
id: tests
run:
ant -noinput -buildfile build.xml coverage-report
- name: Extract test and coverage metrics
if: always()
id: metrics
run: |
SUMMARY="test_report/summary.txt"
COV_XML="test_report/coverage/coverage.xml"
TESTS=0; FAILURES=0; ERRORS=0
if [ -f "$SUMMARY" ]; then
while IFS= read -r line; do
t=$(echo "$line" | grep -oP 'Tests run: \K[0-9]+' || true)
f=$(echo "$line" | grep -oP 'Failures: \K[0-9]+' || true)
e=$(echo "$line" | grep -oP 'Errors: \K[0-9]+' || true)
[ -n "$t" ] && TESTS=$((TESTS + t))
[ -n "$f" ] && FAILURES=$((FAILURES + f))
[ -n "$e" ] && ERRORS=$((ERRORS + e))
done < "$SUMMARY"
fi
PASSED=$((TESTS - FAILURES - ERRORS))
LINE_COV="N/A"; BRANCH_COV="N/A"
if [ -f "$COV_XML" ]; then
LINE_M=$(grep -oP '<counter type="LINE" missed="\K[0-9]+' "$COV_XML" | tail -1 || true)
LINE_C=$(grep -oP '<counter type="LINE" missed="[0-9]+" covered="\K[0-9]+' "$COV_XML" | tail -1 || true)
BRANCH_M=$(grep -oP '<counter type="BRANCH" missed="\K[0-9]+' "$COV_XML" | tail -1 || true)
BRANCH_C=$(grep -oP '<counter type="BRANCH" missed="[0-9]+" covered="\K[0-9]+' "$COV_XML" | tail -1 || true)
if [ -n "$LINE_M" ] && [ -n "$LINE_C" ]; then
TOTAL_L=$((LINE_M + LINE_C))
if [ "$TOTAL_L" -gt 0 ]; then
LINE_COV="$((LINE_C * 100 / TOTAL_L))%"
fi
fi
if [ -n "$BRANCH_M" ] && [ -n "$BRANCH_C" ]; then
TOTAL_B=$((BRANCH_M + BRANCH_C))
if [ "$TOTAL_B" -gt 0 ]; then
BRANCH_COV="$((BRANCH_C * 100 / TOTAL_B))%"
fi
fi
fi
echo "tests=$TESTS" >> "$GITHUB_OUTPUT"
echo "passed=$PASSED" >> "$GITHUB_OUTPUT"
echo "failures=$FAILURES" >> "$GITHUB_OUTPUT"
echo "errors=$ERRORS" >> "$GITHUB_OUTPUT"
echo "line_cov=$LINE_COV" >> "$GITHUB_OUTPUT"
echo "branch_cov=$BRANCH_COV" >> "$GITHUB_OUTPUT"
- name: Post step summary
if: always() && steps.metrics.outputs.tests != '0'
run: |
STATUS="${{ steps.tests.outcome == 'success' && 'All tests passed' || 'Tests failed' }}"
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
## VStar Unit Tests (Java ${{ matrix.java }})
**${STATUS}**
| Metric | Value |
|--------|-------|
| Tests | ${{ steps.metrics.outputs.tests }} |
| Passed | ${{ steps.metrics.outputs.passed }} |
| Failures | ${{ steps.metrics.outputs.failures }} |
| Errors | ${{ steps.metrics.outputs.errors }} |
| Line Coverage | ${{ steps.metrics.outputs.line_cov }} |
| Branch Coverage | ${{ steps.metrics.outputs.branch_cov }} |
EOF
- name: Comment on PR
if: >-
always() &&
github.event_name == 'pull_request' &&
matrix.java == '17' &&
steps.metrics.outputs.tests != '0'
uses: actions/github-script@v7
with:
script: |
const outcome = '${{ steps.tests.outcome }}';
const status = outcome === 'success' ? 'All tests passed' : 'Tests failed';
const tests = '${{ steps.metrics.outputs.tests }}';
const passed = '${{ steps.metrics.outputs.passed }}';
const failures = '${{ steps.metrics.outputs.failures }}';
const errors = '${{ steps.metrics.outputs.errors }}';
const body = [
'## VStar Unit Tests',
'',
`**${status}** (Java 17)`,
'',
'| Metric | Value |',
'|--------|-------|',
`| Tests | ${tests} |`,
`| Passed | ${passed} |`,
`| Failures | ${failures} |`,
`| Errors | ${errors} |`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c =>
c.user.type === 'Bot' && c.body.startsWith('## VStar Unit Tests')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report-java${{ matrix.java }}
path: test_report/coverage/
- name: Checkout gh-pages
if: >-
github.event_name == 'push' &&
github.ref == 'refs/heads/master' &&
matrix.java == '17' &&
steps.metrics.outputs.tests != '0'
uses: actions/checkout@v4
with:
ref: gh-pages
path: _site
- name: Publish to dashboard
if: >-
github.event_name == 'push' &&
github.ref == 'refs/heads/master' &&
matrix.java == '17' &&
steps.metrics.outputs.tests != '0'
run: |
DATE=$(date -u +%Y-%m-%d)
cat > _site/data/coverage.json <<DATAJSON
{
"updated": "${DATE}",
"java_version": "17",
"tests": ${{ steps.metrics.outputs.tests }},
"passed": ${{ steps.metrics.outputs.passed }},
"failures": ${{ steps.metrics.outputs.failures }},
"errors": ${{ steps.metrics.outputs.errors }},
"line_coverage": "${{ steps.metrics.outputs.line_cov }}",
"branch_coverage": "${{ steps.metrics.outputs.branch_cov }}"
}
DATAJSON
rm -rf _site/coverage/vstar/*
if [ -d "test_report/coverage" ]; then
cp -r test_report/coverage/* _site/coverage/vstar/
fi
cd _site
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add -A
git diff --cached --quiet && exit 0
git commit -m "Update VStar coverage data [${DATE}]"
for i in 1 2 3; do
git pull --rebase origin gh-pages && git push origin gh-pages && break
echo "Push attempt $i failed, retrying in $((i * 5))s..."
sleep $((i * 5))
done