]> git.kaiwu.me - nginx.git/commitdiff
GH: add a workflow to check for whitespace issues
authorAndrew Clayton <a.clayton@nginx.com>
Thu, 26 Mar 2026 17:51:56 +0000 (17:51 +0000)
committerAndrew Clayton <a.clayton@nginx.com>
Fri, 24 Apr 2026 16:33:41 +0000 (17:33 +0100)
This runs git-log(1) --check on *each* commit and will report any
issues, e.g.

  --- afe5753fa ("Changes made in upstream")
  src/http/ngx_http_upstream.c:415: trailing whitespace.
  +
  src/http/ngx_http_upstream.c:417: trailing whitespace.
  +      ngx_http_upstream_backend_ssl_protocol, 0,

Specific exceptions can be handled via gitattributes(5).

.github/workflows/check-whitespace.yaml [new file with mode: 0644]

diff --git a/.github/workflows/check-whitespace.yaml b/.github/workflows/check-whitespace.yaml
new file mode 100644 (file)
index 0000000..f95025a
--- /dev/null
@@ -0,0 +1,49 @@
+name: Check Whitespace
+
+# Process `git log --check` output to extract just the check errors.
+
+on:
+  pull_request:
+    types: [ opened, synchronize ]
+
+jobs:
+  check-whitespace:
+    runs-on: ubuntu-24.04
+    steps:
+    - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
+      with:
+        fetch-depth: 0
+
+    - name: git log --check
+      run: |
+        echo "## Whitespace Check Results" >${GITHUB_STEP_SUMMARY}
+        err=0
+        commit=
+        while read dash hash subj
+        do
+          case "${dash}" in
+          "---")
+            err=0
+            commit="${hash} (\"${subj}\")"
+            ;;
+          "")
+            ;;
+          *)
+            if test -n "${commit}"
+            then
+              echo "" | tee -a ${GITHUB_STEP_SUMMARY}
+              echo "--- ${commit}" | tee -a ${GITHUB_STEP_SUMMARY}
+            fi
+            err=1
+            commit=
+            # Ignore the variable names, this is actually the output from
+            # git-log --check
+            echo "${dash} ${hash} ${subj}" | tee -a ${GITHUB_STEP_SUMMARY}
+            ;;
+          esac
+        done <<< $(git log --check --pretty=format:"--- %h %s" ${{github.event.pull_request.base.sha}}..)
+
+        if test ${err} -ne 0
+        then
+          exit 2
+        fi