Proper support for shell input (#189)

* add options for shell

Signed-off-by: kpenfound <kyle@dagger.io>

assemble dagger command in new step with output

Signed-off-by: kpenfound <kyle@dagger.io>

fixing some inline bash

Signed-off-by: kpenfound <kyle@dagger.io>

wrap conditional inputs in quotes

Signed-off-by: kpenfound <kyle@dagger.io>

use cat for heredoc script file

Signed-off-by: kpenfound <kyle@dagger.io>

missing space in heredoc

Signed-off-by: kpenfound <kyle@dagger.io>

add tab ignore and dagger shebang

Signed-off-by: kpenfound <kyle@dagger.io>

use toJson and jq to safely write the shell input to a file

Signed-off-by: kpenfound <kyle@dagger.io>

put DAGGER_COMMAND in a variable

Signed-off-by: kpenfound <kyle@dagger.io>

missing semicolon for the dagger command

Signed-off-by: kpenfound <kyle@dagger.io>

safely evaluate if shell is set

Signed-off-by: kpenfound <kyle@dagger.io>

extra > in shell file write

Signed-off-by: kpenfound <kyle@dagger.io>

add some logging

Signed-off-by: kpenfound <kyle@dagger.io>

strip extra newline from jq when shell is not set

Signed-off-by: kpenfound <kyle@dagger.io>

debugging

Signed-off-by: kpenfound <kyle@dagger.io>

toJSON and jq will send null instead of empty string with no input

Signed-off-by: kpenfound <kyle@dagger.io>

safely handle all inputs

Signed-off-by: kpenfound <kyle@dagger.io>

did i fix the wrong thing?

Signed-off-by: kpenfound <kyle@dagger.io>

change up the approach a bit for an easier diff

Signed-off-by: kpenfound <kyle@dagger.io>

fix shell test

Signed-off-by: kpenfound <kyle@dagger.io>

single quotes around shell input

Signed-off-by: kpenfound <kyle@dagger.io>

try with piped input

Signed-off-by: kpenfound <kyle@dagger.io>

try single quotes again

Signed-off-by: kpenfound <kyle@dagger.io>

debug

Signed-off-by: kpenfound <kyle@dagger.io>

debug

Signed-off-by: kpenfound <kyle@dagger.io>

fix shell test

Signed-off-by: kpenfound <kyle@dagger.io>

does shell emit a newline?

Signed-off-by: kpenfound <kyle@dagger.io>

remove the trailing newline if its in stdout

Signed-off-by: kpenfound <kyle@dagger.io>

break the trailing output test

Signed-off-by: kpenfound <kyle@dagger.io>

fix shell test

Signed-off-by: kpenfound <kyle@dagger.io>

missed !

Signed-off-by: kpenfound <kyle@dagger.io>

add comment about weird test

Signed-off-by: kpenfound <kyle@dagger.io>

* use echo -n in shell test

Signed-off-by: kpenfound <kyle@dagger.io>

---------

Signed-off-by: kpenfound <kyle@dagger.io>
This commit is contained in:
Kyle Penfound 2025-09-16 13:19:53 -04:00 committed by GitHub
parent 710906f307
commit 4e0ad19142
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 7 deletions

View file

@ -120,7 +120,6 @@ jobs:
exit 1 exit 1
fi fi
version: version:
runs-on: "ubuntu-latest" runs-on: "ubuntu-latest"
steps: steps:
@ -219,6 +218,27 @@ jobs:
exit 1 exit 1
fi fi
shell:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: "Test shell"
id: test-shell
uses: ./
with:
shell: 'container | from alpine | with-exec echo,-n,"hello world!" | stdout'
- name: "Test shell (check)"
run: |
target='${{ steps.test-shell.outputs.output }}'
result='hello world!'
if [[ "$target" == "$result" ]]; then
echo "matches"
exit 0
else
echo "does not match"
exit 1
fi
nocall: nocall:
runs-on: "ubuntu-latest" runs-on: "ubuntu-latest"
steps: steps:
@ -228,4 +248,3 @@ jobs:
- name: "Test Install" - name: "Test Install"
run: | run: |
dagger core version dagger core version

View file

@ -2,7 +2,7 @@
## Usage Examples ## Usage Examples
### `dagger call` (default) ### `dagger call`
```yaml ```yaml
- name: Hello - name: Hello
@ -14,6 +14,16 @@
version: "latest" # semver x.y.z version: "latest" # semver x.y.z
``` ```
### `dagger shell`
```yaml
- name: Hello
uses: dagger/dagger-for-github@8.0.0
with:
shell: container | from alpine | with-exec echo,"hello, world!" | stdout
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
```
### `dagger run` ### `dagger run`
```yaml ```yaml
@ -43,5 +53,6 @@ By setting the version to `latest`, this action will install the latest version
| `cloud-token` | Dagger Cloud Token | false | '' | | `cloud-token` | Dagger Cloud Token | false | '' |
| `module` | Dagger module to call. Local or Git | false | '' | | `module` | Dagger module to call. Local or Git | false | '' |
| `args` | Arguments to pass to CLI | false | '' | | `args` | Arguments to pass to CLI | false | '' |
| `call` | Arguments to pass to CLI (Alias for args) | false | '' | | `call` | Arguments to pass to CLI (Alias for args with verb:call) | false | '' |
| `shell` | Arguments to pass to CLI (Alias for args with verb:shell) | false | '' |
| `engine-stop` | Whether to stop the Dagger Engine after this run | false | 'true' | | `engine-stop` | Whether to stop the Dagger Engine after this run | false | 'true' |

View file

@ -40,6 +40,10 @@ inputs:
description: "Function and arguments for dagger call" description: "Function and arguments for dagger call"
required: false required: false
default: "" default: ""
shell:
description: "Function and arguments for dagger shell"
required: false
default: ""
outputs: outputs:
output: output:
description: "Job output" description: "Job output"
@ -75,8 +79,25 @@ runs:
curl -fsS https://dl.dagger.io/dagger/install.sh \ curl -fsS https://dl.dagger.io/dagger/install.sh \
| BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh | BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
- id: assemble
if: inputs.call != '' || inputs.shell != '' || inputs.args != ''
shell: bash
env:
INPUT_MODULE: ${{ inputs.module }}
run: |
verb=${{ inputs.verb }}
shell=$(echo '${{ toJSON(inputs.shell) }}' | jq -rj .)
if [[ -n "${{ inputs.call }}" ]]; then
verb="call"
elif [[ "$shell" != "" ]]; then
verb=""
script=$(mktemp)
printf '%s' "$shell" > $script
fi
echo "script=$script" >> "$GITHUB_OUTPUT"
echo "verb=$verb" >> "$GITHUB_OUTPUT"
- id: exec - id: exec
if: inputs.call != '' || inputs.args != '' if: inputs.call != '' || inputs.shell != '' || inputs.args != ''
shell: bash shell: bash
env: env:
INPUT_MODULE: ${{ inputs.module }} INPUT_MODULE: ${{ inputs.module }}
@ -87,9 +108,9 @@ runs:
DAGGER_CLOUD_TOKEN=${{ inputs.cloud-token }} \ DAGGER_CLOUD_TOKEN=${{ inputs.cloud-token }} \
dagger \ dagger \
${{ inputs.dagger-flags }} \ ${{ inputs.dagger-flags }} \
${{ inputs.verb }} \ ${{ steps.assemble.outputs.verb }} \
${INPUT_MODULE:+-m $INPUT_MODULE} \ ${INPUT_MODULE:+-m $INPUT_MODULE} \
${{ inputs.args || inputs.call }}; } 1> >(tee "${tmpout}") 2> >(tee "${tmperr}" >&2) ${{ inputs.args || inputs.call || steps.assemble.outputs.script }}; } 1> >(tee "${tmpout}") 2> >(tee "${tmperr}" >&2)
{ {
# we need a delim that doesn't appear in the output - a hash of the # we need a delim that doesn't appear in the output - a hash of the