Skip to content

Commit

Permalink
Merge branch 'main' into renovate/maru-code-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 authored Jun 6, 2024
2 parents 5261484 + fe71cd0 commit 0586a31
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 142 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/defenseunicorns/maru-runner
go 1.21.8

require (
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/defenseunicorns/pkg/exec v0.0.1
github.com/defenseunicorns/pkg/helpers/v2 v2.0.1
github.com/goccy/go-yaml v1.11.3
github.com/invopop/jsonschema v0.12.0
github.com/pterm/pterm v0.12.79
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.19.0
Expand All @@ -17,6 +17,8 @@ require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/defenseunicorns/pkg/helpers v1.1.1 // indirect
Expand All @@ -26,11 +28,11 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand All @@ -48,6 +50,7 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
Expand Down
16 changes: 11 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/
github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE=
github.com/MarvinJWendt/testza v0.5.2 h1:53KDo64C1z/h/d/stCYCPY69bt/OSwjq5KpFNwi+zB4=
github.com/MarvinJWendt/testza v0.5.2/go.mod h1:xu53QFE5sCdjtMCKk8YMQ2MnymimEctc4n3EjyIYvEY=
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b h1:doCpXjVwui6HUN+xgNsNS3SZ0/jUZ68Eb+mJRNOZfog=
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b/go.mod h1:/n6+1/DWPltRLWL/VKyUxg6tzsl5kHUCcraimt4vr60=
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
Expand Down Expand Up @@ -56,10 +58,11 @@ github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/hashicorp/hcl v1.0.1-vault-5 h1:kI3hhbbyzr4dldA8UdTb7ZlVVlI2DACdCfz31RPDgJM=
github.com/hashicorp/hcl v1.0.1-vault-5/go.mod h1:XYhtn6ijBSAj6n4YqAaf7RBPS4I06AItNorpy+MoQNM=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 h1:i462o439ZjprVSFSZLZxcsoAe592sZB1rci2Z8j4wdk=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
Expand All @@ -79,6 +82,8 @@ github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down Expand Up @@ -136,7 +141,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand All @@ -147,6 +151,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
Expand Down
19 changes: 14 additions & 5 deletions hack/generate-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
go run main.go internal config-tasks-schema > tasks.schema.json

# Adds pattern properties to all definitions to allow for yaml extensions
jq '.definitions |= map_values(. + {"patternProperties": {"^x-": {}}})' tasks.schema.json > temp_tasks.schema.json
mv temp_tasks.schema.json tasks.schema.json
jq '
def addPatternProperties:
. +
if has("properties") then
{"patternProperties": {"^x-": {}}}
else
{}
end;
walk(if type == "object" then addPatternProperties else . end)
' tasks.schema.json > temp_tasks.schema.json

# Modifies pattern properties to allow input parameters
jq '.definitions.Task.properties.inputs.patternProperties = {"^[_a-zA-Z][a-zA-Z0-9_-]*$": {"$schema": "http://json-schema.org/draft-04/schema#","$ref": "#/definitions/InputParameter"}}' tasks.schema.json > temp_tasks.schema.json
mv temp_tasks.schema.json tasks.schema.json
jq '.definitions.Action.properties.with.patternProperties = {"^[_a-zA-Z][a-zA-Z0-9_-]*$": {"additionalProperties": true}}' tasks.schema.json > temp_tasks.schema.json

awk '{gsub(/\[github\.com\/defenseunicorns\/maru-runner\/src\/pkg\/variables\.ExtraVariableInfo\]/, ""); print}' tasks.schema.json > temp_tasks.schema.json

mv temp_tasks.schema.json tasks.schema.json
2 changes: 1 addition & 1 deletion src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"encoding/json"
"fmt"

"github.com/alecthomas/jsonschema"
"github.com/defenseunicorns/maru-runner/src/config/lang"
"github.com/defenseunicorns/maru-runner/src/message"
"github.com/defenseunicorns/maru-runner/src/types"
"github.com/invopop/jsonschema"
"github.com/spf13/cobra"
)

Expand Down
5 changes: 5 additions & 0 deletions src/pkg/runner/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ func RunAction[T any](action *types.BaseAction[T], envFilePath string, variableC
// Template dir string
cfg.Dir = utils.TemplateString(variableConfig.GetSetVariables(), cfg.Dir)

// Template env strings
for idx := range cfg.Env {
cfg.Env[idx] = utils.TemplateString(variableConfig.GetSetVariables(), cfg.Env[idx])
}

duration := time.Duration(cfg.MaxTotalSeconds) * time.Second
timeout := time.After(duration)

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/variables/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
type Variable[T any] struct {
Name string `json:"name" jsonschema:"description=The name to be used for the variable,pattern=^[A-Z0-9_]+$"`
Pattern string `json:"pattern,omitempty" jsonschema:"description=An optional regex pattern that a variable value must match before a package deployment can continue."`
Extra T `json:",inline"`
Extra T `json:",omitempty,inline"`
}

// InteractiveVariable is a variable that can be used to prompt a user for more information
Expand Down
9 changes: 8 additions & 1 deletion src/test/e2e/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,20 @@ func TestTaskRunner(t *testing.T) {
require.Contains(t, stdErr, "overwritten env var - 8080")
})

t.Run("test that variables of type file and setting dir from a variable are processed correctly", func(t *testing.T) {
t.Run("test that setting dir from a variable is processed correctly", func(t *testing.T) {
t.Parallel()
stdOut, stdErr, err := e2e.Maru("run", "file-and-dir", "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "SECRET_KEY=not-a-secret")
})

t.Run("test that setting an env var from a variable is processed correctly", func(t *testing.T) {
t.Parallel()
stdOut, stdErr, err := e2e.Maru("run", "env-templating", "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "hello-replaced")
})

t.Run("test that env vars get used for variables that do not have a default set", func(t *testing.T) {
t.Parallel()
os.Setenv("MARU_LOG_LEVEL", "debug")
Expand Down
1 change: 0 additions & 1 deletion src/test/tasks/even-more-tasks-to-import.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ tasks:
echo "defenseunicorns"
setVariables:
- name: PRETTY_OK_COMPANY
sensitive: false
10 changes: 7 additions & 3 deletions src/test/tasks/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ variables:
- name: COOL_DIR
default: src/test/tasks
- name: COOL_FILE
type: file
default: my-env

tasks:
Expand Down Expand Up @@ -57,7 +56,6 @@ tasks:
mute: true
setVariables:
- name: ACTION_VAR
sensitive: true
- cmd: echo "I'm set from setVariables - ${ACTION_VAR}"
- cmd: echo "I'm set from a runner var - ${REPLACE_ME}"
- cmd: echo "I'm set from a --set var - ${REPLACE_ME}"
Expand Down Expand Up @@ -156,7 +154,13 @@ tasks:
actions:
- cmd: echo overwritten env var - $PORT
- name: file-and-dir
description: Tests variables of type file and setting dir from variable
description: Tests setting dir from variable
actions:
- cmd: cat ${COOL_FILE}
dir: ${COOL_DIR}
- name: env-templating
description: Tests setting an env var from variable
actions:
- cmd: echo ${HELLO_KITTEH}
env:
- HELLO_KITTEH=hello-${REPLACE_ME}
Loading

0 comments on commit 0586a31

Please sign in to comment.