Skip to content

Commit e2b2e71

Browse files
committed
Add patch notes to assets package
1 parent d73c05e commit e2b2e71

File tree

5 files changed

+135
-21
lines changed

5 files changed

+135
-21
lines changed

assets/assets_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package assets
22

3-
import "testing"
3+
import (
4+
"strings"
5+
"testing"
6+
)
47

58
func TestLogo(t *testing.T) {
69
logo := Logo()
@@ -71,3 +74,49 @@ func TestEmptyVersionPanics(t *testing.T) {
7174
_ = RocketPoolVersion()
7275

7376
}
77+
78+
func TestPrintPatchNotes(t *testing.T) {
79+
// Reset v singleton
80+
v = &version{"test"}
81+
notes, err := GetPatchNotes()
82+
if err != nil {
83+
t.Fatal(err)
84+
}
85+
86+
t.Log("Rendered patch notes: ", notes)
87+
88+
// Make sure there are no template directives unpopulated
89+
if strings.Contains(notes, "{{") || strings.Contains(notes, "}}") {
90+
t.Fatal("encountered unexpanded template directive")
91+
}
92+
93+
if !strings.Contains(notes, Logo()) {
94+
t.Fatal("expected logo in patch notes")
95+
}
96+
97+
if !strings.Contains(notes, "test patch notes") {
98+
t.Fatal("expected template body in patch notes")
99+
}
100+
}
101+
102+
// This tests ensures each version has a patchnotes template
103+
func TestPrintCurrentPatchNotes(t *testing.T) {
104+
// Reset v singleton
105+
v = nil
106+
107+
notes, err := GetPatchNotes()
108+
if err != nil {
109+
t.Fatal(err)
110+
}
111+
112+
t.Log("Rendered patch notes: ", notes)
113+
114+
// Make sure there are no template directives unpopulated
115+
if strings.Contains(notes, "{{") || strings.Contains(notes, "}}") {
116+
t.Fatal("encountered unexpanded template directive")
117+
}
118+
119+
if !strings.Contains(notes, Logo()) {
120+
t.Fatal("expected logo in patch notes")
121+
}
122+
}

assets/patchnotes.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package assets
2+
3+
import (
4+
"embed"
5+
"fmt"
6+
"strings"
7+
"text/template"
8+
9+
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/utils/terminal"
10+
)
11+
12+
var patchnotesTemplateFields = struct {
13+
ColorReset string
14+
ColorBold string
15+
ColorRed string
16+
ColorGreen string
17+
ColorYellow string
18+
ColorBlue string
19+
RocketPoolVersion string
20+
}{
21+
ColorReset: terminal.ColorReset,
22+
ColorBold: terminal.ColorBold,
23+
ColorRed: terminal.ColorRed,
24+
ColorGreen: terminal.ColorGreen,
25+
ColorYellow: terminal.ColorYellow,
26+
ColorBlue: terminal.ColorBlue,
27+
RocketPoolVersion: "",
28+
}
29+
30+
//go:embed patchnotes/*.tmpl
31+
var patchnotesFS embed.FS
32+
33+
func loadTemplate(version string) (*template.Template, error) {
34+
return template.ParseFS(patchnotesFS, fmt.Sprintf("patchnotes/%s.tmpl", version))
35+
}
36+
37+
// PrintPatchNotes looks for a template in ./patchnotes/ with a name matching the current
38+
// version of smartnode and a file extension of .tmpl
39+
//
40+
// If it finds one, it populates it using the PatchNotes struct defined above, and prints it after printing the logo.
41+
// It returns an error when no template exists, or the template could not be populated.
42+
func GetPatchNotes() (string, error) {
43+
version := RocketPoolVersion()
44+
tmpl, err := loadTemplate(version)
45+
if err != nil {
46+
return "", fmt.Errorf("unable to read patch notes: %w", err)
47+
}
48+
49+
// Set RocketPoolVersion before executing
50+
patchnotesTemplateFields.RocketPoolVersion = version
51+
52+
notes := new(strings.Builder)
53+
notes.WriteString("\n")
54+
notes.WriteString(Logo())
55+
err = tmpl.Execute(notes, patchnotesTemplateFields)
56+
if err != nil {
57+
return "", fmt.Errorf("unable to populate patch notes template: %w", err)
58+
}
59+
60+
return notes.String(), nil
61+
}

assets/patchnotes/2.0.0-b3.tmpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{.ColorGreen}}=== Smart Node v{{.RocketPoolVersion}} ==={{.ColorReset}}
2+
3+
Changes you should be aware of before starting:
4+
5+
{{.ColorGreen}}=== Welcome to the v2.0 Beta! ==={{.ColorReset}}
6+
Welcome to Smart Node v2! This is a completely redesigned Smart Node from the ground up, taking advantage of years of lessons learned and user feedback. The list of features and changes is far too long to list here, but here are some highlights:
7+
- Support for installing and updating via Debian's `apt` package manager (other package managers coming soon!)
8+
- Support for printing transaction data or signed transactions without submitting them to the network
9+
- Passwordless mode: an opt-in feature that will no longer save your node wallet's password to disk
10+
- Overhauled Smart Node service with an HTTP API, support for batching Ethereum queries and transactions together, a new logging system, and consolidation of the api / node / watchtower containers into one
11+
- And much more!
12+
13+
To learn all about what's changed in Smart Node v2 and how to use it, take a look at our guide: https://github.com/rocket-pool/smartnode/blob/v2/v2.md

assets/patchnotes/test.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{.RocketPoolVersion}} patch notes.
2+
3+
This file is a test of Patch Note template population and printing.
4+
{{.ColorGreen}} Green Text {{.ColorReset}}

rocketpool-cli/commands/service/install.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ func installService(c *cli.Context) error {
7777
fmt.Println("")
7878
fmt.Println("The Rocket Pool Smart Node service was successfully installed!")
7979

80-
printPatchNotes()
80+
patchNotes, err := assets.GetPatchNotes()
81+
if err != nil {
82+
fmt.Println("Couldn't get patch notes: this version of Smart Node may not have any.")
83+
fmt.Printf("Error: %v\n", err)
84+
} else {
85+
fmt.Print(patchNotes)
86+
}
8187

8288
// Reload the config after installation
8389
_, isNew, err := rp.LoadConfig()
@@ -97,22 +103,3 @@ func installService(c *cli.Context) error {
97103

98104
return nil
99105
}
100-
101-
// Print the latest patch notes for this release
102-
// TODO: get this from an external source and don't hardcode it into the CLI
103-
func printPatchNotes() {
104-
fmt.Println()
105-
fmt.Println(assets.Logo())
106-
fmt.Printf("%s=== Smart Node v%s ===%s\n\n", terminal.ColorGreen, assets.RocketPoolVersion(), terminal.ColorReset)
107-
fmt.Printf("Changes you should be aware of before starting:\n\n")
108-
109-
fmt.Printf("%s=== Welcome to the v2.0 Beta! ===%s\n", terminal.ColorGreen, terminal.ColorReset)
110-
fmt.Println("Welcome to Smart Node v2! This is a completely redesigned Smart Node from the ground up, taking advantage of years of lessons learned and user feedback. The list of features and changes is far too long to list here, but here are some highlights:")
111-
fmt.Println("- Support for installing and updating via Debian's `apt` package manager (other package managers coming soon!)")
112-
fmt.Println("- Support for printing transaction data or signed transactions without submitting them to the network")
113-
fmt.Println("- Passwordless mode: an opt-in feature that will no longer save your node wallet's password to disk")
114-
fmt.Println("- Overhauled Smart Node service with an HTTP API, support for batching Ethereum queries and transactions together, a new logging system, and consolidation of the api / node / watchtower containers into one")
115-
fmt.Println("- And much more!")
116-
fmt.Println()
117-
fmt.Println("To learn all about what's changed in Smart Node v2 and how to use it, take a look at our guide: https://github.com/rocket-pool/smartnode/blob/v2/v2.md")
118-
}

0 commit comments

Comments
 (0)