Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the clang-format job to give a patch #469

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 0 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ on:
- develop
- master
jobs:
clang-format-check:
runs-on: macos-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Install clang-format
run: |
brew install clang-format
clang-format --version
- name: Run clang format check
run: |
bash scripts/check-clang.sh

mac-os-build-gcc:
runs-on: macos-13
permissions:
Expand Down
93 changes: 93 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: clang-format-check
on: [ push ]
jobs:
check-format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format-14
sudo ln -sf /usr/bin/clang-format-14 /usr/bin/clang-format

- name: Check clang
run: |
find . -name "*.c" -o -name "*.h" -o -name "*.cpp" | xargs clang-format -style=file --dry-run -Werror
shell: bash

- name: Clang Format Success Summary
if: success()
run: |
echo "# 🎉 Clang Format Check Passed!" >> $GITHUB_STEP_SUMMARY
echo "All files are properly formatted." >> $GITHUB_STEP_SUMMARY

format-and-upload:
runs-on: ubuntu-latest
needs: check-format
if: failure() # Only run this job if the check-format job fails

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format-14
sudo ln -sf /usr/bin/clang-format-14 /usr/bin/clang-format

- name: Find and format .c, .h, and .cpp files
run: |
git add -u
# Apply formatting
find . -name "*.c" -o -name "*.h" -o -name "*.cpp" | xargs clang-format -i -style=file
# Check which files were modified by clang-format
git diff --name-only > modified_files.txt
git diff > clang-format-fix.patch
echo "Modified files: $(cat modified_files.txt)"
shell: bash

- name: Archive formatted files
run: |
mkdir -p formatted_files
while IFS= read -r file; do
echo "Compressing $file ..."
# Copy only modified files to the formatted_files directory, preserving structure
mkdir -p "formatted_files/$(dirname "$file")"
cp "$file" "formatted_files/$file"
done < modified_files.txt
shell: bash

- name: Upload formatted files
uses: actions/upload-artifact@v4
with:
name: formatted-files
path: formatted_files

- name: Upload patch file
uses: actions/upload-artifact@v4
with:
name: clang-format-fix.patch
path: clang-format-fix.patch

- name: Generate Markdown Summary for Corrected Files
run: |
echo "# ❌ Clang Format Check Failed" >> $GITHUB_STEP_SUMMARY
echo "$(wc -l < modified_files.txt) file(s) are not clang-format compliant. Please review the list of affected files below:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
while IFS= read -r file; do
echo "- \`$file\`" >> $GITHUB_STEP_SUMMARY
done < modified_files.txt
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🛠️ Fixed files" >> $GITHUB_STEP_SUMMARY
echo "**Total Files Formatted**: $(wc -l < modified_files.txt)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "ℹ️ Check the \"Artifacts\" below for the corrected files." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To apply the formatting fixes locally, download the patch file below and place it in the repository root. Then run this command from the repository root:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "git apply clang-format-fix.patch" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
Loading