From 6eb5063ddc8fc6732b764e12a0a84ef72d6a8e52 Mon Sep 17 00:00:00 2001
From: Anas Nashif <anas.nashif@intel.com>
Date: Wed, 24 Mar 2021 10:54:54 -0400
Subject: [PATCH] ci: add coding guideline workflow

Use coccinelle rules to detect coding guideline violations on submitted
code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
---
 .github/workflows/coding_guidelines.yml | 59 +++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 .github/workflows/coding_guidelines.yml

diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml
new file mode 100644
index 00000000000..27528b68726
--- /dev/null
+++ b/.github/workflows/coding_guidelines.yml
@@ -0,0 +1,59 @@
+name: Coding Guidelines
+
+on: pull_request
+
+jobs:
+  compliance_job:
+    runs-on: ubuntu-latest
+    name: Run coding guidelines checks on patch series (PR)
+    steps:
+    - name: Checkout the code
+      uses: actions/checkout@v2
+      with:
+        ref: ${{ github.event.pull_request.head.sha }}
+        fetch-depth: 0
+
+    - name: cache-pip
+      uses: actions/cache@v1
+      with:
+        path: ~/.cache/pip
+        key: ${{ runner.os }}-doc-pip
+
+    - name: Install python dependencies
+      run: |
+        pip3 install unidiff
+        pip3 install wheel
+        pip3 install sh
+
+    - name: Install Packages
+      run: |
+        sudo apt-get install ocaml-base-nox
+        wget https://launchpad.net/~npalix/+archive/ubuntu/coccinelle/+files/coccinelle_1.0.8~20.04npalix1_amd64.deb
+        sudo dpkg -i coccinelle_1.0.8~20.04npalix1_amd64.deb
+
+    - name: Run Coding Guildeines Checks
+      continue-on-error: true
+      id: coding_guidelines
+      env:
+        BASE_REF: ${{ github.base_ref }}
+      run: |
+        export ZEPHYR_BASE=$PWD
+        source zephyr-env.sh
+        # debug
+        ls -la
+        git log  --pretty=oneline | head -n 10
+        ./scripts/ci/guideline_check.py --output output.txt -c origin/${BASE_REF}..
+
+    - name: check-warns
+      run: |
+        if [[ -s "output.txt" ]]; then
+            errors=$(cat output.txt)
+            errors="${errors//'%'/'%25'}"
+            errors="${errors//$'\n'/'%0A'}"
+            errors="${errors//$'\r'/'%0D'}"
+            echo "::error file=output.txt::$errors"
+            exit=1
+        fi
+        if [ ${exit} == 1 ]; then
+          exit 1;
+        fi
-- 
GitLab