Skip to content

Commit 71b432d

Browse files
committed
format
1 parent 0535fc5 commit 71b432d

1 file changed

Lines changed: 7 additions & 33 deletions

File tree

‎.github/workflows/format.yml‎

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,47 +27,21 @@ jobs:
2727
- name: Run clang-format (C/C++)
2828
run: |
2929
set -e
30-
# Only run if there are matching files
3130
if git ls-files '*.cpp' '*.hpp' '*.cc' '*.cxx' '*.h' '*.hh' --error-unmatch >/dev/null 2>&1; then
3231
git ls-files '*.cpp' '*.hpp' '*.cc' '*.cxx' '*.h' '*.hh' -z | xargs -0 clang-format -i
3332
else
3433
echo "No C/C++ files to format."
3534
fi
3635
37-
- name: Check for modified files
38-
id: git-check
36+
- name: Commit formatted files (always on push)
37+
if: github.event_name == 'push'
3938
shell: bash
4039
run: |
41-
echo "Checking for modified files..."
42-
git status
43-
git diff --name-only
44-
if ! git diff --quiet; then
45-
echo "modified=true" >> "$GITHUB_OUTPUT"
46-
echo "Files were modified by formatting"
47-
else
48-
echo "modified=false" >> "$GITHUB_OUTPUT"
49-
echo "No files were modified"
50-
fi
51-
52-
- name: Debug info
53-
run: |
54-
echo "Event name: ${{ github.event_name }}"
55-
echo "Branch: ${{ github.ref_name }}"
56-
echo "Modified: ${{ steps.git-check.outputs.modified }}"
57-
58-
- name: Commit formatted files
59-
if: steps.git-check.outputs.modified == 'true' && github.event_name == 'push'
60-
run: |
61-
echo "Committing formatted files..."
40+
echo "Checking diff and committing if needed..."
6241
git config --global user.name "GitHub Actions Bot"
6342
git config --global user.email "actions@github.com"
64-
git add -A
65-
git status
66-
git commit -m "Auto-format C/C++ code with clang-format"
67-
git push
6843
69-
- name: Fail PR if formatting required
70-
if: steps.git-check.outputs.modified == 'true' && github.event_name == 'pull_request'
71-
run: |
72-
echo "::error::Code formatting changes detected. Please run clang-format locally and push the results."
73-
exit 1
44+
if ! git diff --quiet; then
45+
echo "Changes detected. Committing..."
46+
git add -A
47+
git commit -m "Auto-format C/C++ code with clang-format"

0 commit comments

Comments
 (0)