Fixes #29972
Use a single script to run the linter locally or in CI.
Works from inside a worktree.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34391.
See the guideline for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | davidgumberg |
If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.
13+```
14+
15+Or use the included Dockerfile:
16
17 ```sh
18 DOCKER_BUILDKIT=1 docker build --platform=linux --tag=bitcoin-linter --file="./ci/lint_imagefile" ./ && docker run --rm -v $(pwd):/bitcoin -it bitcoin-linter
30+ if not content.startswith("gitdir: "):
31+ return []
32+ gitdir = (repo_root / content.removeprefix("gitdir: ")).resolve()
33+ main_gitdir = gitdir.parent.parent
34+ return [
35+ f"--volume={gitdir}:{gitdir}:ro",
0 f"--volume={gitdir}:{gitdir}",
otherwise:
0fatal: Unable to create '/btc/bitcoin/.git/worktrees/34391/index.lock': Read-only file system
alternatively, could get rid gitdir and just mount main_gitdir (without ro ):
0diff --git a/ci/lint.py b/ci/lint.py
1index ed522c6e90..eff624ce8e 100755
2--- a/ci/lint.py
3+++ b/ci/lint.py
4@@ -25,16 +25,12 @@ def run(cmd, **kwargs):
5 def get_worktree_mounts(repo_root):
6 git_path = repo_root / ".git"
7 if not git_path.is_file():
8- return []
9+ return ""
10 content = git_path.read_text().strip()
11 if not content.startswith("gitdir: "):
12- return []
13- gitdir = (repo_root / content.removeprefix("gitdir: ")).resolve()
14- main_gitdir = gitdir.parent.parent
15- return [
16- f"--volume={gitdir}:{gitdir}:ro",
17- f"--volume={main_gitdir}:{main_gitdir}:ro",
18- ]
19+ return ""
20+ gitdir = (repo_root / content.removeprefix("gitdir: ")).resolve().parent.parent
21+ return f"--volume={gitdir}:{gitdir}"
22
23
24 def main():
25@@ -71,7 +67,7 @@ def main():
26 "--rm",
27 *extra_env,
28 f"--volume={repo_root}:/bitcoin",
29- *get_worktree_mounts(repo_root),
30+ get_worktree_mounts(repo_root),
31 *([] if is_ci else ["-it"]),
32 container,
33 *sys.argv[1:],
but this is slightly less belt and suspenders I guess, no strong feelings about that.
ro from gitdir in a3c44cd2762ce1464bf2ec7abe4e2d0fd539b834
72+ *extra_env,
73+ f"--volume={repo_root}:/bitcoin",
74+ *get_worktree_mounts(repo_root),
75+ *([] if is_ci else ["-it"]),
76+ container,
77+ *sys.argv[1:],
Would be nice to add a note documenting this in the README
e.g. just mentioning that you can do:
0./ci/lint.py ./test/lint/lint-python.py
not blocking at all, feel free to disregard
Also taken in a3c44cd2762ce1464bf2ec7abe4e2d0fd539b834.
Thanks for the review!
cargo run, but I have run into a mismatch with the CI linter doing that.
Add a ci/lint.py script to run the linter both locally or inside the CI
(replacing .github/ci-lint-exec.py) which supports running from a
worktree.
Determines whether we are in a worktree, and mounts the real `.git`
directory as a read-only volume if we are.
17+
18+```sh
19+./ci/lint.py ./test/lint/lint-python.py
20 ```
21
22 Building the container can be done every time, because it is fast when the
willcl-ark
DrahtBot
maflcko
davidgumberg
Labels
Tests