-
Notifications
You must be signed in to change notification settings - Fork 1
328 lines (271 loc) · 10.6 KB
/
ci_tests.yml
File metadata and controls
328 lines (271 loc) · 10.6 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
name: "CI tests"
on: [ push, workflow_dispatch ]
jobs:
build-mingw:
name: Tests and application run on Windows Latest MinGW
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install MinGW toolchain
shell: powershell
run: |
choco install mingw --yes --no-progress
echo "C:\tools\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Create CMake cache
run: |
cmake -S . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles"
cmake -S . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -G "MinGW Makefiles"
- name: Build main target
shell: bash
run: |
cmake --build cmake-build-release || echo Built with errors
- name: Build tests target
shell: bash
run: |
cmake --build cmake-build-debug --target cpp_tests_tests || echo Built with errors
- name: Run program
working-directory: .\cmake-build-release
shell: bash
run: |
./cpp_tests.exe --help
- name: Run tests
working-directory: .\cmake-build-debug
shell: bash
run: |
# ./cpp_tests_tests.exe
echo "Tests are not run on Windows MinGW due to issues with the test runner"
build-matrix:
name: Tests and application run on ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: "Windows Latest MSVC", artifact: "Windows-MSVC.tar.xz",
os: windows-latest,
build_type: "Release", cc: "cl", cxx: "cl",
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
}
- {
name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz",
os: ubuntu-latest,
build_type: "Release", cc: "gcc", cxx: "g++"
}
- {
name: "macOS Latest Clang", artifact: "macOS.tar.xz",
os: macos-latest,
build_type: "Release", cc: "clang", cxx: "clang++"
}
steps:
- uses: actions/checkout@v4
- name: Create CMake cache
shell: bash
run: |
cmake -S . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release
cmake -S . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug
- name: Build main target
shell: bash
run: |
cmake --build cmake-build-release --target cpp_tests || echo "Built with errors"
- name: Build tests target
shell: bash
run: |
cmake --build cmake-build-debug --target cpp_tests_tests || echo "Built with errors"
- name: Run program
shell: bash
working-directory: ./cmake-build-release
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
./cpp_tests.exe --help
else
cd bin
./cpp_tests --help
fi
- name: Run tests
shell: bash
working-directory: ./cmake-build-debug
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
./cpp_tests_tests.exe
else
cd tests
./cpp_tests_tests
fi
memory-leaks:
name: Find memory leaks in tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install valgrind
run: |
sudo apt-get update && sudo apt-get -y install valgrind
- name: Create CMake cache
run: |
cmake -S . -B cmake-build -DCMAKE_BUILD_TYPE=Debug
- name: Build tests target
run: |
cmake --build cmake-build --target cpp_tests_tests
- name: Run valgrind
working-directory: ./cmake-build/tests
run: |
valgrind --leak-check=full --track-origins=yes --error-exitcode=1 ./cpp_tests_tests
style-check:
name: Code style check with clang-format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clang-format
run: |
sudo apt-get update && sudo apt-get -y install clang-format
- name: Check code style
shell: bash
run: |
mapfile -t files < <(git ls-files '*.c' '*.cpp' '*.h' '*.hpp')
if [ "${#files[@]}" -eq 0 ]; then
echo "No C/C++ files to check."
exit 0
fi
clang-format --dry-run --Werror "${files[@]}" 2>format_output.txt || {
cat format_output.txt
exit 1
}
- name: Comment on style issues
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const { execSync } = require('child_process');
try {
// Get list of files that need formatting
const rawFiles = execSync('git ls-files "*.c" "*.cpp" "*.h" "*.hpp"', { encoding: 'utf8' }).trim();
if (!rawFiles) {
console.log('No files require formatting checks.');
return;
}
const files = rawFiles.split('\n');
let comment = '## 🎨 Code Style Issues Found\n\n';
comment += 'The following files have formatting issues:\n\n';
let hasIssues = false;
for (const file of files) {
try {
const result = execSync(`clang-format --dry-run --Werror "${file}" 2>&1`, { encoding: 'utf8' });
} catch (error) {
comment += `- \`${file}\`: Formatting issues detected\n`;
hasIssues = true;
}
}
if (!hasIssues) {
comment += 'No files with formatting issues were detected.';
} else {
comment += '\nPlease run `clang-format -i <file>` to fix formatting issues.';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} catch (error) {
console.log('Could not create comment:', error.message);
}
code-quality-check:
name: Code quality check with clang-tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clang-tidy
run: |
sudo apt-get update && sudo apt-get -y install clang-tidy
- name: Create CMake cache
run: |
cmake -S . -B cmake-build-tidy -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: Run clang-tidy
shell: bash
run: |
mapfile -t files < <(git ls-files '*.c' '*.cpp')
if [ "${#files[@]}" -eq 0 ]; then
echo "No C/C++ files to analyze."
echo "" > tidy_output.txt
exit 0
fi
echo "Running clang-tidy on ${#files[@]} files..."
clang-tidy "${files[@]}" -p cmake-build-tidy --format-style=file > tidy_output.txt 2>&1 || true
# Ensure file exists and is readable
if [ ! -f tidy_output.txt ]; then
echo "" > tidy_output.txt
fi
- name: Count warnings and errors
id: count_issues
run: |
# Count errors and warnings - handle empty file case
if [ ! -s tidy_output.txt ]; then
errors=0
warnings=0
else
errors=$(grep -c "error:" tidy_output.txt 2>/dev/null || echo "0")
warnings=$(grep -c "warning:" tidy_output.txt 2>/dev/null || echo "0")
fi
# Ensure we have clean integer values
errors=$(echo "$errors" | tr -d '\n' | head -c 10)
warnings=$(echo "$warnings" | tr -d '\n' | head -c 10)
# Default to 0 if empty or non-numeric
errors=${errors:-0}
warnings=${warnings:-0}
echo "errors=$errors" >> $GITHUB_OUTPUT
echo "warnings=$warnings" >> $GITHUB_OUTPUT
echo "Found $errors errors and $warnings warnings"
# Fail if more than 3 warnings or any errors
if [ "$errors" -gt 0 ] || [ "$warnings" -gt 3 ]; then
echo "clang-tidy found $errors errors and $warnings warnings"
cat tidy_output.txt
exit 1
fi
- name: Comment on quality issues
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
try {
let comment = '## 🔍 Code Quality Issues Found\n\n';
if (fs.existsSync('tidy_output.txt')) {
const output = fs.readFileSync('tidy_output.txt', 'utf8');
const lines = output.split('\n');
let currentFile = '';
let hasIssues = false;
for (const line of lines) {
if (line.includes('error:') || line.includes('warning:')) {
const parts = line.split(':');
if (parts.length >= 4) {
const file = parts[0];
const lineNum = parts[1];
const message = parts.slice(3).join(':').trim();
if (file !== currentFile) {
if (hasIssues) comment += '\n';
comment += `### \`${file}\`\n\n`;
currentFile = file;
hasIssues = true;
}
const issueType = line.includes('error:') ? '❌ Error' : '⚠️ Warning';
comment += `- **Line ${lineNum}**: ${issueType} - ${message}\n`;
}
}
}
if (!hasIssues) {
comment += 'No specific issues found in the output.';
}
} else {
comment += 'Could not read clang-tidy output.';
}
comment += '\n\nPlease review and fix the issues above.';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} catch (error) {
console.log('Could not create comment:', error.message);
}