summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Schenker <philippe.schenker@toradex.com>2021-04-07 19:55:56 +0200
committerPhilippe Schenker <philippe.schenker@toradex.com>2021-04-08 15:40:49 +0200
commit9f11bcae20cae26d5d6983319fe9db7125e314c4 (patch)
treee1a2658262caf2d2045b4160ae2e56bc3add5acd
parent77ea21970b40ba6547cbada228904914a1ba2c11 (diff)
gitlab-ci: add scripts/checkpatch.pl
Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
-rwxr-xr-x.gitlab-ci.d/check-patch.py50
-rw-r--r--.gitlab-ci.yml9
2 files changed, 59 insertions, 0 deletions
diff --git a/.gitlab-ci.d/check-patch.py b/.gitlab-ci.d/check-patch.py
new file mode 100755
index 000000000000..9cf16ebdafdc
--- /dev/null
+++ b/.gitlab-ci.d/check-patch.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+#
+# check-patch.py: run checkpatch.pl across all commits in a branch
+#
+# Copyright (C) 2020 Red Hat, Inc.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import os
+import os.path
+import sys
+import subprocess
+
+namespace = "linux-bsp"
+if len(sys.argv) >= 2:
+ namespace = sys.argv[1]
+
+cwd = os.getcwd()
+reponame = os.path.basename(cwd)
+repourl = "https://gitlab.int.toradex.com/rd/%s/%s.git" % (namespace, reponame)
+masterbranch = "toradex_5.4.y"
+
+# GitLab CI environment does not give us any direct info about the
+# base for the user's branch. We thus need to figure out a common
+# ancestor between the user's branch and current git master.
+subprocess.check_call(["git", "remote", "add", "check-patch", repourl])
+subprocess.check_call(["git", "fetch", "check-patch", masterbranch],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL)
+
+ancestor = subprocess.check_output(["git", "merge-base",
+ "check-patch/" + masterbranch, "HEAD"],
+ universal_newlines=True)
+
+ancestor = ancestor.strip()
+
+subprocess.check_call(["git", "remote", "rm", "check-patch"])
+
+errors = False
+
+print("\nChecking all commits since %s...\n" % ancestor)
+
+ret = subprocess.run(["scripts/checkpatch.pl", "-g", ancestor + "..."])
+
+if ret.returncode != 0:
+ print(ret)
+ print(" ❌ FAIL one or more commits failed scripts/checkpatch.pl")
+ sys.exit(1)
+
+sys.exit(0)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e79f21ea719d..fef15bf02a2b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -17,6 +17,7 @@ variables:
TEMP_BUILD_FOLDER: /builds/temp-builds
stages:
+ - check-patch
- build-product
.build_base:
@@ -59,6 +60,14 @@ stages:
- set -o xtrace
- rm -rf $TEMP_BUILD_FOLDER
+check_patch:
+ stage: check-patch
+ script: .gitlab-ci.d/check-patch.py
+ variables:
+ GIT_STRATEGY: fetch
+ GIT_DEPTH: 1000
+ allow_failure: true
+
# If you need additional products build just copy-paste build_******_product section with new config name
build_default_defconfig :
extends: .build_base