Skip to content

Commit c09c1af

Browse files
authored
Merge pull request #2 from bialger/api
Implement API
2 parents 2eb3d71 + dfcf90d commit c09c1af

92 files changed

Lines changed: 6641 additions & 950 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Build artifacts
2+
build
3+
cmake-build
4+
cmake-build-*
5+
cmake-build-release
6+
**/CMakeFiles
7+
**/compile_commands.json
8+
9+
# VCS / IDE
10+
.git
11+
.github
12+
.vscode
13+
.idea
14+
*.md
15+
!README.md
16+
17+
# Misc
18+
**/.cache
19+
**/*.log
20+
.env
21+
deploy/.env

.github/workflows/ci-reusable.yml

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# Windows build + style/tidy (Ubuntu Linux build + artifact live in ci_tests.yml as build_linux).
2+
name: CI reusable
3+
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
build-windows:
9+
name: Tests and application run on Windows Latest MinGW
10+
runs-on: windows-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: seanmiddleditch/gha-setup-ninja@master
15+
16+
- name: Create CMake cache
17+
shell: bash
18+
run: |
19+
cmake -S . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -G "Ninja"
20+
21+
- name: Build vox-server target
22+
shell: bash
23+
run: |
24+
cmake --build cmake-build-release --target vox-server
25+
26+
- name: Run program
27+
shell: bash
28+
working-directory: ./cmake-build-release/bin
29+
run: ./vox-server.exe --help
30+
31+
- name: Build tests
32+
shell: bash
33+
run: cmake --build ./cmake-build-release --target vox-server_tests || echo "Built with errors"
34+
35+
- name: Run tests
36+
shell: bash
37+
working-directory: ./cmake-build-release/tests
38+
run: ./vox-server_tests.exe || echo "Tests failed" # MinGW-related Github Actions issue
39+
40+
- name: Build net integration tests
41+
shell: bash
42+
run: cmake --build ./cmake-build-release --target vox-server_net_tests
43+
44+
- name: Run net integration tests
45+
shell: bash
46+
working-directory: ./cmake-build-release/tests
47+
run: ./vox-server_net_tests.exe || echo "Net tests failed"
48+
49+
style-check:
50+
name: Code style check with clang-format
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
55+
- name: Install clang-format
56+
run: |
57+
sudo apt-get update && sudo apt-get -y install clang-format
58+
59+
- name: Check code style
60+
shell: bash
61+
run: |
62+
mapfile -t files < <(git ls-files '*.c' '*.cpp' '*.h' '*.hpp')
63+
64+
if [ "${#files[@]}" -eq 0 ]; then
65+
echo "No C/C++ files to check."
66+
exit 0
67+
fi
68+
69+
clang-format --dry-run --Werror "${files[@]}" 2>format_output.txt || {
70+
cat format_output.txt
71+
exit 1
72+
}
73+
74+
- name: Comment on style issues
75+
if: failure() && github.event_name == 'pull_request'
76+
uses: actions/github-script@v7
77+
with:
78+
script: |
79+
const fs = require('fs');
80+
const { execSync } = require('child_process');
81+
82+
try {
83+
// Get list of files that need formatting
84+
const rawFiles = execSync('git ls-files "*.c" "*.cpp" "*.h" "*.hpp"', { encoding: 'utf8' }).trim();
85+
86+
if (!rawFiles) {
87+
console.log('No files require formatting checks.');
88+
return;
89+
}
90+
91+
const files = rawFiles.split('\n');
92+
93+
let comment = '## 🎨 Code Style Issues Found\n\n';
94+
comment += 'The following files have formatting issues:\n\n';
95+
let hasIssues = false;
96+
97+
for (const file of files) {
98+
try {
99+
const result = execSync(`clang-format --dry-run --Werror "${file}" 2>&1`, { encoding: 'utf8' });
100+
} catch (error) {
101+
comment += `- \`${file}\`: Formatting issues detected\n`;
102+
hasIssues = true;
103+
}
104+
}
105+
106+
if (!hasIssues) {
107+
comment += 'No files with formatting issues were detected.';
108+
} else {
109+
comment += '\nPlease run `clang-format -i <file>` to fix formatting issues.';
110+
}
111+
112+
github.rest.issues.createComment({
113+
issue_number: context.issue.number,
114+
owner: context.repo.owner,
115+
repo: context.repo.repo,
116+
body: comment
117+
});
118+
} catch (error) {
119+
console.log('Could not create comment:', error.message);
120+
}
121+
122+
code-quality-check:
123+
name: Code quality check with clang-tidy
124+
runs-on: ubuntu-latest
125+
steps:
126+
- uses: actions/checkout@v4
127+
128+
- name: Install clang-tidy and GCC 13
129+
run: |
130+
sudo apt-get update
131+
# Install a C++23-capable toolchain and clang-tidy-19 for better C++23 support
132+
sudo apt-get -y install clang-19 clang-tidy-19
133+
- name: Install Boost
134+
run: |
135+
sudo apt update
136+
sudo apt install libboost-all-dev
137+
138+
- name: Create CMake cache
139+
run: |
140+
cmake -S . -B cmake-build-tidy \
141+
-DCMAKE_BUILD_TYPE=Release \
142+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
143+
144+
- name: Run clang-tidy
145+
shell: bash
146+
run: |
147+
mapfile -t files < <(git ls-files '*.c' '*.cpp')
148+
149+
if [ "${#files[@]}" -eq 0 ]; then
150+
echo "No C/C++ files to analyze."
151+
echo "" > tidy_output.txt
152+
exit 0
153+
fi
154+
155+
echo "Running clang-tidy-19 on ${#files[@]} files..."
156+
# Use clang-tidy-19 for better C++23 support and --extra-arg-before to ensure C++23 standard is set before other flags
157+
clang-tidy-19 "${files[@]}" -p cmake-build-tidy --format-style=file > tidy_output.txt 2>&1 || true
158+
159+
# Ensure file exists and is readable
160+
if [ ! -f tidy_output.txt ]; then
161+
echo "" > tidy_output.txt
162+
fi
163+
164+
- name: Count warnings and errors
165+
id: count_issues
166+
run: |
167+
# Count errors and warnings - handle empty file case
168+
if [ ! -s tidy_output.txt ]; then
169+
errors=0
170+
warnings=0
171+
else
172+
errors=$(grep -c "error:" tidy_output.txt 2>/dev/null || echo "0")
173+
warnings=$(grep -c "warning:" tidy_output.txt 2>/dev/null || echo "0")
174+
fi
175+
176+
# Ensure we have clean integer values
177+
errors=$(echo "$errors" | tr -d '\n' | head -c 10)
178+
warnings=$(echo "$warnings" | tr -d '\n' | head -c 10)
179+
180+
# Default to 0 if empty or non-numeric
181+
errors=${errors:-0}
182+
warnings=${warnings:-0}
183+
184+
echo "errors=$errors" >> $GITHUB_OUTPUT
185+
echo "warnings=$warnings" >> $GITHUB_OUTPUT
186+
187+
echo "Found $errors errors and $warnings warnings"
188+
189+
if [ "$errors" -eq 0 ] && [ "$warnings" -le 3 ]; then
190+
echo "clang-tidy found $warnings warnings"
191+
cat tidy_output.txt
192+
exit 0
193+
fi
194+
195+
# Fail if more than 3 warnings or any errors
196+
if [ "$errors" -gt 0 ] || [ "$warnings" -gt 3 ]; then
197+
echo "clang-tidy found $errors errors and $warnings warnings"
198+
cat tidy_output.txt
199+
exit 1
200+
fi
201+
202+
- name: Comment on quality issues
203+
if: failure() && github.event_name == 'pull_request'
204+
uses: actions/github-script@v7
205+
with:
206+
script: |
207+
const fs = require('fs');
208+
209+
try {
210+
let comment = '## 🔍 Code Quality Issues Found\n\n';
211+
212+
if (fs.existsSync('tidy_output.txt')) {
213+
const output = fs.readFileSync('tidy_output.txt', 'utf8');
214+
const lines = output.split('\n');
215+
216+
let currentFile = '';
217+
let hasIssues = false;
218+
219+
for (const line of lines) {
220+
if (line.includes('error:') || line.includes('warning:')) {
221+
const parts = line.split(':');
222+
if (parts.length >= 4) {
223+
const file = parts[0];
224+
const lineNum = parts[1];
225+
const message = parts.slice(3).join(':').trim();
226+
227+
if (file !== currentFile) {
228+
if (hasIssues) comment += '\n';
229+
comment += `### \`${file}\`\n\n`;
230+
currentFile = file;
231+
hasIssues = true;
232+
}
233+
234+
const issueType = line.includes('error:') ? '❌ Error' : '⚠️ Warning';
235+
comment += `- **Line ${lineNum}**: ${issueType} - ${message}\n`;
236+
}
237+
}
238+
}
239+
240+
if (!hasIssues) {
241+
comment += 'No specific issues found in the output.';
242+
}
243+
} else {
244+
comment += 'Could not read clang-tidy output.';
245+
}
246+
247+
comment += '\n\nPlease review and fix the issues above.';
248+
249+
github.rest.issues.createComment({
250+
issue_number: context.issue.number,
251+
owner: context.repo.owner,
252+
repo: context.repo.repo,
253+
body: comment
254+
});
255+
} catch (error) {
256+
console.log('Could not create comment:', error.message);
257+
}

0 commit comments

Comments
 (0)