Skip to content

Commit

Permalink
feat: implicit run args from globa parameters and options
Browse files Browse the repository at this point in the history
Formely when you call an another job with `run "JOB" { args }`, you had to explicitly set args even for global parameters/options that the JOB requires. This fixes that.

See examples/globals to see how it works.
  • Loading branch information
mumoshu committed Apr 17, 2020
1 parent e44fe22 commit 5f09f29
Show file tree
Hide file tree
Showing 12 changed files with 597 additions and 281 deletions.
12 changes: 8 additions & 4 deletions examples/defaults/defaults.variant
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ option "emptymap" {
}

option "sometuple" {
type = tuple([string,number])
default = ["x", 1]
type = tuple([string,number,bool])
default = ["x", 1, true]
}

option "someobj" {
type = object({foo=string, bar=number})
default = {foo="FOO", bar=1}
type = object({foo=string, bar=number, baz=bool})
default = {foo="FOO", bar=1, baz=true}
}

job "example" {
Expand All @@ -46,13 +46,17 @@ emptymap.foo=${try(opt.emptymap.foo, "FOO")}

sometuple.0=${opt.sometuple.0}
sometuple.1=${opt.sometuple.1}
sometuple.2=${opt.sometuple.2}
sometuple[0]=${opt.sometuple[0]}
sometuple[1]=${opt.sometuple[1]}
sometuple[2]=${opt.sometuple[2]}

someobj.foo=${opt.someobj.foo}
someobj.bar=${opt.someobj.bar}
someobj.baz=${opt.someobj.baz}
someobj["foo"]=${opt.someobj["foo"]}
someobj["bar"]=${opt.someobj["bar"]}
someobj["baz"]=${opt.someobj["baz"]}
EOF
EOS
]
Expand Down
4 changes: 4 additions & 0 deletions examples/defaults/defaults_test.variant
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ emptymap.foo=FOO

sometuple.0=x
sometuple.1=1
sometuple.2=true
sometuple[0]=x
sometuple[1]=1
sometuple[2]=true

someobj.foo=FOO
someobj.bar=1
someobj.baz=true
someobj["foo"]=FOO
someobj["bar"]=1
someobj["baz"]=true
EOS
)
exitstatus = 0
Expand Down
72 changes: 72 additions & 0 deletions examples/globals/example.variant
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
parameter "global_param" {
type = string
default = "A"
}

option "global_opt" {
type = string
default = "B"
}

job "example" {
parameter "local_param" {
type = string
default = "C"
}

option "local_opt" {
type = string
default = "D"
}

step "call sub" {
run "sub" {
param1 = "E"
}
}

step "call echo" {
run "echo" {
text = <<EOS
example:global_param=${param.global_param}
example:global_opt=${opt.global_opt}
example:local_param=${param.local_param}
example:local_opt=${opt.local_opt}
EOS
}
}
}

job "sub" {
parameter "param1" {
type = string
}

run {
job = "echo"
with = {
text = <<EOS
sub:global_param=${param.global_param}
sub:global_opt=${opt.global_opt}
sub:param1=${param.param1}
EOS
}
}
}

job "echo" {
option "text" {
type = string
}

exec {
command = "bash"
args = [
"-c", <<EOS
cat <<EOF
${opt.text}
EOF
EOS
]
}
}
26 changes: 26 additions & 0 deletions examples/globals/example_test.variant
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
test "example" {
case "ok" {
out = <<EOS
sub:global_param=A
sub:global_opt=B
sub:param1=E

example:global_param=A
example:global_opt=B
example:local_param=C
example:local_opt=D
EOS
exitstatus = 0
}

run "example" {
}

assert "out" {
condition = run.res.stdout == case.out
}

assert "exitstatus" {
condition = run.res.exitstatus == case.exitstatus
}
}
5 changes: 5 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func TestExamples(t *testing.T) {
args: []string{"variant", "test"},
wd: "./examples/variables",
},
{
subject: "examples/globals",
args: []string{"variant", "test"},
wd: "./examples/globals",
},
{
subject: "examples/advaned/terraform-and-helmfile-wrapper",
args: []string{"variant", "test"},
Expand Down
Loading

0 comments on commit 5f09f29

Please sign in to comment.