-
Notifications
You must be signed in to change notification settings - Fork 98
44 lines (36 loc) · 1.39 KB
/
pr-code-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
name: "Check code formatting"
permissions:
contents: read
on:
pull_request:
branches:
- master
jobs:
code_formatter:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install clang-format
run:
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" | sudo tee -a /etc/apt/sources.list && \
sudo apt update && sudo apt install wget && wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - && \
sudo apt update && sudo apt install -y --no-install-recommends clang-format-18.1.8*
- name: Run clang-format on changed files
run: |
# Get list of changed files
CHANGED_FILES=$(git diff --name-only --diff-filter=ACM origin/master...HEAD --)
CHANGED_CPP_FILES=$(echo "$CHANGED_FILES" | grep -E '^(runtime-light|runtime-common)/.*\.(cpp|h|inl)$')
# Apply clang-format to each changed source file
echo "$CHANGED_CPP_FILES" | xargs -r clang-format-18 -i
- name: Check for formatting changes
run: |
# Check if any files were modified by clang-format
git diff --exit-code
if [ $? -ne 0 ]; then
echo "Code is not formatted. Please run clang-format."
exit 1
fi