Skip to content

Commit

Permalink
fix: task schema generation using maru and removing runner tests (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
decleaver committed Jul 12, 2024
1 parent e53e92e commit 6b50d20
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 292 deletions.
20 changes: 14 additions & 6 deletions hack/generate-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ mv temp_uds.schema.json uds.schema.json
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
mv temp_tasks.schema.json 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

# Create the json schema for zarf.yaml
go run main.go zarf internal gen-config-schema > zarf.schema.json
Expand Down
13 changes: 4 additions & 9 deletions src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/alecthomas/jsonschema"
runnerCLI "github.com/defenseunicorns/maru-runner/src/cmd"
"github.com/defenseunicorns/uds-cli/src/config/lang"
"github.com/defenseunicorns/uds-cli/src/types"
"github.com/defenseunicorns/zarf/src/pkg/message"
Expand Down Expand Up @@ -45,15 +46,9 @@ var configTasksSchemaCmd = &cobra.Command{
Use: "config-tasks-schema",
Aliases: []string{"c"},
Short: lang.CmdInternalConfigSchemaShort,
RunE: func(_ *cobra.Command, _ []string) error {
schema := jsonschema.Reflect(&types.TasksFile{})
output, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return fmt.Errorf(lang.CmdInternalConfigSchemaErr)
}
fmt.Print(string(output) + "\n")

return nil
Run: func(cmd *cobra.Command, input []string) {
runnerCLI.RootCmd().SetArgs([]string{"internal", "config-tasks-schema"})
runnerCLI.Execute()
},
}

Expand Down
49 changes: 0 additions & 49 deletions src/types/tasks.go

This file was deleted.

Loading

0 comments on commit 6b50d20

Please sign in to comment.