diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af71c57..120332f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -120,7 +120,6 @@ jobs: exit 1 fi - version: runs-on: "ubuntu-latest" steps: @@ -219,6 +218,27 @@ jobs: exit 1 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: runs-on: "ubuntu-latest" steps: @@ -228,4 +248,3 @@ jobs: - name: "Test Install" run: | dagger core version - diff --git a/README.md b/README.md index ea2f8eb..a462d27 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Usage Examples -### `dagger call` (default) +### `dagger call` ```yaml - name: Hello @@ -14,6 +14,16 @@ 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` ```yaml @@ -43,5 +53,6 @@ By setting the version to `latest`, this action will install the latest version | `cloud-token` | Dagger Cloud Token | false | '' | | `module` | Dagger module to call. Local or Git | 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' | diff --git a/action.yml b/action.yml index 03191cf..d47f23b 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,10 @@ inputs: description: "Function and arguments for dagger call" required: false default: "" + shell: + description: "Function and arguments for dagger shell" + required: false + default: "" outputs: output: description: "Job output" @@ -75,8 +79,25 @@ runs: curl -fsS https://dl.dagger.io/dagger/install.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 - if: inputs.call != '' || inputs.args != '' + if: inputs.call != '' || inputs.shell != '' || inputs.args != '' shell: bash env: INPUT_MODULE: ${{ inputs.module }} @@ -87,9 +108,9 @@ runs: DAGGER_CLOUD_TOKEN=${{ inputs.cloud-token }} \ dagger \ ${{ inputs.dagger-flags }} \ - ${{ inputs.verb }} \ + ${{ steps.assemble.outputs.verb }} \ ${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