Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 208 additions & 5 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ jobs:
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 "Unix Makefiles"
cmake -S . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles"
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
Expand All @@ -27,14 +33,16 @@ jobs:

- name: Run program
working-directory: .\cmake-build-release
shell: bash
run: |
.\ovum.exe --help
./ovum.exe --help

- name: Run tests
working-directory: .\cmake-build-debug
shell: bash
run: |
echo "Currently unable to run tests on Windows Latest MinGW. See https://gitmemories.com/cristianadam/HelloWorld/issues/12 and https://github.com/microsoft/vscode-cmake-tools/issues/2451"
% .\ovum_tests.exe
# ./ovum_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 }}
Expand Down Expand Up @@ -123,3 +131,198 @@ jobs:
working-directory: ./cmake-build/tests
run: |
valgrind --leak-check=full --track-origins=yes --error-exitcode=1 ./ovum_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);
}
Loading