Clang Format #33
This file contains hidden or 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 | |
| on: | |
| schedule: | |
| # Run every Sunday at midnight UTC (Sunday night) | |
| - cron: '0 0 * * 0' | |
| workflow_dispatch: # Allow manual triggering for testing | |
| permissions: | |
| contents: write | |
| jobs: | |
| format: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install clang-format | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y clang-format-18 | |
| - name: Run clang-format | |
| run: | | |
| # Find all C/C++ files and format them | |
| find . -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) \ | |
| -not -path "*/build/*" \ | |
| -not -path "*/zephyr/*" \ | |
| -not -path "*/.git/*" \ | |
| -not -path "*/CMakeFiles/*" \ | |
| -not -path "*/tools/autocoders/templates/*" \ | |
| -exec clang-format-18 -i {} \; | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| git checkout -b auto/clang-format-fix | |
| git add . | |
| git commit -m "Apply clang-format formatting" | |
| git push origin auto/clang-format-fix | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| branch: auto/clang-format-fix | |
| title: Clang Format Fix | |
| body: Automated clang-format suggestions |