Skip to content

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

Open

Description

@JasonEtco

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.

Activity

  1. eine commented on May 22, 2020

    @eine

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

  2. JasonEtco commented on May 24, 2020

    @JasonEtco
    CollaboratorAuthor

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

  3. eine commented on May 24, 2020

    @eine

    @JasonEtco, AFAIK exec is not a bash interpreter.

  4. NorseGaud commented on May 31, 2020

    @NorseGaud

    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

  5. Ciberusps commented on Jun 12, 2020

    @Ciberusps

    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

  6. NorseGaud commented on Jun 14, 2020

    @NorseGaud

    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... :)

  7. rickstaa commented on Dec 12, 2020

    @rickstaa

    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"`)
  8. thboop commented on Apr 29, 2021

    @thboop
    Collaborator

    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.

  9. added
    enhancementNew feature or request
    and removed
    bugSomething isn't working
    on Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions