-
Notifications
You must be signed in to change notification settings - Fork 30
65 lines (57 loc) · 2.04 KB
/
clang-format-check.yml
File metadata and controls
65 lines (57 loc) · 2.04 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Clang Format Check
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
clang-format-check:
name: Check PR formatting with clang-format-15
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history to compare with main branch
- name: Install clang-format-15
run: |
sudo apt-get install -y clang-format-15
- name: Fetch base branch
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
git fetch origin "$BASE_REF:$BASE_REF"
- name: Check formatting
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
echo "Running git-clang-format-15 to check for formatting issues..."
echo "Comparing against base branch: $BASE_REF"
# Create a temporary file for the diff and ensure cleanup
DIFF_FILE="$(mktemp)"
trap 'rm -f "$DIFF_FILE"' EXIT
# Run git-clang-format against the PR base commit and capture status safely under set -e
if git-clang-format-15 "$BASE_REF" > "$DIFF_FILE"; then
status=0
else
status=$?
fi
if [ "$status" -eq 0 ]; then
echo "✅ Code is properly formatted!"
exit 0
elif [ "$status" -eq 1 ]; then
echo "❌ Code formatting issues detected!"
echo ""
echo "The following changes would be made by clang-format-15:"
echo "=================================================="
cat "$DIFF_FILE"
echo "=================================================="
echo ""
echo "Please run the following command locally on your feature branch and commit the changes:"
echo " git-clang-format-15 $BASE_REF"
exit 1
else
echo "❌ git-clang-format-15 failed with exit code $status"
echo "Output (if any):"
cat "$DIFF_FILE"
exit 1
fi