diff --git a/dagger/env.go b/dagger/env.go index c0e61f8f..ac4909ac 100644 --- a/dagger/env.go +++ b/dagger/env.go @@ -118,11 +118,27 @@ func (env *Env) Export(fs FS) (FS, error) { // client which is undesirable. // Once Value.Save() resolves non-builtin imports with a tree shake, // we can use it here. - fs = env.base.SaveJSON(fs, "base.cue") - fs = env.input.SaveJSON(fs, "input.cue") + + // FIXME: Exporting base/input/output separately causes merge errors. + // For instance, `foo: string | *"default foo"` gets serialized as + // `{"foo":"default foo"}`, which will fail to merge if output contains + // a different definition of `foo`. + // + // fs = env.base.SaveJSON(fs, "base.cue") + // fs = env.input.SaveJSON(fs, "input.cue") + // if env.output != nil { + // fs = env.output.SaveJSON(fs, "output.cue") + // } + // For now, export a single `state.cue` containing the combined output. + var err error + state := env.state if env.output != nil { - fs = env.output.SaveJSON(fs, "output.cue") + state, err = state.Merge(env.output) + if err != nil { + return env.s.Scratch(), err + } } + fs = state.SaveJSON(fs, "state.cue") return fs, nil } diff --git a/examples/tests/input/default/main.cue b/examples/tests/input/default/main.cue new file mode 100644 index 00000000..a9f82425 --- /dev/null +++ b/examples/tests/input/default/main.cue @@ -0,0 +1,27 @@ +package testing + +X1=in: string | *"default input" + +test: { + string + + #dagger: compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + args: ["sh", "-c", """ + echo -n "received: \(X1)" > /out + """] + // XXX Blocked by https://github.com/blocklayerhq/dagger/issues/19 + dir: "/" + }, + { + do: "export" + source: "/out" + format: "string" + }, + ] +} diff --git a/examples/tests/input/simple/main.cue b/examples/tests/input/simple/main.cue new file mode 100644 index 00000000..5364d6d9 --- /dev/null +++ b/examples/tests/input/simple/main.cue @@ -0,0 +1,27 @@ +package testing + +X1=in: string + +test: { + string + + #dagger: compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + args: ["sh", "-c", """ + echo -n "received: \(X1)" > /out + """] + // XXX Blocked by https://github.com/blocklayerhq/dagger/issues/19 + dir: "/" + }, + { + do: "export" + source: "/out" + format: "string" + }, + ] +} diff --git a/examples/tests/test.sh b/examples/tests/test.sh index 338ef92e..59645222 100755 --- a/examples/tests/test.sh +++ b/examples/tests/test.sh @@ -163,6 +163,21 @@ test::mount(){ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mount/valid/script } +test::input() { + test::one "Input: missing input should skip execution" --exit=0 --stdout='{}' \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/input/simple + + test::one "Input: simple input" --exit=0 --stdout='{"in":"foobar","test":"received: foobar"}' \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input 'in: "foobar"' "$d"/input/simple + + test::one "Input: default values" --exit=0 --stdout='{"in":"default input","test":"received: default input"}' \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/input/default + + test::one "Input: override default value" --exit=0 --stdout='{"in":"foobar","test":"received: foobar"}' \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input 'in: "foobar"' "$d"/input/default +} + + test::all(){ local dagger="$1" @@ -176,6 +191,7 @@ test::all(){ test::fetchgit "$dagger" test::exec "$dagger" test::export "$dagger" + test::input "$dagger" } case "${1:-all}" in