* Chore: Add go workspace (#83191) --------- Co-authored-by: ismail simsek <ismailsimsek09@gmail.com> * CI: Make pkg/build its own module, remove unused Grafana modules in go.mo… (#89243) * Make pkg/build its own module, remove unused Grafana modules in go.mod/go.sum * fix go.work format * log errors on file close errors * CI: Add release-pr workflow (#89005) * Add release-pr workflow * update CODEOWNERS * CI: Trigger release pr workflow when a release is completed (#89062) * Automation: Verify release artifacts on grafana.com (#89197) * baldm0mma/verify_release/ create verify_release_for_download function * baldm0mma/verify_release/ add name, image, env * baldm0mma/verify_release/ add initial commands * baldm0mma/verify_release/ add deps? * baldm0mma/verify_release/ update location * baldm0mma/verify_release/ add anno to lib-star * bald0mma/verify_release/ update func name to verify_grafanacom_step * baldm0mma/verify_release/ add verify shell script * baldm0mma/verify_release/ add script content, first attempt * baldm0mma/verify_release/ add node image to verify_grafanacom_step * baldm0mma/verify_release/ add gcom secret note * baldm0mma/verify_release/ add sudo to apt-get * baldm0mma/verify_release/ add anno * baldm0mma/verify_release/ add anno to secrets * baldm0mma/verify_release/ update commands to reflect node env image * baldm0mma/verify_release/ update annos * baldm0mma/verify_release/ update tag variable * baldm0mma/verify release/ add whitespace * baldm0mma/verify_releases/ update with no bash loops * baldm0mma/verify_release/ update exit logic * baldm0mma/verify_release/ remove annos * baldm0mma/verify_releasse/ resign and build yml * baldm0mma/verify_release/ remove annos * baldm0mma/verify_release/ update signature * baldm0mma/verify_release/ download curl * baldm0mma/verify_release/ remove temp key folder removal * baldm0mma/verify_release/ account for artifact download time * baldm0mma/verify_release/ add anno * baldm0mma/verify_release/ update location * baldm0mma/verify_release/ update script * baldm0mma/verify_release/ make drone * baldm0mma/verify_release/ update script for oss or ent * baldm0mma/verify_release/ add promotion option * baldm0mma/verify_release/ make drone * Update scripts/drone/events/release.star Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> * Update scripts/drone/steps/lib.star Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> * Update scripts/drone/steps/lib.star Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> * baldm0mma/verify_release/ update drone * Update scripts/drone/events/release.star Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> * baldm0mma/verify_release/ update drone * Update scripts/drone/steps/lib.star Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> * baldm0mma/update drone * baldm0mma/verify_release/ update path * baldm0mma/verify_release/ make drone * baldm0mma/update drone * Apply suggestions from code review Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> * baldm0mma/verify_release/ update for loop to account for failure * baldm0mma/verify_release/ make drone * baldm0mma/verify_release/ make format-drone * baldm0mma/verify_release/ rem unused var --------- Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com> --------- Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com> Co-authored-by: ismail simsek <ismailsimsek09@gmail.com> Co-authored-by: Jev Forsberg <46619047+baldm0mma@users.noreply.github.com>
101 lines
2.3 KiB
Go
101 lines
2.3 KiB
Go
package codegen
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"github.com/grafana/codejen"
|
|
tsast "github.com/grafana/cuetsy/ts/ast"
|
|
corecodegen "github.com/grafana/grafana/pkg/codegen"
|
|
"github.com/grafana/grafana/pkg/cuectx"
|
|
"github.com/grafana/grafana/pkg/plugins/pfs"
|
|
"github.com/grafana/kindsys"
|
|
"github.com/grafana/thema"
|
|
)
|
|
|
|
func PluginTSEachMajor(rt *thema.Runtime) codejen.OneToMany[*pfs.PluginDecl] {
|
|
latestMajorsOrX := corecodegen.LatestMajorsOrXJenny(filepath.Join("packages", "grafana-schema", "src", "raw", "composable"), false, corecodegen.TSTypesJenny{})
|
|
return &pleJenny{
|
|
inner: kinds2pd(rt, latestMajorsOrX),
|
|
}
|
|
}
|
|
|
|
type pleJenny struct {
|
|
inner codejen.OneToMany[*pfs.PluginDecl]
|
|
}
|
|
|
|
func (*pleJenny) JennyName() string {
|
|
return "PluginEachMajorJenny"
|
|
}
|
|
|
|
func (j *pleJenny) Generate(decl *pfs.PluginDecl) (codejen.Files, error) {
|
|
if !decl.HasSchema() {
|
|
return nil, nil
|
|
}
|
|
|
|
jf, err := j.inner.Generate(decl)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
version := "export const pluginVersion = \"%s\";"
|
|
if decl.PluginMeta.Info.Version != nil {
|
|
version = fmt.Sprintf(version, *decl.PluginMeta.Info.Version)
|
|
} else {
|
|
version = fmt.Sprintf(version, getGrafanaVersion())
|
|
}
|
|
|
|
files := make(codejen.Files, len(jf))
|
|
for i, file := range jf {
|
|
tsf := &tsast.File{}
|
|
for _, im := range decl.Imports {
|
|
if tsim, err := cuectx.ConvertImport(im); err != nil {
|
|
return nil, err
|
|
} else if tsim.From.Value != "" {
|
|
tsf.Imports = append(tsf.Imports, tsim)
|
|
}
|
|
}
|
|
|
|
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
|
|
Data: version,
|
|
})
|
|
|
|
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
|
|
Data: string(file.Data),
|
|
})
|
|
|
|
data := []byte(tsf.String())
|
|
data = data[:len(data)-1] // remove the additional line break added by the inner jenny
|
|
|
|
files[i] = *codejen.NewFile(file.RelativePath, data, append(file.From, j)...)
|
|
}
|
|
|
|
return files, nil
|
|
}
|
|
|
|
func kinds2pd(rt *thema.Runtime, j codejen.OneToMany[kindsys.Kind]) codejen.OneToMany[*pfs.PluginDecl] {
|
|
return codejen.AdaptOneToMany(j, func(pd *pfs.PluginDecl) kindsys.Kind {
|
|
kd, err := kindsys.BindComposable(rt, pd.KindDecl)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return kd
|
|
})
|
|
}
|
|
|
|
func getGrafanaVersion() string {
|
|
dir, err := os.Getwd()
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
pkg, err := OpenPackageJSON(path.Join(dir, "../../../"))
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
return pkg.Version
|
|
}
|