Skip to content

Commit 1452b41

Browse files
committed
use semver when comparing grafana and plugin versions
1 parent 9e26a4c commit 1452b41

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

pkg/plugins/update_checker.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/grafana/grafana/pkg/log"
1111
"github.com/grafana/grafana/pkg/setting"
12+
"github.com/hashicorp/go-version"
1213
)
1314

1415
type GrafanaNetPlugin struct {
@@ -84,7 +85,15 @@ func checkForUpdates() {
8485
for _, gplug := range gNetPlugins {
8586
if gplug.Slug == plug.Id {
8687
plug.GrafanaNetVersion = gplug.Version
87-
plug.GrafanaNetHasUpdate = plug.Info.Version != plug.GrafanaNetVersion
88+
89+
plugVersion, err1 := version.NewVersion(plug.Info.Version)
90+
gplugVersion, err2 := version.NewVersion(gplug.Version)
91+
92+
if err1 != nil || err2 != nil {
93+
plug.GrafanaNetHasUpdate = plug.Info.Version != plug.GrafanaNetVersion
94+
} else {
95+
plug.GrafanaNetHasUpdate = plugVersion.LessThan(gplugVersion)
96+
}
8897
}
8998
}
9099
}
@@ -116,4 +125,11 @@ func checkForUpdates() {
116125
GrafanaLatestVersion = githubLatest.Stable
117126
GrafanaHasUpdate = githubLatest.Stable != setting.BuildVersion
118127
}
128+
129+
currVersion, err1 := version.NewVersion(setting.BuildVersion)
130+
latestVersion, err2 := version.NewVersion(GrafanaLatestVersion)
131+
132+
if err1 == nil && err2 == nil {
133+
GrafanaHasUpdate = currVersion.LessThan(latestVersion)
134+
}
119135
}

public/views/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@
6464
<a href="http://grafana.org" target="_blank">Grafana</a>
6565
<span>v[[.BuildVersion]] (commit: [[.BuildCommit]])</span>
6666
</li>
67-
<li>
68-
[[if .NewGrafanaVersionExists]]
67+
[[if .NewGrafanaVersionExists]]
68+
<li>
6969
<a href="http://grafana.org/download" target="_blank" bs-tooltip="'[[.NewGrafanaVersion]]'">
7070
New version available!
7171
</a>
72-
[[end]]
73-
</li>
72+
</li>
73+
[[end]]
7474
</ul>
7575
</div>
7676
</footer>

0 commit comments

Comments
 (0)