Skip to content

Commit fa2c3ae

Browse files
feat: add feature to send library update message (#174)
* feat: add feature to send library update message
1 parent 8b51ab0 commit fa2c3ae

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

cmd/eigenlayer/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/Layr-Labs/eigenlayer-cli/internal/versionupdate"
78
"github.com/Layr-Labs/eigenlayer-cli/pkg"
89
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
10+
911
"github.com/urfave/cli/v2"
1012
)
1113

@@ -32,6 +34,10 @@ func main() {
3234

3335
// Initialize the dependencies
3436
prompter := utils.NewPrompter()
37+
app.After = func(c *cli.Context) error {
38+
versionupdate.Check(app.Version)
39+
return nil
40+
}
3541

3642
app.Commands = append(app.Commands, pkg.OperatorCmd(prompter))
3743
app.Commands = append(app.Commands, pkg.RewardsCmd(prompter))

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/Layr-Labs/eigenlayer-contracts v0.3.0-rc3-holesky-preprod-rewards.0.20240618161038-04a0176562a0
88
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.3
99
github.com/Layr-Labs/eigensdk-go v0.1.9
10+
github.com/blang/semver/v4 v4.0.0
1011
github.com/consensys/gnark-crypto v0.12.1
1112
github.com/ethereum/go-ethereum v1.14.5
1213
github.com/fatih/color v1.17.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
5858
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
5959
github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88=
6060
github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
61+
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
62+
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
6163
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
6264
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
6365
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package versionupdate
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"net/http"
8+
9+
"github.com/fatih/color"
10+
11+
"github.com/blang/semver/v4"
12+
)
13+
14+
const (
15+
organization = "Layr-Labs"
16+
repository = "eigenlayer-cli"
17+
)
18+
19+
type release struct {
20+
TagName string `json:"tag_name"`
21+
Name string `json:"name"`
22+
}
23+
24+
// Check if there is a new version of the package
25+
// If there is, print a message to the user
26+
// If there isn't, do nothing
27+
// Don't do anything for development version
28+
// If anything fails in this, it will silently pass since this doesn't affect operations
29+
func Check(currentVersion string) {
30+
if currentVersion == "development" {
31+
fmt.Println("Running development version")
32+
return
33+
}
34+
35+
// Get latest version from GitHub releases
36+
latestReleaseUrl := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", organization, repository)
37+
response, err := http.Get(latestReleaseUrl)
38+
if err != nil {
39+
return
40+
}
41+
defer response.Body.Close()
42+
respBytes, err := io.ReadAll(response.Body)
43+
if err != nil {
44+
return
45+
}
46+
var data release
47+
48+
err = json.Unmarshal(respBytes, &data)
49+
if err != nil {
50+
return
51+
}
52+
53+
// GitHub API returns in vX.X.X format so remove v
54+
latestVersion := data.TagName[1:]
55+
latestSemVer, err := semver.Make(latestVersion)
56+
if err != nil {
57+
return
58+
}
59+
60+
currentSemVer, err := semver.Make(currentVersion)
61+
if err != nil {
62+
return
63+
}
64+
65+
if latestSemVer.GT(currentSemVer) {
66+
greenVersion := color.GreenString(latestVersion)
67+
yellowOldVersion := color.YellowString(currentVersion)
68+
fmt.Println()
69+
fmt.Printf("There is a new version (%s) for this library available.\n", greenVersion)
70+
fmt.Printf("Your current running verison is (%s).\n", yellowOldVersion)
71+
fmt.Println("Please update (https://github.com/Layr-Labs/eigenlayer-cli#install-eigenlayer-cli-using-a-binary) to get latest features and bug fixes.")
72+
fmt.Println()
73+
}
74+
}

0 commit comments

Comments
 (0)