OSDN Git Service

[Chore] 改行コードがLFであることをチェックする
authorHabu <habu1010+github@gmail.com>
Wed, 12 Jun 2024 10:33:12 +0000 (19:33 +0900)
committerHabu <habu1010+github@gmail.com>
Wed, 12 Jun 2024 10:40:26 +0000 (19:40 +0900)
プルリクエストのCIによるチェックで、すべてのテキストファイルの改行
コードがCRLFではなくLFであることをチェックする。
ただし、./VisualStudio/ 以下のファイルは Visual Studio が自動的にCRLFで
上書き保存するので、混乱を避けるためチェックから除外する。

.github/scripts/check-newline.sh [new file with mode: 0644]
.github/workflows/pull-request-status-check.yml

diff --git a/.github/scripts/check-newline.sh b/.github/scripts/check-newline.sh
new file mode 100644 (file)
index 0000000..05107c9
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# ./VisualStudio/ 以下のファイルはVisual StudioがCRLFで上書きするため除外
+CHECK_FILES=$(find . -type f -not -path './.git/*' -and -not -path './VisualStudio/*' -and -not -name \*.wav -and -not -name \*.mp3)
+
+STATUS=0
+
+for file in $CHECK_FILES; do
+    file $file | grep "CRLF" >/dev/null
+    if [ $? -eq 0 ]; then
+        echo "$file: newline is CRLF."
+        STATUS=1
+    fi
+done
+
+exit $STATUS
index b148e04..eaf42f5 100644 (file)
@@ -15,6 +15,13 @@ jobs:
       - uses: actions/checkout@v3
       - run: sh ./.github/scripts/check-bom.sh
 
+  check_newline:
+    name: Check the newline of files
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+      - run: sh ./.github/scripts/check-newline.sh
+
   check_format:
     name: Check the format of the source files
     runs-on: ubuntu-latest