Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions dgctl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.PHONY: build clean test schema schema-docs

# Binary name
BINARY_NAME=dgctl

# Build the dgctl binary
build:
go build -o $(BINARY_NAME) ./main.go

# Clean build artifacts
clean:
rm -f $(BINARY_NAME)
rm -f schema.json

# Run tests
test:
go test -v ./...

# Generate JSON Schema for digger.yml and output to stdout
schema:
go run . schema

# Generate JSON Schema and save to docs folder
schema-docs:
go run . schema -o ./schema.json
@echo "Schema generated at ./schema.json"

# Install dependencies
deps:
go mod tidy

# Run the schema command and verify it works
verify-schema:
@echo "Generating schema..."
@go run . schema > /dev/null && echo "Schema generation successful" || echo "Schema generation failed"
83 changes: 83 additions & 0 deletions dgctl/cmd/schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright © 2024 diggerhq

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"encoding/json"
"fmt"
"os"
"reflect"

"github.com/diggerhq/digger/libs/digger_config"
"github.com/invopop/jsonschema"
"github.com/spf13/cobra"
)

var outputFile string

// schemaCmd represents the schema command
var schemaCmd = &cobra.Command{
Use: "schema",
Short: "Generate JSON Schema for digger.yml",
Long: `Generate a JSON Schema from the digger.yml configuration structure.

Examples:
dgctl schema # Output schema to stdout
dgctl schema -o schema.json # Write schema to file
dgctl schema --output docs/schema.json`,
Run: func(cmd *cobra.Command, args []string) {
schema := generateSchema()

jsonBytes, err := json.MarshalIndent(schema, "", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "Error marshaling schema: %v\n", err)
os.Exit(1)
}

if outputFile != "" {
err = os.WriteFile(outputFile, jsonBytes, 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "Error writing schema to file: %v\n", err)
os.Exit(1)
}
fmt.Printf("Schema written to %s\n", outputFile)
} else {
fmt.Println(string(jsonBytes))
}
},
}

func generateSchema() *jsonschema.Schema {
r := &jsonschema.Reflector{
KeyNamer: jsonschema.ToSnakeCase,
RequiredFromJSONSchemaTags: true,
AllowAdditionalProperties: true,
DoNotReference: true,
Namer: func(t reflect.Type) string {
return t.Name()
},
}

schema := r.Reflect(&digger_config.DiggerConfigYaml{})
schema.ID = jsonschema.ID("https://digger.dev/schemas/digger.yml.json")

return schema
}

func init() {
rootCmd.AddCommand(schemaCmd)
schemaCmd.Flags().StringVarP(&outputFile, "output", "o", "", "Output file path (default: stdout)")
}
1 change: 1 addition & 0 deletions dgctl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ replace github.com/diggerhq/digger/libs => ../libs
require (
github.com/diggerhq/digger/libs v0.0.0-00010101000000-000000000000
github.com/google/go-github/v61 v61.0.0
github.com/invopop/jsonschema v0.12.0
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.6
github.com/spf13/viper v1.20.1
Expand Down
4 changes: 0 additions & 4 deletions docs/ce/reference/digger.yml.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ workflows:
Disable the status check that verifies apply was executed.
</ParamField>

<ParamField path="trusted_appIDs" type="array" default="[]">
Allow bot comments from these GitHub user IDs. Example: `trusted_appIDs: [41898282]` for GitHub Actions.
</ParamField>

<ParamField path="comment_render_mode" type="string" default="basic">
How to render plan output in comments. Options: `basic`, `detailed`.
</ParamField>
Expand Down
6 changes: 6 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,8 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
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/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
github.com/bazelbuild/rules_go v0.49.0 h1:5vCbuvy8Q11g41lseGJDc5vxhDjJtfxr6nM/IC4VmqM=
github.com/bazelbuild/rules_go v0.49.0/go.mod h1:Dhcz716Kqg1RHNWos+N6MlXNkjNP2EwZQ0LukRKJfMs=
Expand Down Expand Up @@ -1743,6 +1745,8 @@ github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3 h1:fO9A67/izFYFY
github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3/go.mod h1:Ey4uAp+LvIl+s5jRbOHLcZpUDnkjLBROl15fZLwPlTM=
github.com/intel/goresctrl v0.3.0 h1:K2D3GOzihV7xSBedGxONSlaw/un1LZgWsc9IfqipN4c=
github.com/intel/goresctrl v0.3.0/go.mod h1:fdz3mD85cmP9sHD8JUlrNWAxvwM86CrbmVXltEKd7zk=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/iris-contrib/go.uuid v2.0.0+incompatible h1:XZubAYg61/JwnJNbZilGjf3b3pB80+OQg2qf6c8BfWE=
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
github.com/iris-contrib/httpexpect/v2 v2.12.1 h1:3cTZSyBBen/kfjCtgNFoUKi1u0FVXNaAjyRJOo6AVS4=
Expand Down Expand Up @@ -2313,6 +2317,8 @@ github.com/vmware/govmomi v0.20.3 h1:gpw/0Ku+6RgF3jsi7fnCLmlcikBHfKBCUcu1qgc16OU
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.11 h1:N7Z7E9UvjW+sGsEl7k/SJrvY2reP1A07MrGuCjIOjRE=
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
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/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
Expand Down
Loading