Skip to content

Commit

Permalink
CI: clean-up check on check compliance test
Browse files Browse the repository at this point in the history
- Rebase check_compliance.py and compliance.yml from zephyr project
- Fix checkpatch subprocess command.
- rebase

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
  • Loading branch information
arnopo committed Apr 11, 2022
1 parent eecda52 commit f27850d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
40 changes: 14 additions & 26 deletions .github/workflows/compliance.yml
Expand Up @@ -22,6 +22,7 @@ jobs:
pip3 install setuptools
pip3 install junitparser==1.6.3 gitlint
- name: Run Compliance Tests
continue-on-error: true
id: compliance
env:
BASE_REF: ${{ github.base_ref }}
Expand All @@ -31,7 +32,6 @@ jobs:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git rebase origin/${BASE_REF}
export
./scripts/ci/check_compliance.py -m checkpatch -m Gitlint -m Identity -c origin/${BASE_REF}..
- name: upload-results
Expand All @@ -46,30 +46,18 @@ jobs:
if [[ ! -s "compliance.xml" ]]; then
exit 1;
fi
if [ -s checkpatch.txt ]; then
errors=$(cat checkpatch.txt)
errors="${errors//'%'/'%25'}"
errors="${errors//$'\n'/'%0A'}"
errors="${errors//$'\r'/'%0D'}"
echo "::error file=Checkpatch.txt::$errors"
exit=1
fi
if [ -s Identity.txt ]; then
errors=$(cat Identity.txt)
errors="${errors//'%'/'%25'}"
errors="${errors//$'\n'/'%0A'}"
errors="${errors//$'\r'/'%0D'}"
echo "::error file=Identity.txt::$errors"
exit=1
fi
if [ -s Gitlint.txt ]; then
errors=$(cat Gitlint.txt)
errors="${errors//'%'/'%25'}"
errors="${errors//$'\n'/'%0A'}"
errors="${errors//$'\r'/'%0D'}"
echo "::error file=Gitlint.txt::$errors"
exit=1
fi
if [ ${exit} == 1 ]; then
for file in checkpatch.txt Identity.txt Gitlint.txt; do
if [[ -s $file ]]; then
errors=$(cat $file)
errors="${errors//'%'/'%25'}"
errors="${errors//$'\n'/'%0A'}"
errors="${errors//$'\r'/'%0D'}"
echo "::error file=${file}::$errors"
exit=1
fi
done
if [ "${exit}" == "1" ]; then
exit 1;
fi
19 changes: 4 additions & 15 deletions scripts/ci/check_compliance.py
Expand Up @@ -9,9 +9,9 @@
import re
import os
from email.utils import parseaddr
from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure, Attr
import logging
import argparse
from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure, Attr
import tempfile
import traceback
from pathlib import Path
Expand All @@ -24,10 +24,6 @@
logger = None


# This ends up as None when we're not running in a Zephyr tree
ZEPHYR_BASE = os.environ.get('ZEPHYR_BASE')


def git(*args, cwd=None):
# Helper for running a Git command. Returns the rstrip()ed stdout output.
# Called like git("diff"). Exits with SystemError (raised by sys.exit()) on
Expand Down Expand Up @@ -189,8 +185,7 @@ class CheckPatch(ComplianceTest):
path_hint = "<git-top>"

def run(self):
# Default to Zephyr's checkpatch if ZEPHYR_BASE is set
checkpatch = os.path.join(ZEPHYR_BASE or GIT_TOP, 'scripts',
checkpatch = os.path.join(GIT_TOP, 'scripts',
'checkpatch.pl')
if not os.path.exists(checkpatch):
self.skip(checkpatch + " not found")
Expand All @@ -199,19 +194,13 @@ def run(self):
diff = subprocess.Popen(('git', 'diff', COMMIT_RANGE),
stdout=subprocess.PIPE)
try:
subprocess.check_output((checkpatch, '--mailback','--mailback', '--no-tree', '-'),
subprocess.check_output(checkpatch + ' --mailback' + ' --no-tree' + ' -',
stdin=diff.stdout,
stderr=subprocess.STDOUT,
shell=True, cwd=GIT_TOP)

except subprocess.CalledProcessError as ex:
output = ex.output.decode("utf-8")
if re.search("[1-9][0-9]* errors,", output):
self.add_failure(output)
else:
# No errors found, but warnings. Show them.
self.add_info(output)

self.add_failure(output)

class GitLint(ComplianceTest):
"""
Expand Down

0 comments on commit f27850d

Please sign in to comment.