New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qa: Support git worktrees when running the linters locally via Docker #29972
Comments
Yes, this happens if you try to run any of the CI tasks locally in a worktree. |
i think the root problem here is that docker only provides access to the source directory to the container, and a worktree isn't self-contained, it contains a path to the actual repository the worktree comes from, which won't be available there. The linters need access to git metadata to do their checks (for example, to make sure that they only check files in git, not generated ones). |
At least for the "real" CI tasks, we should consider making a fallback, as I don't think much from git is needed? So far I could only find |
All git commands work in a worktree, but not when it is seperated from its main repository by containers. |
I can't reproduce that error:
|
On closer inspection, this seems to end up writing some files as root in the mypy_cache dire worktree which is not ideal as it means the worktree can't be deleted in the usual way.
DOCKER_BUILDKIT=1 docker build -t bitcoin-linter --file "./ci/lint_imagefile" ./ && GIT_DIR=$(git rev-parse --path-format=absolute --git-common-dir) docker run --rm -v $(pwd):/bitcoin -v "$GIT_DIR":"$GIT_DIR" -it bitcoin-linter
I don't think it will be possible to support worktrees in a less hacky way with the container, so the other option is to activate a python (v)env with required deps + shellcheck, and run the test-runner manually in the worktree with e.g.: cd test/lint/test_runner
COMMIT_RANGE="$( git rev-list --max-count=1 --merges HEAD )..HEAD" cargo run |
Update: To avoid creating root-owned mypy files you can run the container with your user:group specified: DOCKER_BUILDKIT=1 docker build -t bitcoin-linter --file "./ci/lint_imagefile" ./ && GIT_DIR=$(git rev-parse --path-format=absolute --git-common-dir) docker run --rm -v $(pwd):/bitcoin -v "$GIT_DIR":"$GIT_DIR" -u $(id -u):$(id -g) -it bitcoin-linter This allows |
Probably unrelated, but ideally, I'd say that the container should not modify anything on the host. The "real" CI script use a If something needs to be cached, it can be done in a persisted volume? |
Yes I agree, this bothers me too. Seems like we could perhaps use mypy's --cache-dir option to have it use I don't want to derail this issue, but in a somewhat-related changeset I was also wondering if I could speed up the linter image build (with better layer caching) by building from the python base image and absorbing the install script into the image (as part of a general python revamp in this branch). I'd be curious what you thought of this approach @maflcko (perhaps I should open another issue to discuss it?) ISTM that without the install script, and with the introduction of NB: the CI stuff in that branch is broken/WIP, and I'm not convinced in any benefit to merging |
Not sure about complicating the cirrus yml. I think it should be considered to be set in stone, because any changes will break re-running the lint task on old pull requests, IIRC. At this point, if you want to change it substantially, it could make sense to move it to GHA, along with an update to DrahtBot to be able to re-run GHA tasks. 😅 Also, not sure about dockers No objection about using more layers, if you think that is useful and needed often. |
Thanks, that's useful feedback. TBH I really don't enjoy making changes to the CI anyway. |
I discovered that running this command (from
test/lint/README.md
):doesn't work when trying to run it out of a git worktree:
(Though it did work for me when I tried checking out my branch in a regular git repo).
I don't know anything about these scripts, but if there's an easy way to support worktrees I think it would be useful!
The text was updated successfully, but these errors were encountered: