-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit hook and workflow check
- Loading branch information
1 parent
593ce93
commit d1204aa
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Clang Format Check | ||
|
||
on: | ||
push: | ||
branches: [ 'main', 'release-*' ] | ||
pull_request: | ||
branches: [ 'main', 'release-*' ] | ||
|
||
jobs: | ||
clang-format: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install Clang-Format | ||
run: sudo apt-get install clang-format | ||
|
||
- name: Check Clang Format | ||
run: | | ||
# Check for modified C/C++ files | ||
files=$(git diff --name-only origin/main...HEAD | grep -E '\.(c|cpp|h)$') | ||
if [ -z "$files" ]; then | ||
echo "No C/C++ files modified." | ||
exit 0 | ||
fi | ||
# Run clang-format and check for changes | ||
clang-format -i $files | ||
git diff --exit-code $files | ||
#env: | ||
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
# Format all staged C/C++ files | ||
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|cpp|h)$') | ||
|
||
if [ -n "$files" ]; then | ||
echo "Running clang-format on:" | ||
echo "$files" | ||
|
||
# Run clang-format on the staged files | ||
for file in $files; do | ||
clang-format -i "$file" | ||
git add "$file" # Re-add formatted files to staging | ||
done | ||
fi |