Skip to content

Commit 6f5ae1a

Browse files
committed
Merge bitcoin#31653: lint: Call more checks from test_runner
faf8fc5 lint: Call lint_commit_msg from test_runner (MarcoFalke) fa99728 lint: Move commit range printing to test_runner (MarcoFalke) fa673cf lint: Call lint_scripted_diff from test_runner (MarcoFalke) Pull request description: The lint `commit-script-check.sh` can not be called from the test_runner at all and must be called manually. Also, some checks require `COMMIT_RANGE` to be set. Fix all issues by moving two lint checks into the test_runner. Also, the proper commit range is passed to the checks by the test_runner, so that the user no longer has to do it. ACKs for top commit: kevkevinpal: reACK [faf8fc5](bitcoin@faf8fc5) willcl-ark: tACK faf8fc5 Tree-SHA512: 78018adc618d997508c226c9eee0a4fada3899cdfd91587132ab1c0389aea69127bafc3a900e90e30aca2c6bae9dcd6e6188ef287e91413bc63ee66fb078b1af
2 parents 1172bc4 + faf8fc5 commit 6f5ae1a

File tree

3 files changed

+80
-64
lines changed

3 files changed

+80
-64
lines changed

ci/lint/06_script.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2018-2022 The Bitcoin Core developers
3+
# Copyright (c) 2018-present The Bitcoin Core developers
44
# Distributed under the MIT software license, see the accompanying
55
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
66

@@ -9,23 +9,13 @@ export LC_ALL=C
99
set -ex
1010

1111
if [ -n "$CIRRUS_PR" ]; then
12-
COMMIT_RANGE="HEAD~..HEAD"
12+
export COMMIT_RANGE="HEAD~..HEAD"
1313
if [ "$(git rev-list -1 HEAD)" != "$(git rev-list -1 --merges HEAD)" ]; then
1414
echo "Error: The top commit must be a merge commit, usually the remote 'pull/${PR_NUMBER}/merge' branch."
1515
false
1616
fi
17-
else
18-
# Otherwise, assume that a merge commit exists. This merge commit is assumed
19-
# to be the base, after which linting will be done. If the merge commit is
20-
# HEAD, the range will be empty.
21-
COMMIT_RANGE="$( git rev-list --max-count=1 --merges HEAD )..HEAD"
2217
fi
23-
export COMMIT_RANGE
2418

25-
echo
26-
git log --no-merges --oneline "$COMMIT_RANGE"
27-
echo
28-
test/lint/commit-script-check.sh "$COMMIT_RANGE"
2919
RUST_BACKTRACE=1 "${LINT_RUNNER_PATH}/test_runner"
3020

3121
if [ "$CIRRUS_REPO_FULL_NAME" = "bitcoin/bitcoin" ] && [ "$CIRRUS_PR" = "" ] ; then

test/lint/lint-git-commit-check.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

test/lint/test_runner/src/main.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ fn get_linter_list() -> Vec<&'static Linter> {
6868
name: "subtree",
6969
lint_fn: lint_subtree
7070
},
71+
&Linter {
72+
description: "Check scripted-diffs",
73+
name: "scripted_diff",
74+
lint_fn: lint_scripted_diff
75+
},
76+
&Linter {
77+
description: "Check that commit messages have a new line before the body or no body at all.",
78+
name: "commit_msg",
79+
lint_fn: lint_commit_msg
80+
},
7181
&Linter {
7282
description: "Check that tabs are not used as whitespace",
7383
name: "tabs_whitespace",
@@ -173,6 +183,21 @@ fn get_git_root() -> PathBuf {
173183
PathBuf::from(check_output(git().args(["rev-parse", "--show-toplevel"])).unwrap())
174184
}
175185

186+
/// Return the commit range, or panic
187+
fn commit_range() -> String {
188+
// Use the env var, if set. E.g. COMMIT_RANGE='HEAD~n..HEAD' for the last 'n' commits.
189+
env::var("COMMIT_RANGE").unwrap_or_else(|_| {
190+
// Otherwise, assume that a merge commit exists. This merge commit is assumed
191+
// to be the base, after which linting will be done. If the merge commit is
192+
// HEAD, the range will be empty.
193+
format!(
194+
"{}..HEAD",
195+
check_output(git().args(["rev-list", "--max-count=1", "--merges", "HEAD"]))
196+
.expect("check_output failed")
197+
)
198+
})
199+
}
200+
176201
/// Return all subtree paths
177202
fn get_subtrees() -> Vec<&'static str> {
178203
vec![
@@ -210,6 +235,55 @@ fn lint_subtree() -> LintResult {
210235
}
211236
}
212237

238+
fn lint_scripted_diff() -> LintResult {
239+
if Command::new("test/lint/commit-script-check.sh")
240+
.arg(commit_range())
241+
.status()
242+
.expect("command error")
243+
.success()
244+
{
245+
Ok(())
246+
} else {
247+
Err("".to_string())
248+
}
249+
}
250+
251+
fn lint_commit_msg() -> LintResult {
252+
let mut good = true;
253+
let commit_hashes = check_output(git().args(&[
254+
"-c",
255+
"log.showSignature=false",
256+
"log",
257+
&commit_range(),
258+
"--format=%H",
259+
]))?;
260+
for hash in commit_hashes.lines() {
261+
let commit_info = check_output(git().args([
262+
"-c",
263+
"log.showSignature=false",
264+
"log",
265+
"--format=%B",
266+
"-n",
267+
"1",
268+
hash,
269+
]))?;
270+
if let Some(line) = commit_info.lines().nth(1) {
271+
if !line.is_empty() {
272+
println!(
273+
"The subject line of commit hash {} is followed by a non-empty line. Subject lines should always be followed by a blank line.",
274+
hash
275+
);
276+
good = false;
277+
}
278+
}
279+
}
280+
if good {
281+
Ok(())
282+
} else {
283+
Err("".to_string())
284+
}
285+
}
286+
213287
fn lint_py_lint() -> LintResult {
214288
let bin_name = "ruff";
215289
let checks = format!(
@@ -650,6 +724,10 @@ fn main() -> ExitCode {
650724
};
651725

652726
let git_root = get_git_root();
727+
let commit_range = commit_range();
728+
let commit_log = check_output(git().args(["log", "--no-merges", "--oneline", &commit_range]))
729+
.expect("check_output failed");
730+
println!("Checking commit range ({commit_range}):\n{commit_log}\n");
653731

654732
let mut test_failed = false;
655733
for linter in linters_to_run {

0 commit comments

Comments
 (0)