setup-msys2 icon indicating copy to clipboard operation
setup-msys2 copied to clipboard

Weird behavior chaining multiple commands using &&

Open jhasse opened this issue 5 years ago • 16 comments
trafficstars

I'm trying to port an AppVeyor script for wxFormBuilder to GitHub Actions. I've noticed that chaining a cd command with another one won't actually change the working directory. Only if I also add ls && at the front: https://github.com/wxFormBuilder/wxFormBuilder/pull/568/commits/c05b987ef473522dbcb5025a98abbc2aeef9bef5

I'm not really sure what's going on there, do you have an idea?

jhasse avatar Dec 01 '19 13:12 jhasse

msys2do does already include bash -c, you don't need to specify it:

https://github.com/numworks/setup-msys2/blob/a59619f8cc2c4c08e51bb0d8f2dc41d8e2dae095/index.js#L37-L39

So, your commands are expanded to:

%~dp0\\msys64\\usr\\bin\\bash.exe -ilc "cd $OLDPWD && bash -c cd build/3.0/gmake && make config=release"

%~dp0\\msys64\\usr\\bin\\bash.exe -ilc "cd $OLDPWD && bash -c ls && cd build/3.0/gmake && make config=release"

As you see, bash -c cd build/3.0/gmake and bash -c ls are executed in children shells and have no effect on the commands before or after.

eine avatar Dec 01 '19 13:12 eine

I see. How do I chain those commands using && then?

jhasse avatar Dec 01 '19 13:12 jhasse

msys2do "cd build/3.0/gmake && make config=release" should work.

eine avatar Dec 01 '19 13:12 eine

I thought so, too, but make is executed in the wrong directory then: https://github.com/wxFormBuilder/wxFormBuilder/runs/327916925

Maybe some extra quoting is required?

jhasse avatar Dec 01 '19 13:12 jhasse

I think that there's something else going on there. I just tried:

    - run: msys2do "pwd && cd .github && pwd"
    - run: msys2do "pwd; cd .github; pwd"
    - run: |
        cd .github
        msys2do pwd
  • https://github.com/1138-4EB/setup-msys2/runs/327926283#step:5:14
  • https://github.com/1138-4EB/setup-msys2/runs/327926283#step:6:14
  • https://github.com/1138-4EB/setup-msys2/runs/327926283#step:7:15

So, either the first or the last syntaxes work. The second one does only execute the first pwd, which is expected.

eine avatar Dec 01 '19 13:12 eine

Could path-type: inherit be to blame?

jhasse avatar Dec 01 '19 13:12 jhasse

I suggest to replace make config=release with pwd && ls -la, just to be sure that you are where you expect to be and that a Makefile exists.

eine avatar Dec 01 '19 13:12 eine

Could path-type: inherit be to blame?

Note that neither path-type nor update are supported in the current v1 tag. Those features were contributed to master recently, and the release has not been updated (see https://github.com/numworks/setup-msys2/pull/14#issuecomment-559025007). I wonder why it did not complain when you used options that are not defined.

eine avatar Dec 01 '19 14:12 eine

I'm in the base directory as if cd build/3.0/gmake wasn't executed: https://github.com/wxFormBuilder/wxFormBuilder/runs/327939048

jhasse avatar Dec 01 '19 14:12 jhasse

So, the issue seems to be related to the slashes? https://github.com/1138-4EB/wxFormBuilder/runs/327961332#step:12:11

eine avatar Dec 01 '19 14:12 eine

Which slashes do you mean? I think that your example works because of the pwd && in the front.

jhasse avatar Dec 01 '19 15:12 jhasse

Yes, you are correct. It is currently not supported to use &&. Some specific examples do work, but I believe that those are false positives. For your specific use case, I suggest an approach such as the following:

  • https://github.com/1138-4EB/wxFormBuilder/blob/master/.github/build.sh
  • https://github.com/1138-4EB/wxFormBuilder/blob/master/.github/workflows/windows.yml
  • https://github.com/1138-4EB/wxFormBuilder/commit/9f4d132edd22d28aa6c0895a7f48a21e61bc0411/checks?check_suite_id=336612832#step:6:36

eine avatar Dec 01 '19 17:12 eine

Thank you so much for the support :) I'm using the build script approach now.

jhasse avatar Dec 03 '19 15:12 jhasse

You are welcome! I hope that actions/toolkit#232 will eventually get some attention from engineers at GitHub, so that we can use #21. Otherwise (if args need to be processed twice, once by a cmd file and then in bash), we are likely to hit multiple issues such as this one.

eine avatar Dec 03 '19 21:12 eine

Not sure if this is the problem here, but try "set CHERE_INVOKING=yes", which makes bash keep the current working directory when executing the passed command.

lazka avatar Jan 17 '20 17:01 lazka

@lazka, I'm afraid it's unrelated. CHERE_INVOKING might replace the cd in https://github.com/numworks/setup-msys2/blob/master/index.js#L37. Nevertheless, the issue with chaining multiple commands is that bash is not called directly, but through a *.cmd file. The proper solution to this issue is actions/virtual-environments#30.

eine avatar Jan 18 '20 01:01 eine