cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Job failing on trying to `cargo install` already existing crate

Open mr-pascal opened this issue 3 years ago • 1 comments

Do the checklist before filing an issue:

  • [x] Is this related to the actions-rs Actions? If you think it's a problem related to Github Actions in general, use GitHub Community forum instead: https://github.community
  • [x] You've read the Contributing section about bugs reporting: https://github.com/actions-rs/.github/blob/master/CONTRIBUTING.md#reporting-bugs
  • [ ] Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.

Description

On my GitHub Actions CI pipeline the actin-rs/cargo@v1 errors using the install command when, due to caching, the target crate is already installed.

Workflow code

My Workflow file: https://github.com/mr-pascal/changelog-generator/actions/runs/3451578950/workflow See the test_coverage job workflow.

# Install "grcov"
- uses: actions-rs/cargo@v1
  with:
    command: install
    args: grcov

Action output

Run actions-rs/cargo@v1
  with:
    command: install
    args: grcov
    use-cross: false
  env:
    RUSTFLAGS: -Cinstrument-coverage
    LLVM_PROFILE_FILE: coverage-%p-%m.profraw
/home/runner/.cargo/bin/cargo install grcov
    Updating crates.io index
error: binary `grcov` already exists in destination
Error: Add --force to overwrite
Error: The process '/home/runner/.cargo/bin/cargo' failed with exit code 101

Expected behavior

Instead of throwing an error and failing the job I would expect a plain "Ignored" notice, that the package already exists and the job just continues.

image

Additional context

I use caching in the workflow to speed it up significantly, as such also the previous installed grcov is kept in cache and available.

- uses: actions/cache@v3
  with:
    path: |
      ~/.cargo/bin/
      ~/.cargo/registry/index/
      ~/.cargo/registry/cache/
      ~/.cargo/git/db/
      target/
    key: ${{ runner.os }}-cargo-2-${{ hashFiles('**/Cargo.lock') }}

Using --force and just re-installing the crate is no option, since this would introduce also a re-compilation of the crate.

mr-pascal avatar Nov 12 '22 16:11 mr-pascal

ℹ️ As a workaround I used some tiny shell magic to check if it is installed and if not, install it:

if ! which grcov; then cargo install grcov; fi

Even though it would be way better and cleaner if I could use the action-rs/cargo way instead of falling back to shell scripting.

mr-pascal avatar Nov 13 '22 17:11 mr-pascal