Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Add --nomanifest flag to the generate command #403

Merged
merged 1 commit into from
Sep 13, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ jobs:
- name: Generate code
run: |
cd codegen-tests
grafana-app-sdk generate --kindgrouping=kind --gogenpath=pkg/gen1 --tsgenpath=ts/gen1 --crdencoding=json
grafana-app-sdk generate --kindgrouping=group --gogenpath=pkg/gen2 --tsgenpath=ts/gen2 --crdencoding=yaml
grafana-app-sdk generate --kindgrouping=kind --gogenpath=pkg/gen1 --tsgenpath=ts/gen1 --crdencoding=json --nomanifest
grafana-app-sdk generate --kindgrouping=group --gogenpath=pkg/gen2 --tsgenpath=ts/gen2 --crdencoding=yaml --nomanifest
diff pkg/gen1/resource/customkind cmp/go/groupbykind/customkind > diff.txt
sed -i '/^Common subdirectories/d' diff.txt
difflines=$(wc -l diff.txt | awk '{ print $1 }')
Expand Down
75 changes: 43 additions & 32 deletions cmd/grafana-app-sdk/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Definitions will be created. Only applicable if type=kubernetes`)
Allowed values are 'group' and 'kind'. Dictates the packaging of go kinds, where 'group' places all kinds with the same group in the same package, and 'kind' creates separate packages per kind (packaging will always end with the version)`)
generateCmd.Flags().Bool("postprocess", false, "Whether to run post-processing on the generated files after they are written to disk. Post-processing includes code generation based on +k8s comments on types. Post-processing will fail if the dependencies required by the generated code are absent from go.mod.")
generateCmd.Flags().Lookup("postprocess").NoOptDefVal = "true"
generateCmd.Flags().Bool("nomanifest", false, "Whether to disable generating the app manifest")
generateCmd.Flags().Lookup("nomanifest").NoOptDefVal = "true"

// Don't show "usage" information when an error is returned form the command,
// because our errors are not command-usage-based
Expand Down Expand Up @@ -105,6 +107,10 @@ func generateCmdFunc(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
noManifest, err := cmd.Flags().GetBool("nomanifest")
if err != nil {
return err
}

var files codejen.Files
switch format {
Expand All @@ -121,12 +127,13 @@ func generateCmdFunc(cmd *cobra.Command, _ []string) error {
}
case FormatCUE:
files, err = generateKindsCue(os.DirFS(cuePath), kindGenConfig{
GoGenBasePath: goGenPath,
TSGenBasePath: tsGenPath,
StorageType: storageType,
CRDEncoding: encType,
CRDPath: crdPath,
GroupKinds: grouping == kindGroupingGroup,
GoGenBasePath: goGenPath,
TSGenBasePath: tsGenPath,
StorageType: storageType,
CRDEncoding: encType,
CRDPath: crdPath,
GroupKinds: grouping == kindGroupingGroup,
GenerateManifest: !noManifest,
}, selectors...)
if err != nil {
return err
Expand Down Expand Up @@ -169,12 +176,13 @@ func generateCmdFunc(cmd *cobra.Command, _ []string) error {
}

type kindGenConfig struct {
GoGenBasePath string
TSGenBasePath string
StorageType string
CRDEncoding string
CRDPath string
GroupKinds bool
GoGenBasePath string
TSGenBasePath string
StorageType string
CRDEncoding string
CRDPath string
GroupKinds bool
GenerateManifest bool
}

//nolint:goconst
Expand Down Expand Up @@ -364,34 +372,37 @@ func generateKindsCue(modFS fs.FS, cfg kindGenConfig, selectors ...string) (code

// Manifest
var manifestFiles codejen.Files
if cfg.CRDEncoding != "none" {
encFunc := func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}
if cfg.CRDEncoding == "yaml" {
encFunc = yaml.Marshal
var goManifestFiles codejen.Files
if cfg.GenerateManifest {
if cfg.CRDEncoding != "none" {
encFunc := func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}
if cfg.CRDEncoding == "yaml" {
encFunc = yaml.Marshal
}
manifestFiles, err = generator.FilteredGenerate(cuekind.ManifestGenerator(encFunc, cfg.CRDEncoding, ""), func(kind codegen.Kind) bool {
return kind.Properties().APIResource != nil
}, selectors...)
if err != nil {
return nil, err
}
for i, f := range manifestFiles {
manifestFiles[i].RelativePath = filepath.Join(cfg.CRDPath, f.RelativePath)
}
}
manifestFiles, err = generator.FilteredGenerate(cuekind.ManifestGenerator(encFunc, cfg.CRDEncoding, ""), func(kind codegen.Kind) bool {

goManifestFiles, err = generator.FilteredGenerate(cuekind.ManifestGoGenerator(filepath.Base(cfg.GoGenBasePath), ""), func(kind codegen.Kind) bool {
return kind.Properties().APIResource != nil
}, selectors...)
})
if err != nil {
return nil, err
}
for i, f := range manifestFiles {
manifestFiles[i].RelativePath = filepath.Join(cfg.CRDPath, f.RelativePath)
for i, f := range goManifestFiles {
goManifestFiles[i].RelativePath = filepath.Join(cfg.GoGenBasePath, f.RelativePath)
}
}

goManifestFiles, err := generator.FilteredGenerate(cuekind.ManifestGoGenerator(filepath.Base(cfg.GoGenBasePath), ""), func(kind codegen.Kind) bool {
return kind.Properties().APIResource != nil
})
if err != nil {
return nil, err
}
for i, f := range goManifestFiles {
goManifestFiles[i].RelativePath = filepath.Join(cfg.GoGenBasePath, f.RelativePath)
}

allFiles := append(make(codejen.Files, 0), resourceFiles...)
allFiles = append(allFiles, modelFiles...)
allFiles = append(allFiles, tsModelFiles...)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/grafana/grafana-app-sdk
go 1.23.0

retract (
v0.20.0 // Errors in release pipeline didn't allow the binaries to be built for this release, which can break automated workflows that depend on them
v0.18.4 // Errors in release pipeline didn't allow the binaries to be built for this release, which can break automated workflows that depend on them
v0.18.3 // Tag was deleted and re-created with a new commit, causing GOPROXY conflicts
)
Expand Down
Loading
Loading