-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (40 loc) · 1.24 KB
/
formatCode.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: Format code
on:
pull_request:
types: [opened, reopened, edited]
workflow_dispatch:
push:
branches:
- main
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
formatCode:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Install clang-format 18
run: |
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
sudo apt-get update &&
sudo apt-get install -y clang-format-18
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}
fetch-depth: 0
- name: Format code and commit changes
run : |
find ${{github.workspace}}/ -iname '*.h' -o -iname '*.c' | xargs clang-format-18 -i
- name: Commit changes
run : |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git diff-index --quiet HEAD || git commit -m "Fixed formatting" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.BRANCH_NAME }}