-
-
Notifications
You must be signed in to change notification settings - Fork 9
175 lines (134 loc) · 5.29 KB
/
dotnet-tests.yml
File metadata and controls
175 lines (134 loc) · 5.29 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
name: .NET Tests
on:
pull_request:
branches:
- main
- dev
paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
workflow_dispatch:
jobs:
tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: '8.0.x' # Adjust the version as needed
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Run tests with code coverage
run: dotnet test --no-build --verbosity normal --results-directory "./TestResults/Coverage/" --logger "trx;LogFileName=test_results.trx" --collect:"XPlat Code Coverage"
# - name: Publish test results
# uses: dorny/test-reporter@v1
# with:
# name: tests
# path: src/TestResults/Coverage/test_results.trx
# reporter: dotnet-trx
# fail-on-error: true
- name: Upload test results artifact
uses: actions/upload-artifact@v4
with:
name: test-results
path: '**/TestResults/**'
- name: Install xmlstarlet
run: sudo apt-get update && sudo apt-get install -y xmlstarlet
- name: Summarize test results from .trx
run: |
TRX_FILE="TestResults/Coverage/test_results.trx"
# Register the namespace (ns) and query using that
PASSED=$(xmlstarlet sel -N ns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "count(//ns:UnitTestResult[@outcome='Passed'])" "$TRX_FILE")
FAILED=$(xmlstarlet sel -N ns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "count(//ns:UnitTestResult[@outcome='Failed'])" "$TRX_FILE")
SKIPPED=$(xmlstarlet sel -N ns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "count(//ns:UnitTestResult[@outcome='NotExectured'])" "$TRX_FILE")
TOTAL=$(xmlstarlet sel -N ns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "count(//ns:UnitTestResult)" "$TRX_FILE")
echo "## 🧪 Test Results Summary" >> $GITHUB_STEP_SUMMARY
# Write message based on test outcome
if [ "$FAILED" -eq 0 ]; then
echo "✅ All tests passed!" >> $GITHUB_STEP_SUMMARY
else
echo "❌ $FAILED test(s) failed!" >> $GITHUB_STEP_SUMMARY
fi
BAR_LENGTH=10
make_bar() {
COUNT=$1
TOTAL=$2
CHAR=$3
FILLED=$(( (COUNT * BAR_LENGTH + TOTAL / 2) / TOTAL ))
EMPTY=$(( BAR_LENGTH - FILLED ))
BAR=""
for ((i=0; i<FILLED; i++)); do BAR+="$CHAR"; done
for ((i=0; i<EMPTY; i++)); do BAR+="⬜"; done
echo "$BAR"
}
format_pct() {
COUNT=$1
TOTAL=$2
echo "$(echo "scale=1; $COUNT*100/$TOTAL" | bc)%"
}
PASSED_BAR=$(make_bar $PASSED $TOTAL "🟩")
FAILED_BAR=$(make_bar $FAILED $TOTAL "🟥")
SKIPPED_BAR=$(make_bar $SKIPPED $TOTAL "🟨")
PASSED_PCT=$(format_pct $PASSED $TOTAL)
FAILED_PCT=$(format_pct $FAILED $TOTAL)
SKIPPED_PCT=$(format_pct $SKIPPED $TOTAL)
{
echo ""
echo "| | Count | Percent | |"
echo "|-----------|--------|---------|-------------|"
echo "| ✅ Passed | $PASSED | $PASSED_PCT | $PASSED_BAR |"
echo "| ❌ Failed | $FAILED | $FAILED_PCT | $FAILED_BAR |"
echo "| ➖ Skipped | $SKIPPED | $SKIPPED_PCT | $SKIPPED_BAR |"
echo "| 📊 Total | $TOTAL | | |"
} >> $GITHUB_STEP_SUMMARY
- name: Install ReportGenerator
run: dotnet tool install -g dotnet-reportgenerator-globaltool
- name: Generate Markdown report
run: |
reportgenerator \
-reports:./TestResults/Coverage/**/coverage.cobertura.xml \
-targetdir:./coveragereport \
-reporttypes:MarkdownSummaryGithub
- name: Append coverage to summary
run: |
echo "## Code Coverage Summary" >> $GITHUB_STEP_SUMMARY
cat ./coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
- name: Upload code coverage report
uses: actions/upload-artifact@v4
with:
name: CodeCoverage
path: ./src/TestResults/Coverage/**/coverage.cobertura.xml
performance:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: '8.0.x' # Adjust the version as needed
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Performance Test
run: dotnet run --project SharpVectorPerformance --configuration Release
- name: Performance Results
run: |
echo "## Performance Results" > $GITHUB_STEP_SUMMARY
cat ./BenchmarkDotNet.Artifacts/results/SharpVectorPerformance.MemoryVectorDatabasePerformance-report-github.md >> $GITHUB_STEP_SUMMARY
- name: Upload Performance artifact
uses: actions/upload-artifact@v4
with:
name: performance-results
path: './src/BenchmarkDotNet.Artifacts/*'