Skip to content

Commit 0631550

Browse files
committed
Merge branch 'feature/add-clang-format'
2 parents 62dcf26 + 595adcd commit 0631550

File tree

9 files changed

+1279
-1429
lines changed

9 files changed

+1279
-1429
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NOTE: The content of this file has been directly adapted from /godot-cpp/.workflows/static_checks.yml
2+
name: 📊 Static Checks
3+
on: [push, pull_request]
4+
5+
jobs:
6+
static-checks:
7+
name: Format (clang-format)
8+
runs-on: ubuntu-20.04
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
with:
13+
lfs: true
14+
submodules: recursive
15+
16+
# Azure repositories are not reliable, we need to prevent Azure giving us packages.
17+
- name: Make apt sources.list use the default Ubuntu repositories
18+
run: |
19+
sudo rm -f /etc/apt/sources.list.d/*
20+
sudo cp -f godot-cpp/misc/ci/sources.list /etc/apt/sources.list
21+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
22+
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main"
23+
sudo apt-get update
24+
25+
- name: Install dependencies
26+
run: |
27+
sudo apt-get install -qq clang-format-15
28+
sudo update-alternatives --remove-all clang-format || true
29+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 100
30+
31+
- name: Style checks via clang-format (clang_format.sh)
32+
run: |
33+
bash ./misc/scripts/clang_format.sh

misc/scripts/clang_format.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# This script runs clang-format on all relevant files in the repo.
4+
# This is the primary script responsible for fixing style violations.
5+
6+
set -uo pipefail
7+
8+
# Loops through all code files tracked by Git.
9+
git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' ':!:src/sqlite/*' |
10+
while read -r f; do
11+
# Run clang-format.
12+
clang-format --style=file:godot-cpp/.clang-format --Wno-error=unknown -i "$f"
13+
done
14+
15+
diff=$(git diff --color)
16+
17+
# If no patch has been generated all is OK, clean up, and exit.
18+
if [ -z "$diff" ] ; then
19+
printf "Files in this commit comply with the clang-tidy style rules.\n"
20+
exit 0
21+
fi
22+
23+
# A patch has been created, notify the user, clean up, and exit.
24+
printf "\n*** The following changes have been made to comply with the formatting rules:\n\n"
25+
echo "$diff"
26+
printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
27+
exit 1

0 commit comments

Comments
 (0)