Merge pull request #76 from blocklayerhq/output-no-merge

output: merge base/input/output into a single state.cue
This commit is contained in:
Andrea Luzzardi 2021-01-26 16:53:32 -08:00 committed by GitHub
commit cc5a48d39b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 89 additions and 3 deletions

View File

@ -118,11 +118,27 @@ func (env *Env) Export(fs FS) (FS, error) {
// client which is undesirable. // client which is undesirable.
// Once Value.Save() resolves non-builtin imports with a tree shake, // Once Value.Save() resolves non-builtin imports with a tree shake,
// we can use it here. // 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 { 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 return fs, nil
} }

View File

@ -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"
},
]
}

View File

@ -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"
},
]
}

View File

@ -186,6 +186,21 @@ test::mount(){
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mount/valid/script "$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(){ test::all(){
local dagger="$1" local dagger="$1"
@ -199,6 +214,7 @@ test::all(){
test::fetchgit "$dagger" test::fetchgit "$dagger"
test::exec "$dagger" test::exec "$dagger"
test::export "$dagger" test::export "$dagger"
test::input "$dagger"
} }
case "${1:-all}" in case "${1:-all}" in