cargo
cargo copied to clipboard
Running cargo commands in a subdirectory?
Do the checklist before filing an issue:
- [x] Is this related to the
actions-rsActions? 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 feature requests: https://github.com/actions-rs/.github/blob/master/CONTRIBUTING.md#feature-requests
- [ ] Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
Motivation
My understanding is this github action only supports running cargo commands from the root of the repo. Is it possible to run cargo commands from a subdirectory? The motivation is that I have a monorepo that has projects that use different languages. I'd like to run cargo commands only for the rust projects.
Additional context
I've tried to set "working-directory" at the top level but that didn't seem to work.
This is also needed if you have a workspace project and want to tests with feature flags:
$ cargo test --features 'env'
error: --features is not allowed in the root of a virtual workspace
note: while this was previously accepted, it didn't actually do anything
Actually, while digging through the source, I suspect this is an actual bug in https://github.com/actions/toolkit. If you look at this comment, it states that if cwd is unset, it defaults to the current working directory, which is set by the working-directory option in the yaml:
https://github.com/actions/toolkit/blob/ea503a235e2ad9ef6aada2f72d62cbed17d31c76/packages/exec/src/interfaces.ts#L6-L7
Perhaps this works?
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path dir1/dir2/Cargo.toml
This works around this issue. Nevertheless I think this is a bug.
I could also use a way to run cargo commands from a subdirectory, especially when using cargo deb which has a bug (https://github.com/mmstick/cargo-deb/issues/151) where it doesn't work properly if run from the workspace root.
I have a same requirement as to publish crates onto crates.io in a workspace through an action trigger.
So it seems we are waiting for #59 to be merged. As a workaround one could use marco-polos branch
I also expected this to use
defaults:
run:
working-directory: my-rust-project
As the working directory for where cargo run is run
Is there a way to do this? I cannot set the manifest path as that's not the directory I wish to run cargo from. 🙏
@lpil yes, as others stated you could use the --manifest-path:
cargo build --manifest-path /path/to/your/Cargo.toml
it'd still be neat to have this! --manifest-path doesn't work correctly with .cargo/config.toml and is usually broken when cross-compiling
I ended up changing it to this
