diff --git a/pkg/plugins/manager/pipeline/bootstrap/steps.go b/pkg/plugins/manager/pipeline/bootstrap/steps.go index f2d61e58e91..9cfb92ea3cd 100644 --- a/pkg/plugins/manager/pipeline/bootstrap/steps.go +++ b/pkg/plugins/manager/pipeline/bootstrap/steps.go @@ -30,6 +30,7 @@ func DefaultConstructFunc(signatureCalculator plugins.SignatureCalculator, asset func DefaultDecorateFuncs(cfg *config.Cfg) []DecorateFunc { return []DecorateFunc{ AppDefaultNavURLDecorateFunc, + TemplateDecorateFunc, AppChildDecorateFunc(cfg), } } @@ -86,6 +87,22 @@ func AppDefaultNavURLDecorateFunc(_ context.Context, p *plugins.Plugin) (*plugin return p, nil } +// TemplateDecorateFunc is a DecorateFunc that removes the placeholder for the version and last_update fields. +func TemplateDecorateFunc(_ context.Context, p *plugins.Plugin) (*plugins.Plugin, error) { + // %VERSION% and %TODAY% are valid values, according to the plugin schema + // but it's meant to be replaced by the build system with the actual version and date. + // If not, it's the same than not having a version or a date. + if p.Info.Version == "%VERSION%" { + p.Info.Version = "" + } + + if p.Info.Updated == "%TODAY%" { + p.Info.Updated = "" + } + + return p, nil +} + func setDefaultNavURL(p *plugins.Plugin) { // slugify pages for _, include := range p.Includes { diff --git a/pkg/plugins/manager/pipeline/bootstrap/steps_test.go b/pkg/plugins/manager/pipeline/bootstrap/steps_test.go index 670a667a707..795d7f8a5a9 100644 --- a/pkg/plugins/manager/pipeline/bootstrap/steps_test.go +++ b/pkg/plugins/manager/pipeline/bootstrap/steps_test.go @@ -1,6 +1,7 @@ package bootstrap import ( + "context" "testing" "github.com/stretchr/testify/require" @@ -66,6 +67,34 @@ func TestSetDefaultNavURL(t *testing.T) { }) } +func TestTemplateDecorateFunc(t *testing.T) { + t.Run("Removes %VERSION%", func(t *testing.T) { + pluginWithoutVersion := &plugins.Plugin{ + JSONData: plugins.JSONData{ + Info: plugins.Info{ + Version: "%VERSION%", + }, + }, + } + p, err := TemplateDecorateFunc(context.TODO(), pluginWithoutVersion) + require.NoError(t, err) + require.Equal(t, "", p.Info.Version) + }) + + t.Run("Removes %TODAY%", func(t *testing.T) { + pluginWithoutVersion := &plugins.Plugin{ + JSONData: plugins.JSONData{ + Info: plugins.Info{ + Version: "%TODAY%", + }, + }, + } + p, err := TemplateDecorateFunc(context.TODO(), pluginWithoutVersion) + require.NoError(t, err) + require.Equal(t, "", p.Info.Updated) + }) +} + func Test_configureAppChildPlugin(t *testing.T) { t.Run("When setting paths based on core plugin on Windows", func(t *testing.T) { child := &plugins.Plugin{ diff --git a/pkg/services/pluginsintegration/loader/loader_test.go b/pkg/services/pluginsintegration/loader/loader_test.go index d062955e7fa..c4fda2f7b14 100644 --- a/pkg/services/pluginsintegration/loader/loader_test.go +++ b/pkg/services/pluginsintegration/loader/loader_test.go @@ -1335,8 +1335,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) { }, Screenshots: []plugins.Screenshots{}, Description: "Grafana App Plugin Template", - Version: "%VERSION%", - Updated: "%TODAY%", + Version: "", + Updated: "", }, Dependencies: plugins.Dependencies{ GrafanaVersion: "7.0.0", @@ -1415,8 +1415,8 @@ func TestLoader_Load_NestedPlugins(t *testing.T) { }, Screenshots: []plugins.Screenshots{}, Description: "Grafana Panel Plugin Template", - Version: "%VERSION%", - Updated: "%TODAY%", + Version: "", + Updated: "", }, Dependencies: plugins.Dependencies{ GrafanaDependency: ">=7.0.0",