kiegroup / github-action-build-chain

85 stars 24 forks source link

Cannot use shell `if` in build command #256

Closed radtriste closed 2 years ago

radtriste commented 2 years ago

Pull request config example:

version: "2.1"

dependencies:
  - project: kiegroup/drools

build:
  - project: kiegroup/drools
    build-command:
      current: |
        if [ "${{ env.DISABLE_ANYTHING }}" != 'true' ]; then mvn -f drools/pom.xml clean install -Dfull ${{ env.BUILD_MVN_OPTS }} ${{ env.BUILD_MVN_OPTS_CURRENT }} ${{ env.DROOLS_BUILD_MVN_OPTS }}; fi
      upstream: mvn clean install -Dquickly ${{ env.BUILD_MVN_OPTS }} ${{ env.BUILD_MVN_OPTS_UPSTREAM }} ${{ env.DROOLS_BUILD_MVN_OPTS_UPSTREAM }}
    clone:
      - drools

Execute this command:

$ build-chain-action -df ./pull-request-config.yaml build pr -url https://github.com/kiegroup/kogito-runtimes/pull/2253 -sp kiegroup/drools

You will get this error:

[ERROR]  [kiegroup/drools] error executing command: 'if [ "true" != 'true' ]; then mvn -f drools/pom.xml clean install -Dfull   ; fi -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B'. Message: Error: Unable to locate executable file: if. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
[ERROR]  Command executions have failed, please review latest execution Error: [kiegroup/drools] error executing command: 'if [ "true" != 'true' ]; then mvn -f drools/pom.xml clean install -Dfull   ; fi -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B'. Message: Error: Unable to locate executable file: if. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

Looks like similar to https://github.com/actions/toolkit/issues/461 with @action/exec command execution

Ginxo commented 2 years ago

the problem is here https://github.com/actions/toolkit/blob/b5f31bb5a25d129441c294fc81ba7f92f3e978ba/packages/exec/src/exec.ts#L27 the actions/exec considers the first word of the command is the tool to be used. Trying to figure out what's the best approach to handle/execute commands