This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ec3631af ci: add GitHub Action to validate commit message style
2ec3631af is described below

commit 2ec3631af9514b8e38d81c3bdbcc2236c53745d9
Author: Szymon Czapracki <szymon.czapra...@codecoup.pl>
AuthorDate: Wed Jul 2 18:22:06 2025 +0200

    ci: add GitHub Action to validate commit message style
    
    This workflow checks all commits between the current branch and
    upstream/master. It enforces subject length, colon usage in the
    subject line, and body line length. This helps maintain consistency
    and readability in the project's history.
---
 .github/workflows/check_compliance.yml | 70 ++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/.github/workflows/check_compliance.yml 
b/.github/workflows/check_compliance.yml
index 536a8993e..6380aef6e 100644
--- a/.github/workflows/check_compliance.yml
+++ b/.github/workflows/check_compliance.yml
@@ -109,3 +109,73 @@ jobs:
         shell: bash
         run: |
           .github/check_doxygen.py
+
+  commits-check:
+    name: Check commit messages
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
+
+      - name: Validate commit message style
+        shell: bash
+        run: |
+          set -e
+          has_errors=0
+          
COMMIT_URL="https://cwiki.apache.org/confluence/display/MYNEWT/Contributing+to+Apache+Mynewt";
+
+          # Determine commit range for PR or fallback to origin/master
+          if [ -n "${GITHUB_BASE_REF}" ]; then
+            base_ref="origin/${GITHUB_BASE_REF}"
+          else
+            base_ref="origin/master"
+          fi
+
+          base_commit=$(git merge-base HEAD ${base_ref})
+
+          echo "Checking commits from ${base_commit} to HEAD"
+
+          for commit in $(git rev-list --no-merges ${base_commit}..HEAD); do
+            short_sha=$(git rev-parse --short=7 $commit)
+            subject=$(git log -1 --pretty=format:%s $commit)
+            body=$(git log -1 --pretty=format:%b $commit)
+
+            if [ ${#subject} -gt 72 ]; then
+              echo "Commit $short_sha subject too long (${#subject} > 72):"
+              echo "$subject"
+              has_errors=1
+            fi
+
+            if [[ "$subject" != *:* ]]; then
+              echo "Commit $short_sha subject missing colon (e.g. 'subsystem: 
msg')"
+              echo "$subject"
+              has_errors=1
+            fi
+
+            if [ -z "$body" ]; then
+              echo "Commit $short_sha body is missing"
+              has_errors=1
+            else
+              line_num=0
+              while IFS= read -r line; do
+                line_num=$((line_num + 1))
+                if [ ${#line} -gt 72 ]; then
+                  echo "Commit $short_sha body line $line_num too long 
(${#line} > 72):"
+                  echo "$line"
+                  has_errors=1
+                fi
+              done <<< "$body"
+            fi
+
+            echo ""
+          done
+
+          if [ "$has_errors" -eq 1 ]; then
+            echo "::error::Commit message check failed."
+            echo "For contributing guidelines, see:"
+            echo "  $COMMIT_URL"
+            exit 1
+          else
+            echo "All commit messages pass style rules."
+          fi

Reply via email to