Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Support changing working directory #6

Closed
jgrund opened this issue Sep 24, 2019 · 24 comments · May be fixed by #59
Closed

Support changing working directory #6

jgrund opened this issue Sep 24, 2019 · 24 comments · May be fixed by #59
Assignees

Comments

@jgrund
Copy link

jgrund commented Sep 24, 2019

So cargo commands can be run in subdirectories.

@svartalf
Copy link
Member

Sounds like a good idea to add, smth like

- uses: actions-rs/cargo@v1
  with:
    cwd: ./sub-folder
    command: build

I'll try to add it tomorrow

@svartalf svartalf self-assigned this Sep 24, 2019
@svartalf
Copy link
Member

Btw, @jgrund, can you elaborate a little bit on your case? Do you have a cargo workspace or rust project is just laying in a sub-folder of repository root?

@jgrund
Copy link
Author

jgrund commented Sep 24, 2019

I have a top-level workspace, and then a workspace in a subfolder within the same project.

The workspaces are not tied together by cargo (one is backend code, one is wasm front-end code), so I can't use cargo -p from the top level.

@svartalf
Copy link
Member

@jgrund I researched it for a bit and found the working-directory parameter for steps, that should do the job for your case.

@Arnavion
Copy link

working-directory appears to only work for the run action (which your docs link is for), not for arbitrary actions like actions-rs/cargo

@nelsonjchen
Copy link

Here's an example of working-directory not working for non-run actions:

https://github.com/nelsonjchen/com-rs/commit/c3af52907da12cb4331c17a48e84f4a6a52afa0c/checks?check_suite_id=366094450

Could this issue be reopened?

@Arnavion
Copy link

Arnavion commented Dec 19, 2019

@nelsonjchen You should be able to do:

command: build
args: --manifest-path examples/aggregation/Cargo.toml

... instead of needing to change the working directory.

(Edit: Fixed suggestion as nelsonjchen pointed out.)

@nelsonjchen
Copy link

@Arnavion I had to use args: (only build is accepted in command:) but otherwise yeah, that works for me.

nelsonjchen/com-rs@0b6f041

Thanks!

@dbrgn
Copy link

dbrgn commented Dec 24, 2019

I also ran into this issue. A proper working-directory argument would be nice, even though the workaround seems to work.

@Xcodo
Copy link

Xcodo commented Dec 29, 2019

This tripped me up a bit today too. working_directory would be clearer than using --manifest-path for me.

@teburd
Copy link

teburd commented Mar 3, 2020

I ran into this today myself while working on using actions for CI on a complex workspace.

I would much prefer working_directory here.

@mtslzr
Copy link

mtslzr commented Mar 29, 2020

Chiming in with another +1. While the work-around works... the purpose of using a package it to have the workflow be more elegant. Adding support for working-directory is definitely preferred.

@MarcoPolo
Copy link

The workaround doesn't seem to work with cross.

Specifically I'm doing:

      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: x86_64-unknown-linux-musl
          override: true
      - uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: --release --target=x86_64-unknown-linux-musl --manifest-path hello-lambda/Cargo.toml

And it fails in an error about musl-gcc.

@MarcoPolo
Copy link

MarcoPolo commented Apr 15, 2020

As a workaround you can use my fork like so:

...
      - uses: marcopolo/cargo@master
        with:
          command: build
          working-directory: YOUR_SUBDIRECTORY

I added a PR here: #59

@svartalf
Copy link
Member

@MarcoPolo does your change works correctly with cross enabled?

@MarcoPolo
Copy link

Yes

@adamgreig
Copy link

Just to chime in with another use case for working_directory that --manifest-path doesn't cover: if you have a .cargo/config in the directory you want to build in, it's not picked up when using --manifest-path.

My repo has an embedded project in /firmware/ where .cargo/config sets the target and some rustc flags for linker scripts, so it's quite a pain to specify them as extra args to cargo, but a working_directory setting would do the trick nicely.

sorah added a commit to isucon/isucon10-portal that referenced this issue Sep 10, 2020
@tarcieri
Copy link

tarcieri commented Oct 20, 2020

FYI, we're also using @MarcoPolo's fork in conjunction with use_cross: true successfully:

RustCrypto/asm-hashes#20

It'd sure be nice if #59 got merged!

NoxHarmonium added a commit to NoxHarmonium/macbrew that referenced this issue Jan 9, 2021
@boaz-codota
Copy link

This is still something that will help greatly at 2021. @svartalf possible to merge the PR or add the existing way to the docs?

@pfmooney
Copy link

Just to chime in with another use case for working_directory that --manifest-path doesn't cover: if you have a .cargo/config in the directory you want to build in, it's not picked up when using --manifest-path.

My repo has an embedded project in /firmware/ where .cargo/config sets the target and some rustc flags for linker scripts, so it's quite a pain to specify them as extra args to cargo, but a working_directory setting would do the trick nicely.

Changing the working directory would also mean picking up any rust-toolchain specified there - a definite nice-to-have.

@lovasoa
Copy link

lovasoa commented Mar 30, 2021

Hello ! I am affected by this too. Could this issue be reopened ?

xkons added a commit to xkons/learning-rust that referenced this issue Apr 11, 2021
Michael-F-Bryan pushed a commit to hotg-ai/librunecoral that referenced this issue Jul 20, 2021
Michael-F-Bryan pushed a commit to hotg-ai/librunecoral that referenced this issue Jul 20, 2021
@jblachly
Copy link

jblachly commented Sep 4, 2021

@nelsonjchen You should be able to do:

command: build
args: --manifest-path examples/aggregation/Cargo.toml

... instead of needing to change the working directory.

(Edit: Fixed suggestion as nelsonjchen pointed out.)

This is not a suitable replacement, as the cwd as the rust binary sees it is the root; resources like .env files, static assets etc. are typically specified relative to the crate root, not the monorepo (or whatever) root

@sam0x17
Copy link

sam0x17 commented Sep 10, 2021

I am unable to use actions-rs actions on my project because of this issue and am instead manually installing cargo in a GitHub Action.

@danielhenrymantilla
Copy link

Also noting that an actual cd is needed not only for rust-toolchain files, but also .cargo/config files: --manifest-path is thus not equivalent.

danielhenrymantilla added a commit to danielhenrymantilla/next-gen-rs that referenced this issue Jan 2, 2022
danielhenrymantilla added a commit to danielhenrymantilla/next-gen-rs that referenced this issue Jan 2, 2022
danielhenrymantilla added a commit to danielhenrymantilla/next-gen-rs that referenced this issue Jan 2, 2022
nick-mobilecoin added a commit to mobilecoinfoundation/sgx that referenced this issue May 16, 2022
andrwng added a commit to andrwng/redpanda that referenced this issue Jun 12, 2023
The action-rs plugin doesn't support the working-directory syntax we
were trying to use. This commit fixes the hook by using a workaround[1].

We would previously see errors like this in CI:

Warning: Unexpected input(s) 'working-directory', valid inputs are ['command', 'toolchain', 'args', 'use-cross']
Run actions-rs/cargo@v1
/home/runner/.cargo/bin/cargo test
error: could not find `Cargo.toml` in `/home/runner/work/redpanda/redpanda` or any parent directory
Error: The process '/home/runner/.cargo/bin/cargo' failed with exit code 101

[1] actions-rs/cargo#6 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.