dagger-for-github icon indicating copy to clipboard operation
dagger-for-github copied to clipboard

fix: Action now parses "\" line seperator

Open squizzi opened this issue 10 months ago • 1 comments

When trying to use this action I tried to provide multi-line args to my call command, for example:

      - name: Run Something
        uses: dagger/dagger-for-github@v7
        env:
         API_TOKEN: ${{ steps.set-token.outputs.api_token }}
        with:
          cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN}}
          version: "latest"
          verb: call
          args: some-command \
            --token=env:API_TOKEN \
            --progress=plain

Which was resulting in a very perplexing error regarding required flags even when I could copy/paste the exact command from actions into my local CLI and run it fine:

Error: required flag(s) "token" not set

I realized that the with.args was wanting all of the args to sit on the same line and the \ separator was breaking the interpretation of those args.

So I updated the arg parsing in the bash in the action to support this use case. You can run this example to simulate the action input and the result:

#!/usr/bin/env bash

# Example: Simulate receiving multi-line args (as a single string)
ARGS_INPUT="--foo bar \
--baz qux \
--flag"

# Remove backslash-newline and any trailing spaces, do not include backslash in args
ARGS=$(echo "$ARGS_INPUT" | awk '{sub(/[ \t]*\\$/, ""); printf "%s", $0; if (!/[ \t]*\\$/) print ""}')

# Convert to array
read -r -a ARGS_ARRAY <<< "$ARGS"

# Show the resulting array
echo "Parsed arguments:"
for arg in "${ARGS_ARRAY[@]}"; do
  echo "[$arg]"
done

echo "Result: dagger call some-call-command ${ARGS_ARRAY[@]}"

For example:

./bash-example.sh
Parsed arguments:
[--foo]
[bar]
[--baz]
[qux]
[--flag]
Result: dagger call some-call-command --foo bar --baz qux --flag

squizzi avatar May 01 '25 22:05 squizzi

The folded style also doesn't work around this:

      - name: Run Something
        uses: dagger/dagger-for-github@v7
        env:
         API_TOKEN: ${{ steps.set-token.outputs.api_token }}
        with:
          cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN}}
          version: "latest"
          verb: call
          args: >
            some-command
            --token=env:API_TOKEN
            --progress=plain

squizzi avatar May 01 '25 22:05 squizzi