-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add JSON Schema * chore: fix golangci-lint * chore: fix description * feat(init): add a link to json schema to generated config
- Loading branch information
1 parent
a8309d7
commit 5c64f66
Showing
9 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ linters: | |
- nonamedreturns | ||
- musttag | ||
- depguard | ||
- tagalign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/invopop/jsonschema" | ||
"github.com/suzuki-shunsuke/pinact/pkg/controller/run" | ||
) | ||
|
||
func main() { | ||
if err := core(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func core() error { | ||
if err := gen(&run.Config{}, "json-schema/pinact.json"); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func gen(input interface{}, p string) error { | ||
f, err := os.Create(p) | ||
if err != nil { | ||
return fmt.Errorf("create a file %s: %w", p, err) | ||
} | ||
defer f.Close() | ||
encoder := json.NewEncoder(f) | ||
encoder.SetIndent("", " ") | ||
s := jsonschema.Reflect(input) | ||
b, err := json.MarshalIndent(s, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("mashal schema as JSON: %w", err) | ||
} | ||
if err := os.WriteFile(p, []byte(strings.ReplaceAll(string(b), "http://json-schema.org", "https://json-schema.org")+"\n"), 0o644); err != nil { //nolint:gosec,mnd | ||
return fmt.Errorf("write JSON Schema to %s: %w", p, err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://github.com/suzuki-shunsuke/pinact/pkg/controller/run/config", | ||
"$ref": "#/$defs/Config", | ||
"$defs": { | ||
"Config": { | ||
"properties": { | ||
"files": { | ||
"items": { | ||
"$ref": "#/$defs/File" | ||
}, | ||
"type": "array", | ||
"description": "Target files. If files are passed via positional command line arguments" | ||
}, | ||
"ignore_actions": { | ||
"items": { | ||
"$ref": "#/$defs/IgnoreAction" | ||
}, | ||
"type": "array", | ||
"description": "Actions and reusable workflows that pinact ignores" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"type": "object" | ||
}, | ||
"File": { | ||
"properties": { | ||
"pattern": { | ||
"type": "string", | ||
"description": "A regular expression of target files. If files are passed via positional command line arguments" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"type": "object", | ||
"required": [ | ||
"pattern" | ||
] | ||
}, | ||
"IgnoreAction": { | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Action and reusable workflow names that pinact ignores" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"type": "object", | ||
"required": [ | ||
"name" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters