Codegen: Remove registry flow to push schemas to kind-registry (legacy schemas) (#117874)
Some checks are pending
Actionlint / Lint GitHub Actions files (push) Waiting to run
Backend Code Checks / Detect whether code changed (push) Waiting to run
Backend Code Checks / Validate Backend Configs (push) Blocked by required conditions
Backend Unit Tests / Detect whether code changed (push) Waiting to run
Backend Unit Tests / Grafana (1/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (2/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (3/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (4/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (5/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (6/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (7/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (8/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (1/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (2/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (3/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (4/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (5/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (6/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (7/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (8/8) (push) Blocked by required conditions
Backend Unit Tests / All backend unit tests complete (push) Blocked by required conditions
CodeQL checks / Detect whether code changed (push) Waiting to run
CodeQL checks / Analyze (push) Blocked by required conditions
Deploy Storybook / Detect whether code changed (push) Waiting to run
Deploy Storybook / Deploy Storybook (push) Blocked by required conditions
Lint Frontend / Detect whether code changed (push) Waiting to run
Lint Frontend / Lint (push) Blocked by required conditions
Lint Frontend / Typecheck (push) Blocked by required conditions
Lint Frontend / Verify API clients (push) Waiting to run
Lint Frontend / Verify API clients (enterprise) (push) Waiting to run
Lint Frontend / Verify packed frontend packages (push) Blocked by required conditions
Lint Frontend / Check circular dependencies (push) Blocked by required conditions
golangci-lint / Detect whether code changed (push) Waiting to run
golangci-lint / go-fmt (push) Blocked by required conditions
golangci-lint / lint-go (push) Blocked by required conditions
Crowdin Upload Action / upload-sources-to-crowdin (push) Waiting to run
Verify i18n / verify-i18n (push) Waiting to run
End-to-end tests / Detect whether code changed (push) Waiting to run
End-to-end tests / Build & Package Grafana (push) Blocked by required conditions
End-to-end tests / Build E2E test runner (push) Blocked by required conditions
End-to-end tests / push-docker-image (push) Blocked by required conditions
End-to-end tests / dashboards-suite (old arch) (push) Blocked by required conditions
End-to-end tests / panels-suite (old arch) (push) Blocked by required conditions
End-to-end tests / smoke-tests-suite (old arch) (push) Blocked by required conditions
End-to-end tests / various-suite (old arch) (push) Blocked by required conditions
End-to-end tests / Verify Storybook (Playwright) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (1/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (2/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (3/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (4/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (5/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (6/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (7/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (8/8) (push) Blocked by required conditions
End-to-end tests / run-azure-monitor-e2e (push) Blocked by required conditions
End-to-end tests / All Playwright tests complete (push) Blocked by required conditions
End-to-end tests / A11y test (push) Blocked by required conditions
End-to-end tests / Publish metrics (push) Blocked by required conditions
End-to-end tests / All E2E tests complete (push) Blocked by required conditions
Frontend tests / Detect whether code changed (push) Waiting to run
Frontend tests / Unit tests (1 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (10 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (11 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (12 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (13 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (14 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (15 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (16 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (2 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (3 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (4 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (5 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (6 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (7 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (8 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (9 / 16) (push) Blocked by required conditions
Frontend tests / Decoupled plugin tests (push) Blocked by required conditions
Frontend tests / Packages unit tests (push) Blocked by required conditions
Frontend tests / All frontend unit tests complete (push) Blocked by required conditions
Frontend tests / Devenv frontend-service build (push) Blocked by required conditions
Integration Tests / Detect whether code changed (push) Waiting to run
Integration Tests / Sqlite (1/4) (push) Blocked by required conditions
Integration Tests / Sqlite (2/4) (push) Blocked by required conditions
Integration Tests / Sqlite (3/4) (push) Blocked by required conditions
Integration Tests / Sqlite (4/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (1/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (2/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (3/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (4/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (profiled) (push) Blocked by required conditions
Integration Tests / MySQL (1/16) (push) Blocked by required conditions
Integration Tests / MySQL (10/16) (push) Blocked by required conditions
Integration Tests / MySQL (11/16) (push) Blocked by required conditions
Integration Tests / MySQL (12/16) (push) Blocked by required conditions
Integration Tests / MySQL (13/16) (push) Blocked by required conditions
Integration Tests / MySQL (14/16) (push) Blocked by required conditions
Integration Tests / MySQL (15/16) (push) Blocked by required conditions
Integration Tests / MySQL (16/16) (push) Blocked by required conditions
Integration Tests / MySQL (2/16) (push) Blocked by required conditions
Integration Tests / MySQL (3/16) (push) Blocked by required conditions
Integration Tests / MySQL (4/16) (push) Blocked by required conditions
Integration Tests / MySQL (5/16) (push) Blocked by required conditions
Integration Tests / MySQL (6/16) (push) Blocked by required conditions
Integration Tests / MySQL (7/16) (push) Blocked by required conditions
Integration Tests / MySQL (8/16) (push) Blocked by required conditions
Integration Tests / MySQL (9/16) (push) Blocked by required conditions
Integration Tests / Postgres (1/16) (push) Blocked by required conditions
Integration Tests / Postgres (10/16) (push) Blocked by required conditions
Integration Tests / Postgres (11/16) (push) Blocked by required conditions
Integration Tests / Postgres (12/16) (push) Blocked by required conditions
Integration Tests / Postgres (13/16) (push) Blocked by required conditions
Integration Tests / Postgres (14/16) (push) Blocked by required conditions
Integration Tests / Postgres (15/16) (push) Blocked by required conditions
Integration Tests / Postgres (16/16) (push) Blocked by required conditions
Integration Tests / Postgres (2/16) (push) Blocked by required conditions
Integration Tests / Postgres (3/16) (push) Blocked by required conditions
Integration Tests / Postgres (4/16) (push) Blocked by required conditions
Integration Tests / Postgres (5/16) (push) Blocked by required conditions
Integration Tests / Postgres (6/16) (push) Blocked by required conditions
Integration Tests / Postgres (7/16) (push) Blocked by required conditions
Integration Tests / Postgres (8/16) (push) Blocked by required conditions
Integration Tests / Postgres (9/16) (push) Blocked by required conditions
Integration Tests / Sqlite Enterprise (1/4) (push) Blocked by required conditions
Integration Tests / Sqlite Enterprise (2/4) (push) Blocked by required conditions
Integration Tests / Sqlite Enterprise (3/4) (push) Blocked by required conditions
Integration Tests / Sqlite Enterprise (4/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo Enterprise (1/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo Enterprise (2/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo Enterprise (3/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo Enterprise (4/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo Enterprise (profiled) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (1/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (10/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (11/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (12/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (13/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (14/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (15/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (16/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (2/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (3/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (4/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (5/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (6/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (7/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (8/16) (push) Blocked by required conditions
Integration Tests / MySQL Enterprise (9/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (1/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (10/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (11/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (12/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (13/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (14/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (15/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (16/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (2/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (3/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (4/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (5/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (6/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (7/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (8/16) (push) Blocked by required conditions
Integration Tests / Postgres Enterprise (9/16) (push) Blocked by required conditions
Integration Tests / All backend integration tests complete (push) Blocked by required conditions
Reject GitHub secrets / reject-gh-secrets (push) Waiting to run
Build Release Packages / setup (push) Waiting to run
Build Release Packages / Dispatch grafana-enterprise build (push) Blocked by required conditions
Build Release Packages / / darwin-amd64 (push) Blocked by required conditions
Build Release Packages / / darwin-arm64 (push) Blocked by required conditions
Build Release Packages / / linux-amd64 (push) Blocked by required conditions
Build Release Packages / / linux-armv6 (push) Blocked by required conditions
Build Release Packages / / linux-armv7 (push) Blocked by required conditions
Build Release Packages / / linux-arm64 (push) Blocked by required conditions
Build Release Packages / / linux-s390x (push) Blocked by required conditions
Build Release Packages / / windows-amd64 (push) Blocked by required conditions
Build Release Packages / / windows-arm64 (push) Blocked by required conditions
Build Release Packages / Upload artifacts (push) Blocked by required conditions
Build Release Packages / publish-dockerhub (push) Blocked by required conditions
Build Release Packages / Dispatch publish NPM canaries (push) Blocked by required conditions
Build Release Packages / notify-pr (push) Blocked by required conditions
Run dashboard schema v2 e2e / dashboard-schema-v2-e2e (push) Waiting to run
Shellcheck / Shellcheck scripts (push) Waiting to run
Run Storybook a11y tests / Detect whether code changed (push) Waiting to run
Run Storybook a11y tests / Run Storybook a11y tests (light theme) (push) Blocked by required conditions
Run Storybook a11y tests / Run Storybook a11y tests (dark theme) (push) Blocked by required conditions
Swagger generated code / Detect whether code changed (push) Waiting to run
Swagger generated code / Verify committed API specs match (push) Blocked by required conditions
Dispatch sync to mirror / dispatch-job (push) Waiting to run
trigger-dashboard-search-e2e / trigger-search-e2e (push) Waiting to run
Trivy Scan / trivy-scan (push) Waiting to run

* Remove registry flow to push schemas to kind-registry

* Fix codeowners

* Update workspaces
This commit is contained in:
Selene 2026-02-11 12:28:13 +01:00 committed by GitHub
parent c03d2bd0c3
commit b26eb58447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1 additions and 1189 deletions

4
.github/CODEOWNERS vendored
View file

@ -1210,7 +1210,6 @@ embed.go @grafana/grafana-as-code
/pkg/codegen/ @grafana/grafana-as-code
/pkg/codegen/generators @grafana/grafana-as-code
/pkg/kinds/*/*_gen.go @grafana/grafana-as-code
/pkg/registry/schemas/ @grafana/grafana-as-code
/public/app/plugins/*gen.go @grafana/grafana-as-code
/cue.mod/ @grafana/grafana-as-code
@ -1276,10 +1275,7 @@ embed.go @grafana/grafana-as-code
/.github/workflows/scripts/json-file-to-job-output.js @grafana/grafana-frontend-platform
/.github/workflows/stale.yml @grafana/grafana-developer-enablement-squad
/.github/workflows/storybook-a11y.yml @grafana/grafana-frontend-platform
/.github/workflows/scripts/kinds/verify-kinds.go @grafana/grafana-app-platform-squad
/.github/workflows/scripts/create-security-branch/create-security-branch.sh @grafana/grafana-developer-enablement-squad
/.github/workflows/publish-kinds-next.yml @grafana/grafana-app-platform-squad
/.github/workflows/publish-kinds-release.yml @grafana/grafana-app-platform-squad
/.github/workflows/verify-kinds.yml @grafana/grafana-app-platform-squad
/.github/workflows/dashboards-issue-add-label.yml @grafana/dashboards-squad
/.github/workflows/run-schema-v2-e2e.yml @grafana/dashboards-squad

View file

@ -1,64 +0,0 @@
name: "publish-kinds-next"
on:
push:
branches:
- "main"
paths:
- '**/*.cue'
workflow_dispatch:
permissions: {}
jobs:
main:
if: github.repository == 'grafana/grafana'
runs-on: "ubuntu-latest"
permissions:
contents: read # cloning repo
actions: read # reading .github/workflows/ dir
id-token: write # reading vault secrets
steps:
- name: "Checkout Grafana repo"
uses: "actions/checkout@v5"
with:
fetch-depth: 0
persist-credentials: false
- name: "Setup Go"
uses: "actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00"
with:
go-version-file: go.mod
- name: "Verify kinds"
run: go run .github/workflows/scripts/kinds/verify-kinds.go
- name: "Get vault secrets"
id: vault-secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@main
with:
# Secrets placed in the ci/data/repo/grafana/grafana/delivery-bot-app path in Vault
repo_secrets: |
GRAFANA_DELIVERY_BOT_APP_PEM=delivery-bot-app:PRIVATE_KEY
- name: "Generate token"
id: generate_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
with:
# App needs Actions: Read/Write for the grafana/security-patch-actions repo
app_id: ${{ vars.DELIVERY_BOT_APP_ID }}
private_key: ${{ env.GRAFANA_DELIVERY_BOT_APP_PEM }}
- name: "Clone website-sync Action"
run: "git clone --single-branch --no-tags --depth 1 -b master https://grafana-delivery-bot:${{ steps.generate_token.outputs.token }}@github.com/grafana/website-sync ./.github/actions/website-sync"
- name: "Publish to kind registry (next)"
uses: "./.github/actions/website-sync"
id: "publish-next"
with:
repository: "grafana/kind-registry"
branch: "main"
host: "github.com"
github_pat: "grafana-delivery-bot:${{ steps.generate_token.outputs.token }}"
source_folder: ".github/workflows/scripts/kinds/next"
target_folder: "grafana/next"

View file

@ -1,87 +0,0 @@
name: "publish-kinds-release"
on:
push:
branches:
- v[0-9]+.[0-9]+.x
tags:
- v[0-9]+.[0-9]+.[0-9]+
paths:
- '**/*.cue'
workflow_dispatch:
permissions: {}
jobs:
main:
if: github.repository == 'grafana/grafana'
runs-on: "ubuntu-latest"
permissions:
contents: read # cloning repo
actions: read # reading .github/workflows/ dir
id-token: write # reading vault secrets
steps:
- name: "Checkout Grafana repo"
uses: "actions/checkout@v5"
with:
# required for the `grafana/grafana-github-actions/has-matching-release-tag` action to work
fetch-depth: 0
persist-credentials: false
- name: "Setup Go"
uses: "actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00"
with:
go-version-file: go.mod
- name: "Verify kinds"
run: go run .github/workflows/scripts/kinds/verify-kinds.go
- name: "Checkout Actions library"
uses: "actions/checkout@v5"
with:
repository: "grafana/grafana-github-actions"
path: "./actions"
persist-credentials: false
- name: "Install Actions from library"
run: "npm install --production --prefix ./actions"
- name: "Determine if there is a matching release tag"
id: "has-matching-release-tag"
uses: "./actions/has-matching-release-tag"
with:
ref_name: "${{ github.ref_name }}"
release_tag_regexp: "^v(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$"
release_branch_regexp: "^v(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.x$"
- name: "Get vault secrets"
id: vault-secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@main
with:
# Secrets placed in the ci/data/repo/grafana/grafana/delivery-bot-app path in Vault
repo_secrets: |
GRAFANA_DELIVERY_BOT_APP_PEM=delivery-bot-app:PRIVATE_KEY
- name: "Generate token"
id: generate_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
with:
# App needs Actions: Read/Write for the grafana/security-patch-actions repo
app_id: ${{ vars.DELIVERY_BOT_APP_ID }}
private_key: ${{ env.GRAFANA_DELIVERY_BOT_APP_PEM }}
- name: "Clone website-sync Action"
if: "steps.has-matching-release-tag.outputs.bool == 'true'"
run: "git clone --single-branch --no-tags --depth 1 -b master https://grafana-delivery-bot:${{ steps.generate_token.outputs.token }}@github.com/grafana/website-sync ./.github/actions/website-sync"
- name: "Publish to kind registry (release)"
if: "steps.has-matching-release-tag.outputs.bool == 'true'"
uses: "./.github/actions/website-sync"
id: "publish-release"
with:
repository: "grafana/kind-registry"
branch: "main"
host: "github.com"
github_pat: "grafana-delivery-bot:${{ steps.generate_token.outputs.token }}"
source_folder: ".github/workflows/scripts/kinds/next"
target_folder: "grafana/${{ github.ref_name }}"

View file

@ -1,229 +0,0 @@
package main
import (
"context"
"errors"
"fmt"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"os"
"path/filepath"
"regexp"
"strings"
"cuelang.org/go/cue"
cueformat "cuelang.org/go/cue/format"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/registry/schemas"
)
var nonAlphaNumRegex = regexp.MustCompile("[^a-zA-Z0-9 ]+")
// main This script verifies that stable kinds are not updated once published (new schemas
// can be added but existing ones cannot be updated).
// It generates kind files into a local "next" folder, ready to be published in the kind-registry repo.
// If kind names are given as parameters, the script will make the above actions only for the
// given kinds.
func main() {
// File generation
jfs := codejen.NewFS()
outputPath := filepath.Join(".github", "workflows", "scripts", "kinds")
corekinds, err := schemas.GetCoreKinds()
die(err)
composableKinds, err := schemas.GetComposableKinds()
die(err)
coreJennies := codejen.JennyList[schemas.CoreKind]{}
coreJennies.Append(
CoreKindRegistryJenny(outputPath),
)
corefs, err := coreJennies.GenerateFS(corekinds...)
die(err)
die(jfs.Merge(corefs))
composableJennies := codejen.JennyList[schemas.ComposableKind]{}
composableJennies.Append(
ComposableKindRegistryJenny(outputPath),
)
composablefs, err := composableJennies.GenerateFS(composableKinds...)
die(err)
die(jfs.Merge(composablefs))
if err = jfs.Write(context.Background(), ""); err != nil {
die(fmt.Errorf("error while writing generated code to disk:\n%s", err))
}
if err := copyCueSchemas("packages/grafana-schema/src/common", filepath.Join(outputPath, "next")); err != nil {
die(fmt.Errorf("error while copying the grafana-schema/common package:\n%s", err))
}
}
func copyCueSchemas(fromDir string, toDir string) error {
baseTargetDir := filepath.Base(fromDir)
return filepath.Walk(fromDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
targetPath := filepath.Join(
toDir,
baseTargetDir,
strings.TrimPrefix(path, fromDir),
)
if info.IsDir() {
return ensureDirectoryExists(targetPath, info.Mode())
}
if !strings.HasSuffix(path, ".cue") {
return nil
}
return copyFile(path, targetPath, info.Mode())
})
}
func copyFile(from string, to string, mode os.FileMode) error {
input, err := os.ReadFile(from)
if err != nil {
return err
}
return os.WriteFile(to, input, mode)
}
func ensureDirectoryExists(directory string, mode os.FileMode) error {
_, err := os.Stat(directory)
if errors.Is(err, os.ErrNotExist) {
if err = os.Mkdir(directory, mode); err != nil {
return err
}
} else if err != nil {
return err
}
return os.Chmod(directory, mode)
}
func die(errs ...error) {
if len(errs) > 0 && errs[0] != nil {
for _, err := range errs {
fmt.Fprint(os.Stderr, err, "\n")
}
os.Exit(1)
}
}
// CoreKindRegistryJenny generates kind files into the "next" folder of the local kind registry.
func CoreKindRegistryJenny(path string) codejen.OneToOne[schemas.CoreKind] {
return &kindregjenny{
path: path,
}
}
type kindregjenny struct {
path string
}
func (j *kindregjenny) JennyName() string {
return "KindRegistryJenny"
}
func (j *kindregjenny) Generate(kind schemas.CoreKind) (*codejen.File, error) {
newKindBytes, err := kindToBytes(kind.CueFile)
if err != nil {
return nil, err
}
path := filepath.Join(j.path, "next", "core", kind.Name, kind.Name+".cue")
return codejen.NewFile(path, newKindBytes, j), nil
}
// ComposableKindRegistryJenny generates kind files into the "next" folder of the local kind registry.
func ComposableKindRegistryJenny(path string) codejen.OneToOne[schemas.ComposableKind] {
return &ckrJenny{
path: path,
}
}
type ckrJenny struct {
path string
}
func (j *ckrJenny) JennyName() string {
return "ComposableKindRegistryJenny"
}
func (j *ckrJenny) Generate(k schemas.ComposableKind) (*codejen.File, error) {
name := strings.ToLower(fmt.Sprintf("%s/%s", k.Name, k.Filename))
v := fixComposableKindFormat(k)
newKindBytes, err := kindToBytes(v)
if err != nil {
return nil, err
}
newKindBytes = []byte(fmt.Sprintf("package grafanaplugin\n\n%s", newKindBytes))
return codejen.NewFile(filepath.Join(j.path, "next", "composable", name), newKindBytes, j), nil
}
// kindToBytes converts a kind cue value to a .cue file content
func kindToBytes(kind cue.Value) ([]byte, error) {
node := kind.Syntax(
cue.All(),
cue.Schema(),
cue.Docs(true),
)
return cueformat.Node(node)
}
func fixComposableKindFormat(schema schemas.ComposableKind) cue.Value {
variant := "PanelCfg"
if schema.CueFile.LookupPath(cue.ParsePath("composableKinds.DataQuery")).Exists() {
variant = "DataQuery"
}
newCue := schema.CueFile.Context().CompileString(
fmt.Sprintf("schemaInterface: %q\n", variant) +
fmt.Sprintf("name: %q + %q\n\n", UpperCamelCase(schema.Name), variant) +
"lineage: _",
)
lineagePath := cue.MakePath(cue.Str("composableKinds"), cue.Str(variant), cue.Str("lineage"))
return newCue.FillPath(cue.MakePath(cue.Str("lineage")), schema.CueFile.LookupPath(lineagePath))
}
func UpperCamelCase(s string) string {
s = LowerCamelCase(s)
// Uppercase the first letter
if len(s) > 0 {
s = strings.ToUpper(s[:1]) + s[1:]
}
return s
}
func LowerCamelCase(s string) string {
// Replace all non-alphanumeric characters by spaces
s = nonAlphaNumRegex.ReplaceAllString(s, " ")
// Title case s
s = cases.Title(language.AmericanEnglish, cases.NoLower).String(s)
// Remove all spaces
s = strings.ReplaceAll(s, " ", "")
// Lowercase the first letter
if len(s) > 0 {
s = strings.ToLower(s[:1]) + s[1:]
}
return s
}

6
go.mod
View file

@ -9,7 +9,7 @@ require (
cloud.google.com/go/kms v1.22.0 // @grafana/grafana-backend-group
cloud.google.com/go/storage v1.55.0 // @grafana/grafana-backend-group
connectrpc.com/connect v1.19.1 // @grafana/observability-traces-and-profiling
cuelang.org/go v0.11.1 // @grafana/grafana-as-code
cuelang.org/go v0.11.1 // indirect; @grafana/grafana-as-code
dario.cat/mergo v1.0.2 // @grafana/grafana-app-platform-squad
filippo.io/age v1.2.1 // @grafana/identity-access-team
github.com/1NCE-GmbH/grpc-go-pool v0.0.0-20231117122434-2a5bb974daa2 // @grafana/grafana-search-and-storage
@ -301,7 +301,6 @@ require (
cloud.google.com/go/iam v1.5.2 // indirect
cloud.google.com/go/longrunning v0.6.7 // indirect
cloud.google.com/go/monitoring v1.24.2 // indirect
cuelabs.dev/go/oci/ociregistry v0.0.0-20251212221603-3adeb8663819 // indirect
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect
@ -411,7 +410,6 @@ require (
github.com/ebitengine/purego v0.8.2 // indirect
github.com/edsrzf/mmap-go v1.2.0 // indirect
github.com/elazarl/goproxy v1.8.0 // indirect
github.com/emicklei/proto v1.14.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.35.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
@ -581,13 +579,11 @@ require (
github.com/prometheus/exporter-toolkit v0.15.1 // indirect
github.com/prometheus/otlptranslator v1.0.0 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
github.com/protocolbuffers/txtpbfmt v0.0.0-20251124094003-fcb97cc64c7b // indirect
github.com/puzpuzpuz/xsync/v2 v2.5.1 // indirect
github.com/quagmt/udecimal v1.9.0 // indirect
github.com/redis/rueidis v1.0.68 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect

View file

@ -49,7 +49,6 @@ func main() {
coreKindsGen.Append(
&codegen.GoSpecJenny{},
&codegen.K8ResourcesJenny{},
&codegen.CoreRegistryJenny{},
codegen.LatestMajorsOrXJenny(TSCoreKindParentPath),
codegen.TSVeneerIndexJenny(filepath.Join("packages", "grafana-schema", "src")),
)

View file

@ -1,46 +0,0 @@
package schemas
import (
"os"
"path/filepath"
"runtime"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
)
type CoreKind struct {
Name string
CueFile cue.Value
}
func GetCoreKinds() ([]CoreKind, error) {
ctx := cuecontext.New()
kinds := make([]CoreKind, 0)
_, caller, _, _ := runtime.Caller(0)
root := filepath.Join(caller, "../../../..")
{{- range .Schemas }}
{{ .Name }}Cue, err := loadCueFile(ctx, filepath.Join(root, "{{ .FilePath }}"))
if err != nil {
return nil, err
}
kinds = append(kinds, CoreKind{
Name: "{{ .Name }}",
CueFile: {{ .Name }}Cue,
})
{{- end }}
return kinds, nil
}
func loadCueFile(ctx *cue.Context, path string) (cue.Value, error) {
cueFile, err := os.ReadFile(path)
if err != nil {
return cue.Value{}, err
}
return ctx.CompileBytes(cueFile), nil
}

View file

@ -1,76 +0,0 @@
package codegen
import (
"bytes"
"fmt"
"go/format"
"path/filepath"
"strings"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
)
var registryPath = filepath.Join("pkg", "registry", "schemas")
var renamedPlugins = map[string]string{
"cloud-monitoring": "googlecloudmonitoring",
"grafana-pyroscope-datasource": "grafanapyroscope",
"annolist": "annotationslist",
"grafanatestdatadatasource": "testdata",
"dashlist": "dashboardlist",
}
type PluginRegistryJenny struct {
}
func (jenny *PluginRegistryJenny) JennyName() string {
return "PluginRegistryJenny"
}
func (jenny *PluginRegistryJenny) Generate(decls ...*pfs.PluginDecl) (*codejen.File, error) {
if len(decls) == 0 {
return nil, nil
}
schemas := make([]Schema, len(decls))
for i, decl := range decls {
variant := fmt.Sprintf("%s.cue", strings.ToLower(decl.SchemaInterface.Name))
name, err := getSchemaName(decl.PluginPath)
if err != nil {
return nil, fmt.Errorf("unable to find schema name: %s", err)
}
schemas[i] = Schema{
Name: name,
Filename: variant,
FilePath: "./" + filepath.Join("public", "app", "plugins", decl.PluginPath, variant),
}
}
buf := new(bytes.Buffer)
if err := tmpls.Lookup("composable_registry.tmpl").Execute(buf, tmpl_vars_plugin_registry{
Schemas: schemas,
}); err != nil {
return nil, fmt.Errorf("failed executing kind registry template: %w", err)
}
b, err := format.Source(buf.Bytes())
if err != nil {
return nil, err
}
return codejen.NewFile(filepath.Join(registryPath, "composable_kind.go"), b, jenny), nil
}
func getSchemaName(path string) (string, error) {
parts := strings.Split(path, "/")
if len(parts) < 2 {
return "", fmt.Errorf("path should contain more than 2 elements")
}
folderName := parts[len(parts)-1]
if renamed, ok := renamedPlugins[folderName]; ok {
folderName = renamed
}
folderName = strings.ReplaceAll(folderName, "-", "")
return strings.ToLower(folderName), nil
}

View file

@ -1,34 +0,0 @@
package codegen
import (
"embed"
"text/template"
"time"
)
// All the parsed templates in the tmpl subdirectory
var tmpls *template.Template
func init() {
base := template.New("codegen").Funcs(template.FuncMap{
"now": time.Now,
})
tmpls = template.Must(base.ParseFS(tmplFS, "tmpl/*.tmpl"))
}
//go:embed tmpl/*.tmpl
var tmplFS embed.FS
// The following group of types, beginning with templateVars_*, all contain the set
// of variables expected by the corresponding named template file under tmpl/
type (
tmpl_vars_plugin_registry struct {
Schemas []Schema
}
Schema struct {
Name string
Filename string
FilePath string
}
)

View file

@ -1,132 +0,0 @@
package schemas
import (
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"runtime"
"testing/fstest"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/load"
)
var cueImportsPath = filepath.Join("packages", "grafana-schema", "src", "common")
var importPath = "github.com/grafana/grafana/packages/grafana-schema/src/common"
type ComposableKind struct {
Name string
Filename string
CueFile cue.Value
}
func GetComposableKinds() ([]ComposableKind, error) {
kinds := make([]ComposableKind, 0)
_, caller, _, _ := runtime.Caller(0)
root := filepath.Join(caller, "../../../..")
{{- range .Schemas }}
{{ .Name }}Cue, err := loadCueFileWithCommon(root, filepath.Join(root, "{{ .FilePath }}"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "{{ .Name }}",
Filename: "{{ .Filename }}",
CueFile: {{ .Name }}Cue,
})
{{- end }}
return kinds, nil
}
func loadCueFileWithCommon(root string, entrypoint string) (cue.Value, error) {
commonFS, err := mockCommonFS(root)
if err != nil {
fmt.Printf("cannot load common cue files: %s\n", err)
return cue.Value{}, err
}
overlay, err := buildOverlay(commonFS)
if err != nil {
fmt.Printf("Cannot build overlay: %s\n", err)
return cue.Value{}, err
}
bis := load.Instances([]string{entrypoint}, &load.Config{
ModuleRoot: "/",
Overlay: overlay,
})
values, err := cuecontext.New().BuildInstances(bis)
if err != nil {
fmt.Printf("Cannot build instance: %s\n", err)
return cue.Value{}, err
}
return values[0], nil
}
func mockCommonFS(root string) (fs.FS, error) {
path := filepath.Join(root, cueImportsPath)
dir, err := os.ReadDir(path)
if err != nil {
return nil, fmt.Errorf("cannot open common cue files directory: %s", err)
}
prefix := "cue.mod/pkg/" + importPath
commonFS := fstest.MapFS{}
for _, d := range dir {
if d.IsDir() {
continue
}
readPath := filepath.Join(path, d.Name())
b, err := os.ReadFile(filepath.Clean(readPath))
if err != nil {
return nil, err
}
commonFS[filepath.Join(prefix, d.Name())] = &fstest.MapFile{Data: b}
}
return commonFS, nil
}
// It loads common cue files into the schema to be able to make import works
func buildOverlay(commonFS fs.FS) (map[string]load.Source, error) {
overlay := make(map[string]load.Source)
err := fs.WalkDir(commonFS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
f, err := commonFS.Open(path)
if err != nil {
return err
}
defer func() { _ = f.Close() }()
b, err := io.ReadAll(f)
if err != nil {
return err
}
overlay[filepath.Join("/", path)] = load.FromBytes(b)
return nil
})
return overlay, err
}

View file

@ -1,458 +0,0 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
//
// Generated by:
// public/app/plugins/gen.go
// Using jennies:
// PluginRegistryJenny
//
// Run 'make gen-cue' from repository root to regenerate.
package schemas
import (
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"runtime"
"testing/fstest"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/load"
)
var cueImportsPath = filepath.Join("packages", "grafana-schema", "src", "common")
var importPath = "github.com/grafana/grafana/packages/grafana-schema/src/common"
type ComposableKind struct {
Name string
Filename string
CueFile cue.Value
}
func GetComposableKinds() ([]ComposableKind, error) {
kinds := make([]ComposableKind, 0)
_, caller, _, _ := runtime.Caller(0)
root := filepath.Join(caller, "../../../..")
azuremonitorCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/azuremonitor/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "azuremonitor",
Filename: "dataquery.cue",
CueFile: azuremonitorCue,
})
googlecloudmonitoringCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/cloud-monitoring/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "googlecloudmonitoring",
Filename: "dataquery.cue",
CueFile: googlecloudmonitoringCue,
})
cloudwatchCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/cloudwatch/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "cloudwatch",
Filename: "dataquery.cue",
CueFile: cloudwatchCue,
})
elasticsearchCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/elasticsearch/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "elasticsearch",
Filename: "dataquery.cue",
CueFile: elasticsearchCue,
})
grafanapyroscopeCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/grafana-pyroscope-datasource/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "grafanapyroscope",
Filename: "dataquery.cue",
CueFile: grafanapyroscopeCue,
})
lokiCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/loki/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "loki",
Filename: "dataquery.cue",
CueFile: lokiCue,
})
parcaCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/parca/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "parca",
Filename: "dataquery.cue",
CueFile: parcaCue,
})
tempoCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/datasource/tempo/dataquery.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "tempo",
Filename: "dataquery.cue",
CueFile: tempoCue,
})
annotationslistCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/annolist/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "annotationslist",
Filename: "panelcfg.cue",
CueFile: annotationslistCue,
})
barchartCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/barchart/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "barchart",
Filename: "panelcfg.cue",
CueFile: barchartCue,
})
bargaugeCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/bargauge/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "bargauge",
Filename: "panelcfg.cue",
CueFile: bargaugeCue,
})
candlestickCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/candlestick/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "candlestick",
Filename: "panelcfg.cue",
CueFile: candlestickCue,
})
canvasCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/canvas/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "canvas",
Filename: "panelcfg.cue",
CueFile: canvasCue,
})
dashboardlistCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/dashlist/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "dashboardlist",
Filename: "panelcfg.cue",
CueFile: dashboardlistCue,
})
datagridCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/datagrid/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "datagrid",
Filename: "panelcfg.cue",
CueFile: datagridCue,
})
debugCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/debug/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "debug",
Filename: "panelcfg.cue",
CueFile: debugCue,
})
gaugeCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/gauge/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "gauge",
Filename: "panelcfg.cue",
CueFile: gaugeCue,
})
geomapCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/geomap/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "geomap",
Filename: "panelcfg.cue",
CueFile: geomapCue,
})
heatmapCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/heatmap/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "heatmap",
Filename: "panelcfg.cue",
CueFile: heatmapCue,
})
histogramCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/histogram/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "histogram",
Filename: "panelcfg.cue",
CueFile: histogramCue,
})
logsCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/logs/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "logs",
Filename: "panelcfg.cue",
CueFile: logsCue,
})
logstableCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/logstable/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "logstable",
Filename: "panelcfg.cue",
CueFile: logstableCue,
})
newsCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/news/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "news",
Filename: "panelcfg.cue",
CueFile: newsCue,
})
nodegraphCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/nodeGraph/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "nodegraph",
Filename: "panelcfg.cue",
CueFile: nodegraphCue,
})
piechartCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/piechart/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "piechart",
Filename: "panelcfg.cue",
CueFile: piechartCue,
})
statCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/stat/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "stat",
Filename: "panelcfg.cue",
CueFile: statCue,
})
statetimelineCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/state-timeline/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "statetimeline",
Filename: "panelcfg.cue",
CueFile: statetimelineCue,
})
statushistoryCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/status-history/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "statushistory",
Filename: "panelcfg.cue",
CueFile: statushistoryCue,
})
tableCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/table/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "table",
Filename: "panelcfg.cue",
CueFile: tableCue,
})
textCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/text/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "text",
Filename: "panelcfg.cue",
CueFile: textCue,
})
timeseriesCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/timeseries/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "timeseries",
Filename: "panelcfg.cue",
CueFile: timeseriesCue,
})
trendCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/trend/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "trend",
Filename: "panelcfg.cue",
CueFile: trendCue,
})
xychartCue, err := loadCueFileWithCommon(root, filepath.Join(root, "./public/app/plugins/panel/xychart/panelcfg.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, ComposableKind{
Name: "xychart",
Filename: "panelcfg.cue",
CueFile: xychartCue,
})
return kinds, nil
}
func loadCueFileWithCommon(root string, entrypoint string) (cue.Value, error) {
commonFS, err := mockCommonFS(root)
if err != nil {
fmt.Printf("cannot load common cue files: %s\n", err)
return cue.Value{}, err
}
overlay, err := buildOverlay(commonFS)
if err != nil {
fmt.Printf("Cannot build overlay: %s\n", err)
return cue.Value{}, err
}
bis := load.Instances([]string{entrypoint}, &load.Config{
ModuleRoot: "/",
Overlay: overlay,
})
values, err := cuecontext.New().BuildInstances(bis)
if err != nil {
fmt.Printf("Cannot build instance: %s\n", err)
return cue.Value{}, err
}
return values[0], nil
}
func mockCommonFS(root string) (fs.FS, error) {
path := filepath.Join(root, cueImportsPath)
dir, err := os.ReadDir(path)
if err != nil {
return nil, fmt.Errorf("cannot open common cue files directory: %s", err)
}
prefix := "cue.mod/pkg/" + importPath
commonFS := fstest.MapFS{}
for _, d := range dir {
if d.IsDir() {
continue
}
readPath := filepath.Join(path, d.Name())
b, err := os.ReadFile(filepath.Clean(readPath))
if err != nil {
return nil, err
}
commonFS[filepath.Join(prefix, d.Name())] = &fstest.MapFile{Data: b}
}
return commonFS, nil
}
// It loads common cue files into the schema to be able to make import works
func buildOverlay(commonFS fs.FS) (map[string]load.Source, error) {
overlay := make(map[string]load.Source)
err := fs.WalkDir(commonFS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
f, err := commonFS.Open(path)
if err != nil {
return err
}
defer func() { _ = f.Close() }()
b, err := io.ReadAll(f)
if err != nil {
return err
}
overlay[filepath.Join("/", path)] = load.FromBytes(b)
return nil
})
return overlay, err
}

View file

@ -1,52 +0,0 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
//
// Generated by:
// kinds/gen.go
// Using jennies:
// CoreRegistryJenny
//
// Run 'make gen-cue' from repository root to regenerate.
package schemas
import (
"os"
"path/filepath"
"runtime"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
)
type CoreKind struct {
Name string
CueFile cue.Value
}
func GetCoreKinds() ([]CoreKind, error) {
ctx := cuecontext.New()
kinds := make([]CoreKind, 0)
_, caller, _, _ := runtime.Caller(0)
root := filepath.Join(caller, "../../../..")
dashboardCue, err := loadCueFile(ctx, filepath.Join(root, "./kinds/dashboard/dashboard_kind.cue"))
if err != nil {
return nil, err
}
kinds = append(kinds, CoreKind{
Name: "dashboard",
CueFile: dashboardCue,
})
return kinds, nil
}
func loadCueFile(ctx *cue.Context, path string) (cue.Value, error) {
cueFile, err := os.ReadFile(path)
if err != nil {
return cue.Value{}, err
}
return ctx.CompileBytes(cueFile), nil
}

View file

@ -43,7 +43,6 @@ func main() {
})
pluginKindGen.Append(
&codegen.PluginRegistryJenny{},
codegen.PluginGoTypesJenny("pkg/tsdb"),
codegen.PluginTSTypesJenny("public/app/plugins"),
)