Brodey | Build system #21
Workflow file for this run
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
name: clang-format Check | |
on: | |
- pull_request | |
jobs: | |
formatting-check: | |
name: Formatting Check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install clang-format | |
run: 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!" |