add github action for formatting
This commit is contained in:
parent
66a0590d77
commit
6989521a31
42
.github/workflows/clang-format.yml
vendored
Normal file
42
.github/workflows/clang-format.yml
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
name: Clang Format & Tidy
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clang-tools:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write # Needed to push changes back
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.head_ref }} # checkout the PR branch so we can push back
|
||||||
|
|
||||||
|
- name: Install clang tools
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y clang-format clang-tidy
|
||||||
|
|
||||||
|
- name: Run clang-format and auto-fix
|
||||||
|
run: |
|
||||||
|
FILES=$(find . -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp')
|
||||||
|
clang-format -i $FILES
|
||||||
|
|
||||||
|
- name: Commit and push changes (if any)
|
||||||
|
run: |
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
git add -u
|
||||||
|
if ! git diff --cached --quiet; then
|
||||||
|
git commit -m "Apply clang-format fixes"
|
||||||
|
git push
|
||||||
|
else
|
||||||
|
echo "No formatting changes needed"
|
||||||
|
fi
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user