Do codegen and check no-diff of all (non-blacklisted) CUE->TS codegen during CI (#39922)

* Add file blacklist to `grafana-cli cue gen-ts` cmd

* Add CI step checking all cuetsification is done

* Add dummy command to make the next one fail

* Generate drone bits

* Check diff output failure

* Echo list of untracked files, for failure locality

* Move git cleanness checking into script

* Blacklist of cue files is complete and correct

* Remove news panel plugin from cuetsify blacklist

* Dummy commit, check that untracked gen still fail

* Tie off remaining errors

* Re-add barchart to blacklist
* Remove file left around by earlier pipeline
* Commit generated news models.gen.ts

* Include eslint as part of cuetsified output gen

* Update pkg/cmd/grafana-cli/commands/cuetsify_command.go

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>

* Update scripts/drone/steps/lib.star

Co-authored-by: Maria Alexandra <239999+axelavargas@users.noreply.github.com>

* Update drone.yml

* Last fix on .drone.yml

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
Co-authored-by: Maria Alexandra <239999+axelavargas@users.noreply.github.com>
This commit is contained in:
sam boyer
2021-10-08 08:47:55 -04:00
committed by GitHub
parent e822c8a24d
commit 0fe200ce41
8 changed files with 210 additions and 7 deletions

View File

@@ -27,12 +27,38 @@ import (
var ctx = cuecontext.New()
// The only import statement we currently allow in any models.cue file
const allowedImport = "github.com/grafana/grafana/packages/grafana-schema/src/schema"
var importMap = map[string]string{
allowedImport: "@grafana/schema",
}
// Hard-coded list of paths to skip. Remove a particular file as we're ready
// to rely on the TypeScript auto-generated by cuetsy for that particular file.
var skipPaths = []string{
"public/app/plugins/panel/barchart/models.cue",
"public/app/plugins/panel/bargauge/models.cue",
"public/app/plugins/panel/canvas/models.cue",
"public/app/plugins/panel/dashlist/models.cue",
"public/app/plugins/panel/gauge/models.cue",
"public/app/plugins/panel/histogram/models.cue",
"public/app/plugins/panel/stat/models.cue",
"public/app/plugins/panel/state-timeline/models.cue",
"public/app/plugins/panel/status-history/models.cue",
"public/app/plugins/panel/table/models.cue",
"public/app/plugins/panel/text/models.cue",
"public/app/plugins/panel/timeseries/models.cue",
// All the cue files in this dir have to be individually excluded, even
// though the generator currently smooshes them all together
"packages/grafana-schema/src/schema/graph.cue",
"packages/grafana-schema/src/schema/legend.cue",
"packages/grafana-schema/src/schema/mudball.cue",
"packages/grafana-schema/src/schema/table.cue",
"packages/grafana-schema/src/schema/text.cue",
"packages/grafana-schema/src/schema/tooltip.cue",
}
const prefix = "/"
func (cmd Command) generateTypescript(c utils.CommandLine) error {
@@ -82,6 +108,20 @@ func (cmd Command) generateTypescript(c utils.CommandLine) error {
"packages/grafana-schema/src/scuemata/dashboard/dist": true,
}
exclude := func(path string) bool {
dir := filepath.Dir(path)
if excl[dir] {
return true
}
for _, p := range skipPaths {
if path == p {
return true
}
}
return false
}
outfiles := make(map[string][]byte)
cuetsify := func(in fs.FS) error {
@@ -92,7 +132,7 @@ func (cmd Command) generateTypescript(c utils.CommandLine) error {
}
dir := filepath.Dir(path)
if d.IsDir() || filepath.Ext(d.Name()) != ".cue" || seen[dir] || excl[dir] {
if d.IsDir() || filepath.Ext(d.Name()) != ".cue" || seen[dir] || exclude(path) {
return nil
}
seen[dir] = true