summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Suvorov <oleksandr.suvorov@toradex.com>2021-04-09 12:18:16 +0300
committerOleksandr Suvorov <oleksandr.suvorov@toradex.com>2021-04-09 14:43:18 +0300
commit2d971f3c057e1c1023b41fa7910906a26ed043bd (patch)
treead0a81ab77af7f502e09aaf944a74c475f93c4f2
parent9f11bcae20cae26d5d6983319fe9db7125e314c4 (diff)
gitlab-ci: check-patch: fix remote branch issue
If check-patch.pl raises an exception, it may leave the remote source "check-patch" undeleted. And all further calls on the repo will fail. Fix this issue, adding the PID modifier to the repote source name and making removing this source mandatory. Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com> (cherry-picked from commit 6f73903d685a476bbf8bd70bd795b993b4efef60)
-rwxr-xr-x.gitlab-ci.d/check-patch.py42
1 files changed, 24 insertions, 18 deletions
diff --git a/.gitlab-ci.d/check-patch.py b/.gitlab-ci.d/check-patch.py
index 9cf16ebdafdc..38c54d93751d 100755
--- a/.gitlab-ci.d/check-patch.py
+++ b/.gitlab-ci.d/check-patch.py
@@ -17,34 +17,40 @@ if len(sys.argv) >= 2:
cwd = os.getcwd()
reponame = os.path.basename(cwd)
+if len(sys.argv) >= 3:
+ reponame = sys.argv[2]
+
repourl = "https://gitlab.int.toradex.com/rd/%s/%s.git" % (namespace, reponame)
masterbranch = "toradex_5.4.y"
+check_patch_branch = "check-patch-%d" % os.getpid()
+rc = 0
# 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)
+subprocess.check_call(["git", "remote", "add", check_patch_branch, repourl])
+try:
+ subprocess.check_call(["git", "fetch", check_patch_branch, masterbranch],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL)
-ancestor = ancestor.strip()
+ ancestor = subprocess.check_output(["git", "merge-base",
+ check_patch_branch + "/" + masterbranch, "HEAD"],
+ universal_newlines=True)
-subprocess.check_call(["git", "remote", "rm", "check-patch"])
+ ancestor = ancestor.strip()
-errors = False
+ errors = False
-print("\nChecking all commits since %s...\n" % ancestor)
+ print("\nChecking all commits since %s...\n" % ancestor)
-ret = subprocess.run(["scripts/checkpatch.pl", "-g", 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)
+ if ret.returncode != 0:
+ print(ret)
+ print(" ❌ FAIL one or more commits failed scripts/checkpatch.pl")
+ rc = 1
+finally:
+ subprocess.check_call(["git", "remote", "rm", check_patch_branch])
-sys.exit(0)
+sys.exit(rc)