Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@actions/exec doesn't support multiple commands #461

Open
JasonEtco opened this issue May 16, 2020 · 8 comments
Open

@actions/exec doesn't support multiple commands #461

JasonEtco opened this issue May 16, 2020 · 8 comments
Labels
enhancement New feature or request exec

Comments

@JasonEtco
Copy link
Collaborator

Describe the bug

Hello! I ran this script through @actions/exec:

await exec.exec('npm ci && npm run build --if-present')

It was expanded and run:

So it looks like the first npm command was prefixed with /usr/local/bin, but the second wasn't. It also didn't throw an error, which made this difficult to debug. What's the right way to

cc JasonEtco/build-and-tag-action#4

To Reproduce

Create an action:

package.json:

{
  "scripts": {
    "build": "echo \"Hello!\""
  }
}

The action:

const exec = require('@actions/exec')

async function main () {
  await exec.exec('npm ci && npm run build')
}

main()

Observe that the build command isn't properly run.

Expected behavior

I'd expect the above command to "just work" - but if not, it should throw an error instead of fail silently.

@eine
Copy link

eine commented May 22, 2020

You can use which to get the full path to npm.

@JasonEtco
Copy link
Collaborator Author

I would expect @actions/exec to do that under the hood, not just for the first command but for all commands chained with &&s.

@eine
Copy link

eine commented May 24, 2020

@JasonEtco, AFAIK exec is not a bash interpreter.

@NorseGaud
Copy link

NorseGaud commented May 31, 2020

Sure enough, this works great

    var commandsToRun = commands.replace( /&& \\\n/m, '&& ' ).split("\n");
    var commandArrayLength = commandsToRun.length;
    for (var i = 0; i < commandArrayLength; i++) {
        await exec.exec('bash', ['-c', commandsToRun[i]], options);
    }
    - uses: ./
      with:
        commands: |
          ls -laht ./
          ls -laht ../
          pwd
          echo "HERE" && \
          echo "THERE HERE WHERE"

    - uses: ./
      with:
        commands: "echo \"test1\" && echo \"Test2\" > /tmp/test && cat /tmp/test"

    - uses: ./
      with:
        commands: "./.github/workflows/test.bash 1 2 3 4"

Screen Shot 2020-05-31 at 10 57 44 AM

@Ciberusps
Copy link

imo such design create big overhead when run multiple commands
on every command exec.exec child_process spawns
its will be awesome if multiple commands execution will be added

@NorseGaud
Copy link

imo such design create big overhead when run multiple commands
on every command exec.exec child_process spawns
its will be awesome if multiple commands execution will be added

Is it big overhead though? I can't imagine any modern container/system would have a problem with this... :)

@rickstaa
Copy link

rickstaa commented Dec 12, 2020

Related to #346, #359.This would be a very nice feature to have! 🚀 I currently use the following workaround that was given in #359 by @hrueger.

LINUX/MAC:

exec.exec(`/bin/bash -c "my command"`)

WINDOWS:

exec.exec(`cmd /c "my command"`)

@thboop
Copy link
Collaborator

thboop commented Apr 29, 2021

exec isn't intended to be a bash interpreter. We don't support shell functions currently. I'm going to retag this as an enhancement.

You can use the above workaround to invoke a shell with your command and run it that way, if you need access to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request exec
Projects
None yet
Development

No branches or pull requests

6 participants