diff options
author | Philippe Schenker <philippe.schenker@toradex.com> | 2021-04-07 19:55:56 +0200 |
---|---|---|
committer | Oleksandr Suvorov <oleksandr.suvorov@toradex.com> | 2021-04-07 20:05:19 +0000 |
commit | b417aeb7cbcd1f7abcb8fb1e338665c8dfc92f72 (patch) | |
tree | bcaf55c852ac526d305333e3bcfe392293c6755d /.gitlab-ci.d | |
parent | 1b055aaef346424831851f5357cf395b523fd5ba (diff) |
gitlab-ci: add scripts/checkpatch.pl
Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
Diffstat (limited to '.gitlab-ci.d')
-rwxr-xr-x | .gitlab-ci.d/check-patch.py | 50 |
1 files changed, 50 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..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) |