ci: run in worktrees #31787

pull willcl-ark wants to merge 2 commits into bitcoin:master from willcl-ark:worktree-qol changing 4 files +100 −30
  1. willcl-ark commented at 4:11 pm on February 3, 2025: member

    Fixes: #30028

    • Run CI in worktrees by mounting the .git root target into the container
    • Run the linter in worktrees by mounting the .git root target into the container

    AFAIK mounting the git root should not present any additional security issues, as this would already be mounted (in RO mode) when not using a worktree.

  2. DrahtBot commented at 4:11 pm on February 3, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31787.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #31349 (ci: detect outbound internet traffic generated while running tests by vasild)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label Tests on Feb 3, 2025
  4. in ci/test/02_run_container.sh:154 in 187ee84694 outdated
    143+    --mount "${CI_CCACHE_MOUNT}"
    144+    --mount "${CI_DEPENDS_MOUNT}"
    145+    --mount "${CI_DEPENDS_SOURCES_MOUNT}"
    146+    --mount "${CI_PREVIOUS_RELEASES_MOUNT}"
    147+  )
    148+  # Add worktree root mount, if needed
    


    maflcko commented at 4:17 pm on February 3, 2025:

    Why is any .git data needed to be copied, when an init .git is sufficient?

    It would be easier to just call git init?


    willcl-ark commented at 4:54 pm on February 3, 2025:

    Hmmm, this was actually my first approach in the lint script, as it was simpler. Once I got this working in the Ci script, I backported a “matching” version to the linter script.

    Looking at:

    https://github.com/bitcoin/bitcoin/blob/1172bc4157eefe80d1aaf0b56459857ec651e535/ci/test/01_base_install.sh#L11-L16

    …I mistakenly thought that .git was actually needed, but i) it’s mounted RO, and ii) it’s only used as above here as far as I can see in the whole CI.

    Can we just touch a (any) file to persist the flag then, and drop all .git requirement?


    maflcko commented at 5:01 pm on February 3, 2025:

    …I mistakenly thought that .git was actually needed, but i) it’s mounted RO, and ii) it’s only used as above here as far as I can see in the whole CI.

    It is also used in tidy via git --no-pager diff.

    Can we just touch a (any) file to persist the flag then, and drop all .git requirement?

    Yes, but I don’t know how to do that in a one-liner cross-platform (linux+mac), taking into account the different root trees and permissions. So just using git seems simplest?


    willcl-ark commented at 8:47 pm on February 3, 2025:

    Is the (possible) running of 01_base_install.sh more than once deliberate? If so, then I’m curious why we ever do that? Is it just for the DANGER_RUN_CI_ON_HOST path or is there another use?

    If not then it seems like we could just mark install as done when building the image, something like this

    It is also used in tidy via git –no-pager diff.

    Does this not mean that it requires the actual .git directory to be mounted for the refs, meaning git init wouldn’t work in that case?


    maflcko commented at 7:58 am on February 4, 2025:

    Is the (possible) running of 01_base_install.sh more than once deliberate? If so, then I’m curious why we ever do that? Is it just for the DANGER_RUN_CI_ON_HOST path or is there another use?

    It should only install once (otherwise there will be issues). Yes, it is for DANGER_RUN_CI_ON_HOST.

    If not then it seems like we could just mark install as done when building the image, something like this

    lgtm. Could rename the file to /ci_base_install_done to include the ci prefix?

    Does this not mean that it requires the actual .git directory to be mounted for the refs, meaning git init wouldn’t work in that case?

    Just for printing the diff, as long as the repo commits to the same tree (or even the staging index is the same), it should work. I see why you opted for copying .git, as it is a bit more future-proof and less confusing, given that the commit id also ends up in the binary or may otherwise be printed in the ci script? No strong opinion on how to fix it, though.


    willcl-ark commented at 11:25 am on February 4, 2025:
    I don’t think the file touch method will work for the same reasons we discussed above (needing the actual .git dir with all its objects and refs for tidy), so have not opted to go for that currently.

    maflcko commented at 3:21 pm on February 4, 2025:
    On a second though, I guess if someone wanted to run the CI on an extracted tarball of the repo (git-archive), it would be better to also support that. Not sure if it is as trivial as git init && git add ./, so no strong opinion.
  5. DrahtBot added the label CI failed on Feb 3, 2025
  6. in test/lint/run_lint.sh:35 in 187ee84694 outdated
    30+    -it
    31+)
    32+
    33+if [[ -n "$WORKTREE_ROOT" ]]; then
    34+    # If in a worktree, mount both the current directory and the git root
    35+    DOCKER_ARGS+=(--mount "type=bind,src=$WORKTREE_ROOT,dst=$WORKTREE_ROOT,readonly")
    


    maflcko commented at 8:00 am on February 4, 2025:
    Would be good to explain why this is needed (with an example error log) and why this is the correct fix. My preference would be to fix it in the lint test_runner itself, so that everyone benefits from the fix, not just people running this ci bash script in a workdir.

    willcl-ark commented at 11:24 am on February 4, 2025:

    As far as I can tell, running bash -c '( cd ./test/lint/test_runner/ && cargo fmt && cargo clippy && RUST_BACKTRACE=1 cargo run )' in a worktree already works fine for me, because the .git directory (referenced by the .git file that a worktree creates) is available to me, unlike in the containerised scenario where this path must be explicitly mounted into the container at runtime, which is what the helper script does.

    I added some more comments to describe why the mount is needed in the script itself.

    Apologies if I’ve misunderstood what you mean here.

  7. willcl-ark force-pushed on Feb 4, 2025
  8. ci: run in worktrees
    Run CI in worktrees by mounting the .git root target into the container.
    2c33704491
  9. in test/lint/README.md:26 in 95207aa1cb outdated
    22@@ -23,7 +23,7 @@ to install the rust toolchain using your package manager of choice or
    23 Then you can use:
    24 
    25 ```sh
    26-( cd ./test/lint/test_runner/ && cargo fmt && cargo clippy && RUST_BACKTRACE=1 cargo run )
    27+( cd ./test/lint/test_runner/ && cargo fmt && cargo clippy && RUST_BACKTRACE=1 COMMIT_RANGE=$(git rev-list --merges -n 1 HEAD)..HEAD cargo run )
    


    maflcko commented at 11:07 am on February 4, 2025:
    why is this needed after 6f5ae1a574562bf3fe938f704592c5374b43091a, which has this as a fallback?

    willcl-ark commented at 11:10 am on February 4, 2025:
    It is not needed since that is now merged
  10. willcl-ark force-pushed on Feb 4, 2025
  11. in test/lint/run_lint.sh:37 in 1a67538c94 outdated
    32+    WORKTREE_ROOT=$(echo "$GIT_DIR" | sed 's/\.git\/worktrees\/.*/\.git/')
    33+    echo "Worktree root: $WORKTREE_ROOT"
    34+    DOCKER_ARGS+=(--mount "type=bind,src=$WORKTREE_ROOT,dst=$WORKTREE_ROOT")
    35+fi
    36+
    37+RUST_BACKTRACE=full docker run "${DOCKER_ARGS[@]}" bitcoin-linter
    


    maflcko commented at 11:55 am on February 4, 2025:
    0docker run "${DOCKER_ARGS[@]}" bitcoin-linter
    

    I don’t think this env var will affect anything?

    Also, style-wise I wonder if the contents of this file should be put into ci/lint_run_all.sh, so that there is only one bash script, instead of multiple.

    Ideally there would only be one script, used by ci and locally, but that can be a follow-up. For now, just a single large if in ci/lint_run_all.sh should be fine to switch between the cirrus_ci code paths ( current content of ci/lint_run_all.sh) and a local run (current content of this file).

  12. DrahtBot removed the label CI failed on Feb 4, 2025
  13. lint: run in worktrees
    Run linter in worktrees by mounting the .git root target into the
    container.
    
    Rename `get_git_root` to `get_git_toplevel` to avoid confusion around
    what this variable represents when modifying the code in the future.
    cc67e4595a
  14. willcl-ark force-pushed on Feb 4, 2025
  15. fanquake commented at 7:16 pm on February 20, 2025: member
    Is this still meant to be a draft?
  16. maflcko commented at 7:28 pm on February 20, 2025: member
    For reference, I can’t review this, because I don’t know if all the bash refactors/behavior changes here are correct and best practise, or if they could fail (and when) on error or on ancient versions of bash used in macOS.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-02-22 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me