Răsfoiți Sursa

Check coding style in CI

Jim Huang 3 ani în urmă
părinte
comite
2db805da2c
3 a modificat fișierele cu 35 adăugiri și 0 ștergeri
  1. 21 0
      .ci/check-format.sh
  2. 11 0
      .github/workflows/generate_doc.yaml
  3. 3 0
      .gitignore

+ 21 - 0
.ci/check-format.sh

@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+SOURCES=$(find $(git rev-parse --show-toplevel) | egrep "\.(cpp|cc|c|h)\$")
+
+CLANG_FORMAT=$(which clang-format-11)
+if [ $? -ne 0 ]; then
+    CLANG_FORMAT=$(which clang-format)
+    if [ $? -ne 0 ]; then
+        echo "[!] clang-format not installed. Unable to check source file format policy." >&2
+        exit 1
+    fi
+fi
+
+set -x
+
+for file in ${SOURCES};
+do
+    $CLANG_FORMAT ${file} > expected-format
+    diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
+done
+exit $($CLANG_FORMAT --output-replacements-xml ${SOURCES} | egrep -c "</replacement>")

+ 11 - 0
.github/workflows/generate_doc.yaml

@@ -35,3 +35,14 @@ jobs:
             lkmpg-html.tar.gz
           tag_name: "latest"
           prerelease: true
+
+  coding_style:
+    runs-on: ubuntu-20.04
+    steps:
+      - name: checkout code
+        uses: actions/checkout@v2
+      - name: style check
+        run: |
+            sudo apt-get install -q -y clang-format-11
+            sh .ci/check-format.sh
+        shell: bash

+ 3 - 0
.gitignore

@@ -29,3 +29,6 @@ lkmpg.pdf
 *.lg 
 *.idv
 *.xref
+
+# format checks
+expected-format