-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
update
Showing
1 changed file
with
34 additions
and
3 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 |
---|---|---|
@@ -1,9 +1,40 @@ | ||
name: clang-format Check | ||
on: [push, pull_request] | ||
on: | ||
- push | ||
- pull_request | ||
jobs: | ||
formatting-check: | ||
name: Formatting Check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: jidicula/[email protected] | ||
- uses: actions/checkout@v4 | ||
- name: Install clang-format | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y clang-format | ||
- name: Fetch base branch | ||
run: > | ||
git fetch origin ${{ github.base_ref }}:refs/remotes/origin/${{ | ||
github.base_ref }} | ||
- name: Run clang-format on diff | ||
run: > | ||
# Get the diff of changed files | ||
git diff --name-only origin/${{ github.base_ref }} | grep -E | ||
'\\.(cpp|h|cu)$' > changed_files.txt | ||
# Check each changed file | ||
while read file; do | ||
echo "Checking $file" | ||
git diff origin/${{ github.base_ref }} -- $file | clang-format-diff -p1 -style=file > formatted.diff | ||
if [ -s formatted.diff ]; then | ||
echo "File $file is not properly formatted. Please run clang-format on your code." | ||
cat formatted.diff | ||
cat formatted.diff >> "$GITHUB_OUTPUT" | ||
exit 1 | ||
fi | ||
done < changed_files.txt | ||
- name: Show success message | ||
if: success() | ||
run: echo "All files are properly formatted!" |