github-action icon indicating copy to clipboard operation
github-action copied to clipboard

Cannot get `command` to work

Open davidlinse opened this issue 3 years ago • 1 comments

Hi there, first of all thanks for this action. I've looked through the open issue but could not find any solution to this.

I attempt to dynamically spawn multiple jobs based on a multi-dimensional array containing the test files which is produced by a nodejs script in a prepare job using the matrix strategy.

// the array, for sake of simplicity
TEST_CHUNKS = [  [ foo.js, bar.js ], [ baz.js, qux.js ] ]

The job configuration

- name: run cypress 
  uses: cypress-io/github-action@v2
  if: always()
  with:
    ci-build-id: ${{ needs.prepare.outputs.uuid }}
    install: false
    start: npm run dev
    wait-on: 'http://localhost:3000'
    command: echo $TEST_CHUNKS | jq '.[${{ matrix.chunk-idx }}] | join(",")' | xargs npm run cypress:run -- --spec

Note: matrix.chunk-idx comes from a prepare job that provides the indexes of the TEST_CHUNKS array The log reveals, that the TEST_CHUNKS exists in the env

Run cypress-io/github-action@v2
  with:
    ci-build-id: sha-baac7166eaeda54633e1473293450254ed0c0b0f-time-1639841791
    install: false
    start: npm run dev
    wait-on: http://localhost:3000
    command: echo $TEST_CHUNKS | jq '.[2] | join(",")' | xargs npm run cypress:run -- --spec
    record: false
    config-file: cypress.json
  env:
    TEST_CHUNKS: [[ foo.js, bar.js ], [ baz.js, qux.js ]]

And finally when it comes to run the command there is just the following output, not running any of the specs

Using custom test command: echo $TEST_CHUNKS | jq '.[2] | join(",")' | xargs npm run cypress:run -- --spec
current working directory "/home/runner/work/demo"
/usr/bin/echo $TEST_CHUNKS | jq '.[2] | join(",")' | xargs npm run cypress:run -- --spec
$TEST_CHUNKS | jq '.[2] | join(",")' | xargs npm run cypress:run -- --spec

Can anyone please shed some light why the command is not working in contrast to a local machine ?

Thanks in advance and best regards

~david

davidlinse avatar Dec 18 '21 17:12 davidlinse

Update:

Using {{env.TEST_CHUNKS}} will output the complete array, so it looks like the piping to jq and following does not work.

Update:

I've done a little more debugging, and it turns out that it is probably the way how the command is handled or created behind the scenes as running the command in a plain job works as expected.

# print content of array at index 1
#
Run echo '[[ "foo.js", "bar.js" ],[ "baz.js", "qux.js" ]]' | jq '.[1] | join(",")' | xargs echo
  echo '[[ "foo.js", "bar.js" ],[ "baz.js", "qux.js" ]]' | jq '.[1] | join(",")' | xargs echo
  shell: /usr/bin/bash -e {0}

baz.js,qux.js

davidlinse avatar Dec 22 '21 14:12 davidlinse

@davidlinse

This is quite an old issue and the usage of the action is also quite specialised. Can we close this issue now?

MikeMcC399 avatar Nov 07 '23 07:11 MikeMcC399

Closing, since this is a stale, inactive issue.

MikeMcC399 avatar Nov 09 '23 11:11 MikeMcC399