From b417aeb7cbcd1f7abcb8fb1e338665c8dfc92f72 Mon Sep 17 00:00:00 2001 From: Philippe Schenker Date: Wed, 7 Apr 2021 19:55:56 +0200 Subject: gitlab-ci: add scripts/checkpatch.pl Signed-off-by: Philippe Schenker --- .gitlab-ci.d/check-patch.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 .gitlab-ci.d/check-patch.py (limited to '.gitlab-ci.d') diff --git a/.gitlab-ci.d/check-patch.py b/.gitlab-ci.d/check-patch.py new file mode 100755 index 000000000000..0e46a8f4072a --- /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-2.3.x-imx" + +# 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) -- cgit v1.2.3