Release 1.2.0 (#267) #1
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: [ 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" | 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 |