Skip to content

Clang Format

Clang Format #20

Workflow file for this run

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/*" \
-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
if: steps.check_changes.outputs.changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Apply clang-format formatting"
git push