-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gitlab: add a CI job for running checkpatch.pl
This job is advisory since it is expected that certain patches will fail the style checks and checkpatch.pl provides no way to mark exceptions to the rules. Signed-off-by: Daniel P. Berrangé <[email protected]> Message-Id: <[email protected]> [thuth: Use "stage: build" to let it run earlier] Signed-off-by: Thomas Huth <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/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 = "qemu-project" | ||
if len(sys.argv) >= 2: | ||
namespace = sys.argv[1] | ||
|
||
cwd = os.getcwd() | ||
reponame = os.path.basename(cwd) | ||
repourl = "https://gitlab.com/%s/%s.git" % (namespace, reponame) | ||
|
||
# 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", "master"], | ||
stdout=subprocess.DEVNULL, | ||
stderr=subprocess.DEVNULL) | ||
|
||
ancestor = subprocess.check_output(["git", "merge-base", | ||
"check-patch/master", "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", ancestor + "..."]) | ||
|
||
if ret.returncode != 0: | ||
print(" ❌ FAIL one or more commits failed scripts/checkpatch.pl") | ||
sys.exit(1) | ||
|
||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters