Module: kamailio
Branch: master
Commit: 4552cec0df1ee366832e5072ffda8679b1ec100b
URL: 
https://github.com/kamailio/kamailio/commit/4552cec0df1ee366832e5072ffda8679b1ec100b

Author: Victor Seva <linuxman...@torreviejawireless.org>
Committer: Victor Seva <linuxman...@torreviejawireless.org>
Date: 2025-03-27T17:06:03+01:00

github: cmake-format lint check on PR [skip ci]

---

Added: .github/scripts/check-cmake-format.sh
Modified: .github/workflows/pull_request.yml

---

Diff:  
https://github.com/kamailio/kamailio/commit/4552cec0df1ee366832e5072ffda8679b1ec100b.diff
Patch: 
https://github.com/kamailio/kamailio/commit/4552cec0df1ee366832e5072ffda8679b1ec100b.patch

---

diff --git a/.github/scripts/check-cmake-format.sh 
b/.github/scripts/check-cmake-format.sh
new file mode 100755
index 00000000000..6c51c415831
--- /dev/null
+++ b/.github/scripts/check-cmake-format.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+COMMIT_MESSAGE_SUBJECT_FORMAT="%s"
+
+set -eu
+
+res=0
+
+git_log_format() {
+  local pattern="$1"
+  local reference="$2"
+  git log -1 --pretty=format:"$pattern" "$reference"
+}
+
+check_cmake-format() {
+  while read -r file ; do
+    if ! [ -f "${file}" ] ; then
+      continue
+    fi
+    if [[ "${file}" =~ CMakeLists.txt$ ]] || [[ "${file}" =~ \.cmake$ ]] ; then
+      echo "Checking ${file}"
+      cmake-format --check -c cmake/cmake-format.py "${file}" || res=1
+    fi
+  done < <(git diff-tree --no-commit-id --name-only -r "${1}")
+}
+
+target="${GITHUB_BASE_REF:-master}"
+if [ "${CI:-}" ]; then
+    git rev-parse -q --no-revs --verify "origin/${target}" || \
+        git rev-parse -q --no-revs --verify "${target}" || \
+        git fetch origin --depth=1 "${target}"
+    git rev-parse -q --no-revs --verify "origin/${target}" || \
+        git rev-parse -q --no-revs --verify "${target}" || \
+        git fetch origin --depth=1 tag "${target}"
+    # Ensure that the target revision has some history
+    target_sha=$(git rev-parse -q --verify "origin/${target}" || git rev-parse 
-q --verify "${target}")
+    git fetch -q "--depth=${FETCH_DEPTH:-50}" origin "+${target_sha}"
+else
+    target_sha=$(git rev-parse -q --verify "${target}") || die "fatal: 
couldn't find ref ${target}"
+fi
+
+ref=${ref:-HEAD}
+src_sha=$(git rev-parse -q --verify "${ref}") || die "fatal: couldn't find ref 
${ref}"
+echo "Checking $(git rev-list --count "${src_sha}" "^${target_sha}") commits 
since revision ${target_sha}"
+for commit in $(git rev-list --reverse "${src_sha}" "^${target_sha}"); do
+  commit_msg=$(git_log_format "${COMMIT_MESSAGE_SUBJECT_FORMAT}" "${commit}")
+  echo "[${commit}] ${commit_msg}"
+  check_cmake-format "${commit}"
+  echo "===================== done ========= "
+done
+
+echo "Result: ${res}"
+exit ${res}
diff --git a/.github/workflows/pull_request.yml 
b/.github/workflows/pull_request.yml
index dcd44cd72c8..5be003dcea8 100644
--- a/.github/workflows/pull_request.yml
+++ b/.github/workflows/pull_request.yml
@@ -14,9 +14,26 @@ jobs:
     steps:
       - name: Check out the repository to the runner
         uses: actions/checkout@v4
-      - uses: wolletd/clang-format-checker@v1.12
+      - name: Run clang-format check
+        uses: wolletd/clang-format-checker@v1.12
         with:
           target-ref: master
+  check-cmake-format:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read # to fetch code (actions/checkout)
+    steps:
+      - name: Check out the repository to the runner
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+      - uses: awalsh128/cache-apt-pkgs-action@v1.4.3
+        with:
+          packages: cmake-format
+      - name: Run scripts/check-cmake-format.sh
+        run: ./.github/scripts/check-cmake-format.sh
+        env:
+          ref: ${{ github.event.pull_request.head.sha }}
   check-commit:
     runs-on: ubuntu-latest
     permissions:

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to