Improve notification for a new version, show release notes
This commit is contained in:
parent
451335e17d
commit
da970239a5
@ -30,12 +30,12 @@ func main() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
version.UpdateVersionInfo()
|
version.VersionInfo.UpdateVersionInfo()
|
||||||
time.Sleep(time.Hour * 6)
|
time.Sleep(time.Hour * 6)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Printf("linkwallet version %s starting", version.Is())
|
log.Printf("linkwallet version %s starting", version.VersionInfo.Local.Tag)
|
||||||
|
|
||||||
server := web.Create(bmm, cmm)
|
server := web.Create(bmm, cmm)
|
||||||
go bmm.RunQueue()
|
go bmm.RunQueue()
|
||||||
|
1
go.mod
1
go.mod
@ -37,6 +37,7 @@ require (
|
|||||||
github.com/gobwas/glob v0.2.3 // indirect
|
github.com/gobwas/glob v0.2.3 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
|
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb
|
||||||
github.com/google/go-github/v44 v44.1.0
|
github.com/google/go-github/v44 v44.1.0
|
||||||
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
|
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
|
||||||
github.com/kennygrant/sanitize v1.2.4 // indirect
|
github.com/kennygrant/sanitize v1.2.4 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -38,6 +38,8 @@ github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW
|
|||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
|
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb h1:5b/eFaSaKPFG9ygDBaPKkydKU5nFJYk08g9jPIVogMg=
|
||||||
|
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||||
|
@ -3,15 +3,16 @@ package version
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/google/go-github/v44/github"
|
"github.com/google/go-github/v44/github"
|
||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Tag = "v0.0.27"
|
const Tag = "v0.0.28"
|
||||||
|
|
||||||
var versionInfo struct {
|
type Info struct {
|
||||||
Local struct {
|
Local struct {
|
||||||
Tag string
|
Tag string
|
||||||
}
|
}
|
||||||
@ -23,36 +24,26 @@ var versionInfo struct {
|
|||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var VersionInfo Info
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
versionInfo.Remote.Valid = false
|
VersionInfo.Remote.Valid = false
|
||||||
versionInfo.Local.Tag = Tag
|
VersionInfo.Local.Tag = Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
func Is() string {
|
func (vi *Info) UpgradeAvailable() bool {
|
||||||
return versionInfo.Local.Tag
|
vi.m.Lock()
|
||||||
}
|
defer vi.m.Unlock()
|
||||||
|
if !vi.Remote.Valid {
|
||||||
func UpgradeAvailable() (bool, string) {
|
return false
|
||||||
versionInfo.m.Lock()
|
|
||||||
defer versionInfo.m.Unlock()
|
|
||||||
if !versionInfo.Remote.Valid {
|
|
||||||
return false, ""
|
|
||||||
}
|
}
|
||||||
if semver.Compare(versionInfo.Local.Tag, versionInfo.Remote.Tag) < 0 {
|
if semver.Compare(vi.Local.Tag, vi.Remote.Tag) < 0 {
|
||||||
return true, versionInfo.Remote.Tag
|
return true
|
||||||
}
|
}
|
||||||
return false, ""
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpgradeAvailableString() string {
|
func (vi *Info) UpdateVersionInfo() {
|
||||||
upgrade, ver := UpgradeAvailable()
|
|
||||||
if upgrade {
|
|
||||||
return ver
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateVersionInfo() {
|
|
||||||
client := github.NewClient(nil)
|
client := github.NewClient(nil)
|
||||||
|
|
||||||
rels, _, err := client.Repositories.ListReleases(context.Background(), "tardisx", "linkwallet", nil)
|
rels, _, err := client.Repositories.ListReleases(context.Background(), "tardisx", "linkwallet", nil)
|
||||||
@ -63,16 +54,24 @@ func UpdateVersionInfo() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
versionInfo.m.Lock()
|
vi.m.Lock()
|
||||||
versionInfo.Remote.Tag = *rels[0].TagName
|
vi.Remote.Tag = *rels[0].TagName
|
||||||
versionInfo.Remote.Valid = true
|
vi.Remote.Valid = true
|
||||||
versionInfo.UpgradeReleaseNotes = ""
|
vi.UpgradeReleaseNotes = ""
|
||||||
for _, r := range rels {
|
for _, r := range rels {
|
||||||
if semver.Compare(versionInfo.Local.Tag, *r.TagName) < 0 {
|
if semver.Compare(VersionInfo.Local.Tag, *r.TagName) < 0 {
|
||||||
versionInfo.UpgradeReleaseNotes += fmt.Sprintf("Version: %s\n\n%s\n\n", *r.TagName, *r.Body)
|
vi.UpgradeReleaseNotes += fmt.Sprintf("*Version %s*\n\n", *r.TagName)
|
||||||
|
bodyLines := strings.Split(*r.Body, "\n")
|
||||||
|
for _, l := range bodyLines {
|
||||||
|
if strings.Index(l, "#") == 0 && strings.Contains(l, "Changelog") {
|
||||||
|
// do nothing, ignore the changelog heading
|
||||||
|
} else {
|
||||||
|
vi.UpgradeReleaseNotes += l + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
versionInfo.m.Unlock()
|
vi.m.Unlock()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="top-bar-right">
|
<div class="top-bar-right">
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
{{ if newVersion }}
|
|
||||||
<li>
|
<li>
|
||||||
<div><a href="https://github.com/tardisx/linkwallet/releases/tag/{{ newVersion }}">{{ newVersion }} available</a></div>
|
<a href="/releaseinfo">{{ version.Local.Tag }}
|
||||||
</li>
|
{{ if version.UpgradeAvailable }}
|
||||||
|
❗
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<li class="menu-text">
|
</a>
|
||||||
{{ version }}
|
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="https://github.com/tardisx/linkwallet">
|
<a href="https://github.com/tardisx/linkwallet">
|
||||||
@ -64,6 +63,8 @@
|
|||||||
{{ template "config.html" . }}
|
{{ template "config.html" . }}
|
||||||
{{ else if eq .page "edit" }}
|
{{ else if eq .page "edit" }}
|
||||||
{{ template "edit.html" . }}
|
{{ template "edit.html" . }}
|
||||||
|
{{ else if eq .page "releaseinfo" }}
|
||||||
|
{{ template "release_info.html" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{/* template "foundation_sample.html" . */}}
|
{{/* template "foundation_sample.html" . */}}
|
||||||
</div>
|
</div>
|
||||||
|
23
web/templates/release_info.html
Normal file
23
web/templates/release_info.html
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<div class="grid-x grid-padding-x">
|
||||||
|
<div class="large-12 cell">
|
||||||
|
|
||||||
|
<h5>Release info</h5>
|
||||||
|
{{ if not version.Remote.Valid }}
|
||||||
|
<p>GitHub version information not yet fetched.</p>
|
||||||
|
{{ else }}
|
||||||
|
{{ if version.UpgradeAvailable }}
|
||||||
|
<p>
|
||||||
|
A new version is available:
|
||||||
|
<a href="https://github.com/tardisx/linkwallet/releases/tag/{{ version.Remote.Tag }}">
|
||||||
|
{{ version.Remote.Tag }}
|
||||||
|
</a>
|
||||||
|
(you have {{ version.Local.Tag }}).
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{{ markdown version.UpgradeReleaseNotes }}
|
||||||
|
|
||||||
|
{{ else }}
|
||||||
|
<p>You are currently running the most recent version.</p>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
17
web/web.go
17
web/web.go
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/tardisx/linkwallet/entity"
|
"github.com/tardisx/linkwallet/entity"
|
||||||
"github.com/tardisx/linkwallet/version"
|
"github.com/tardisx/linkwallet/version"
|
||||||
|
|
||||||
|
"github.com/gomarkdown/markdown"
|
||||||
"github.com/hako/durafmt"
|
"github.com/hako/durafmt"
|
||||||
|
|
||||||
"github.com/gin-contrib/gzip"
|
"github.com/gin-contrib/gzip"
|
||||||
@ -75,7 +76,14 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// templ := template.Must(template.New("").Funcs(template.FuncMap{"dict": dictHelper}).ParseFS(templateFiles, "templates/*.html"))
|
// templ := template.Must(template.New("").Funcs(template.FuncMap{"dict": dictHelper}).ParseFS(templateFiles, "templates/*.html"))
|
||||||
templ := template.Must(template.New("").Funcs(template.FuncMap{"nicetime": niceTime, "niceURL": niceURL, "join": strings.Join, "version": version.Is, "newVersion": version.UpgradeAvailableString}).ParseFS(templateFiles, "templates/*.html"))
|
templ := template.Must(template.New("").Funcs(
|
||||||
|
template.FuncMap{
|
||||||
|
"nicetime": niceTime,
|
||||||
|
"niceURL": niceURL,
|
||||||
|
"join": strings.Join,
|
||||||
|
"version": func() *version.Info { return &version.VersionInfo },
|
||||||
|
"markdown": func(s string) template.HTML { return template.HTML(string(markdown.ToHTML([]byte(s), nil, nil))) },
|
||||||
|
}).ParseFS(templateFiles, "templates/*.html"))
|
||||||
|
|
||||||
config, err := cmm.LoadConfig()
|
config, err := cmm.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -386,6 +394,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.GET("/releaseinfo", func(c *gin.Context) {
|
||||||
|
meta := gin.H{"page": "releaseinfo", "config": config}
|
||||||
|
c.HTML(http.StatusOK,
|
||||||
|
"_layout.html", meta,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user