๐ shell error when using multi-line yaml
lukemarsden opened this issue ยท 2 comments
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
Try adding a \
to the last line too.
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:
-
The trailing semicolon gets kicked to the next line which internally results in the reported
syntax error near unexpected token ';'
, see:Line 69 in 51ce834
-
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.