OSDN Git Service

[Feature] PR ステータスチェックのワークフロー再構成
[hengbandforosx/hengbandosx.git] / .github / scripts / check-format.sh
1 #!/bin/sh
2
3 # InsertBraces オプションに対応するため、clang-format-15 をインストールする
4 # そのため LLVM が用意している APT リポジトリを追加する
5 # 将来的に GitHub Actions の Ubuntu runner が 22.04 になれば Ubuntu の APT リポジトリからインストールできるかもしれない
6 wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key 2>/dev/null | sudo apt-key add - >/dev/null 2>&1
7
8 cat <<EOF | sudo tee /etc/apt/sources.list.d/llvm.list >/dev/null
9 deb http://apt.llvm.org/focal/ llvm-toolchain-focal main
10 deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal main
11 # 13
12 deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main
13 deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main
14 # 14
15 deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main
16 deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main
17
18 EOF
19
20 sudo apt-get update >/dev/null
21 sudo apt-get install clang-format-15 >/dev/null
22
23 SRC_FILES=$(find src/ -name \*.cpp -or -name \*.h)
24
25 clang-format-15 -style=file:.github/scripts/check-clang-format-style -i $SRC_FILES
26
27 DIFF_FILE=$(mktemp)
28 git diff >$DIFF_FILE
29
30 if [ -s $DIFF_FILE ]; then
31     echo "Some source code files are not properly formatted."
32     cat $DIFF_FILE
33     exit 1
34 fi
35
36 exit 0