dagger / dagger-for-github

GitHub Action for Dagger
https://github.com/marketplace/actions/dagger-for-github
Apache License 2.0
133 stars 25 forks source link

šŸž shell error when using multi-line yaml #117

Open lukemarsden opened 7 months ago

lukemarsden commented 7 months ago

What is the issue?

Given the following config: https://github.com/lukemarsden/test-dagger-actions/blob/c0e90ddf436947e4c6639fd95e2c491095f87ff5/.github/workflows/docker-publish.yml

In particular,

      - name: Dagger Build & Push
        uses: dagger/dagger-for-github@v5
        with:
          version: "0.11.0"
          verb: call
          args: |
            build-and-push \
            --registry=$DOCKER_REGISTRY \
            --image-name=$DOCKER_IMAGE_NAME \
            --username=$DOCKER_USERNAME \
            --password=env:DOCKER_PASSWORD
        env:
          DOCKER_REGISTRY: ${{ env.REGISTRY }}
          DOCKER_IMAGE_NAME: ${{ env.IMAGE_NAME }}
          DOCKER_USERNAME: ${{ github.actor }}
          DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

When using the multi-line string args: |, I suppose the string ends up including the trailing newline at the end, which results in the following error: https://github.com/lukemarsden/test-dagger-actions/actions/runs/8630455004/job/23656748756

In particular:

Run cd . && { \
  cd . && { \
  DAGGER_CLOUD_TOKEN= \
  dagger \
  --progress plain \
  call \
  ${INPUT_MODULE:+-m $INPUT_MODULE} \
  build-and-push \
  --registry=$DOCKER_REGISTRY \
  --image-name=$DOCKER_IMAGE_NAME \
  --username=$DOCKER_USERNAME \
  --***
  ; }
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    REGISTRY: ghcr.io
    IMAGE_NAME: lukemarsden/test-dagger-actions
    DOCKER_REGISTRY: ghcr.io
    DOCKER_IMAGE_NAME: lukemarsden/test-dagger-actions
    DOCKER_USERNAME: lukemarsden
    DOCKER_PASSWORD: ***
    INPUT_MODULE: 
/home/runner/work/_temp/18dc8cb9-bd6c-4e31-adb8-b2[96](https://github.com/lukemarsden/test-dagger-actions/actions/runs/8630455004/job/23656748756#step:3:98)01d09f1c.sh: line 12: syntax error near unexpected token `;'
Error: Process completed with exit code 2.

Switching to single line style, like:

          args: build-and-push --registry=$DOCKER_REGISTRY --image-name=$DOCKER_IMAGE_NAME --username=$DOCKER_USERNAME --password=env:DOCKER_PASSWORD --build-context .

fixes the issue, but of course is less readable

Dagger version

dagger v0.11.0 (registry.dagger.io/engine) darwin/arm64

Steps to reproduce

Run the above config

Log output

See above

esafak commented 7 months ago

Try adding a \ to the last line too.

harleylang commented 7 months ago

Try adding a \ to the last line too.

Unfortunately that does not work because part of the issue with using a multiline value for the args input is that either:

  1. The trailing semicolon gets kicked to the next line which internally results in the reported syntax error near unexpected token ';', see: https://github.com/dagger/dagger-for-github/blob/51ce834f1ada27473d258df3a1c5733e72c6b860/action.yml#L69

  2. Or if all lines have a trailing backslash and are clipped then the backslashes persist and will confuse Dagger with the observed error of Error: unknown command " --dir=." for "dagger call"

For example, this:

  args: |
    --env=${{ inputs.environment}} \
    --dir=. \
    pipeline

Is clipped to an args value of: --env=*** \ --dir=. \ pipeline and those inline backslashes are not ignored.

A workaround is to use a block chomping indicator and no backslashes. For example the following will work:

  args: >-
    --env=${{ inputs.environment}}
    --dir=.
    pipeline

I think an ideal expected behaviour for the args input should be to either: (1) handle the various ways yaml can provide a multiline value or (2) parse and throw a more verbose error that prompts users to use the above syntax. Solution 1 is probably out of scope for an action like this. But given that many folks will want to chop up their Dagger call into something readable and maintainable perhaps solution 2 would work simply by parsing the provided args with a regex and shouting for the user to review either this comment or documentation that recommends this strategy for multiline args input.