-
-
Notifications
You must be signed in to change notification settings - Fork 215
47 lines (46 loc) · 1.52 KB
/
format.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
name: Enforce formatting
on:
pull_request:
paths:
- 'src/**'
jobs:
format:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# check out HEAD on the branch
ref: ${{ github.head_ref }}
# make sure the parent commit is grabbed as well, because
# that's what will get formatted (i.e. the most recent commit)
fetch-depth: 2
- name: Get all src files that have changed
id: changed-files
uses: tj-actions/changed-files@v37
with:
files_yaml: |
src:
- src/**/*.c
- src/**/*.h
- src/**/*.cpp
- src/**/*.hpp
- name: List all changed src files
run: |
for file in ${{ steps.changed-files.outputs.src_all_changed_files }}; do
echo "$file was changed"
done
- name: Apply formatting
if: steps.changed-files.outputs.src_any_changed == 'true'
run: |
sudo apt install clang-format
for file in ${{ steps.changed-files.outputs.src_all_changed_files }}; do
echo "clang-format -i '$file'"
clang-format -style=file -i "$file"
done
# commit the changes (if there are any)
- name: Commit changes
uses: stefanzweifel/[email protected]
with:
commit_message: 🎨 apply clang-format changes
branch: ${{ github.head_ref }}