From 15d7f36819b510ea79b43cd8d8509efb8ebc4664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Wed, 23 Aug 2023 16:02:44 +0200 Subject: [PATCH] Kinds: Reconcile verify-kinds.go with kind-registry changes --- .../workflows/scripts/kinds/verify-kinds.go | 21 ++++++++++++------- pkg/plugins/plugindef/plugindef.cue | 2 +- .../plugindef/plugindef_bindings_gen.go | 2 ++ pkg/plugins/plugindef/plugindef_types_gen.go | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/scripts/kinds/verify-kinds.go b/.github/workflows/scripts/kinds/verify-kinds.go index 0d92fff28ae..cced805ce51 100644 --- a/.github/workflows/scripts/kinds/verify-kinds.go +++ b/.github/workflows/scripts/kinds/verify-kinds.go @@ -206,7 +206,7 @@ func loadComposableKind(name string, kind string) (kindsys.Kind, error) { fs := fstest.MapFS{ fmt.Sprintf("%s.cue", name): &fstest.MapFile{ - Data: []byte("package grafanaplugin\n" + kind), + Data: []byte(kind), }, } @@ -290,7 +290,7 @@ func (j *ckrJenny) Generate(k kindsys.Composable) (*codejen.File, error) { return nil, err } - newKindBytes = []byte(fmt.Sprintf("package kind\n\n%s", newKindBytes)) + newKindBytes = []byte(fmt.Sprintf("package grafanaplugin\n\n%s", newKindBytes)) return codejen.NewFile(filepath.Join(j.path, "next", "composable", name+".cue"), newKindBytes, j), nil } @@ -314,7 +314,7 @@ func NewKindRegistry() (*kindRegistry, error) { defer file.Close() // Get the repository archive URL - archiveURL, _, err := client.Repositories.GetArchiveLink(ctx, GITHUB_OWNER, GITHUB_REPO, github.Zipball, &github.RepositoryContentGetOptions{}) + archiveURL, _, err := client.Repositories.GetArchiveLink(ctx, GITHUB_OWNER, GITHUB_REPO, github.Zipball, &github.RepositoryContentGetOptions{Ref: "fix-composable-package-name"}) if err != nil { return nil, fmt.Errorf("failed to get archive URL: %w", err) } @@ -399,10 +399,17 @@ func (registry *kindRegistry) getPublishedKind(name string, category string, lat return "", nil } - kindPath := filepath.Join( - registry.zipDir, - fmt.Sprintf("grafana/%s/%s/%s.cue", latestRegistryDir, category, name), - ) + var cueFilePath string + switch category { + case "core": + cueFilePath = fmt.Sprintf("%s/%s.cue", name, name) + case "composable": + cueFilePath = fmt.Sprintf("%s.cue", name) + default: + return "", fmt.Errorf("kind can only be core or composable") + } + + kindPath := filepath.Join(latestRegistryDir, category, cueFilePath) file, err := registry.zipFile.Open(kindPath) if err != nil { return "", fmt.Errorf("failed to open file: %w", err) diff --git a/pkg/plugins/plugindef/plugindef.cue b/pkg/plugins/plugindef/plugindef.cue index b2ec0f409a1..aa0514fc914 100644 --- a/pkg/plugins/plugindef/plugindef.cue +++ b/pkg/plugins/plugindef/plugindef.cue @@ -125,7 +125,7 @@ schemas: [{ // Required Grafana version for this plugin. Validated using // https://github.com/npm/node-semver. - grafanaDependency: =~"^(<=|>=|<|>|=|~|\\^)?([0-9]+)(\\.[0-9x\\*]+)(\\.[0-9x\\*]+)?(\\s(<=|>=|<|=>)?([0-9]+)(\\.[0-9x]+)(\\.[0-9x]+))?$" + grafanaDependency?: =~"^(<=|>=|<|>|=|~|\\^)?([0-9]+)(\\.[0-9x\\*]+)(\\.[0-9x\\*]+)?(\\s(<=|>=|<|=>)?([0-9]+)(\\.[0-9x]+)(\\.[0-9x]+))?$" // An array of required plugins on which this plugin depends plugins?: [...#Dependency] diff --git a/pkg/plugins/plugindef/plugindef_bindings_gen.go b/pkg/plugins/plugindef/plugindef_bindings_gen.go index 3438f6896a3..06f77733062 100644 --- a/pkg/plugins/plugindef/plugindef_bindings_gen.go +++ b/pkg/plugins/plugindef/plugindef_bindings_gen.go @@ -10,6 +10,7 @@ package plugindef import ( + "cuelang.org/go/cue" "cuelang.org/go/cue/build" "github.com/grafana/thema" ) @@ -67,6 +68,7 @@ func baseLineage(rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, er } raw := rt.Context().BuildInstance(inst) + raw = raw.LookupPath(cue.ParsePath("")) // An error returned from thema.BindLineage indicates one of the following: // - The parsed path does not exist in the loaded CUE file (["github.com/grafana/thema/errors".ErrValueNotExist]) diff --git a/pkg/plugins/plugindef/plugindef_types_gen.go b/pkg/plugins/plugindef/plugindef_types_gen.go index c9ad1b92786..1f419341259 100644 --- a/pkg/plugins/plugindef/plugindef_types_gen.go +++ b/pkg/plugins/plugindef/plugindef_types_gen.go @@ -98,7 +98,7 @@ type BuildInfo struct { type Dependencies struct { // Required Grafana version for this plugin. Validated using // https://github.com/npm/node-semver. - GrafanaDependency string `json:"grafanaDependency"` + GrafanaDependency *string `json:"grafanaDependency,omitempty"` // (Deprecated) Required Grafana version for this plugin, e.g. // `6.x.x 7.x.x` to denote plugin requires Grafana v6.x.x or