@@ -11,9 +11,14 @@ import (
1111 "github.com/flarco/g/net"
1212 "github.com/flarco/g/process"
1313 "github.com/kardianos/osext"
14+ "github.com/samber/lo"
1415 "github.com/slingdata-io/sling-cli/core"
1516 "github.com/slingdata-io/sling-cli/core/env"
16- "github.com/spf13/cast"
17+ )
18+
19+ var (
20+ // detect if running dev or stable channel
21+ isDevChannel = strings .Contains (core .Version , "dev" )
1722)
1823
1924// getDownloadURL returns the appropriate download URL based on the channel (dev or stable)
@@ -47,12 +52,9 @@ func updateCLI(c *g.CliSC) (ok bool, err error) {
4752 ok = true
4853 env .TelMap ["downloaded" ] = false
4954
50- // detect if running dev or stable channel
51- isDevChannel := strings .Contains (core .Version , "dev" )
52-
5355 // get latest version number (skipped for dev channel)
5456 if ! isDevChannel {
55- checkUpdate (true )
57+ checkUpdate ()
5658 if updateVersion == core .Version {
5759 g .Info ("Already up-to-date!" )
5860 return
@@ -192,13 +194,7 @@ func upgradeScoop() (err error) {
192194 return nil
193195}
194196
195- func checkUpdate (force bool ) {
196- if strings .Contains (core .Version , "dev" ) {
197- return
198- } else if time .Now ().Second ()% 4 != 0 && ! force {
199- // a way to check/notify about a new version less frequently
200- return
201- }
197+ func checkUpdate () {
202198
203199 instruction := "Please run `sling update`"
204200 switch getSlingPackage () {
@@ -212,17 +208,38 @@ func checkUpdate(force bool) {
212208 instruction = "Please run `docker pull slingdata/sling` and recreate your container."
213209 }
214210
215- const url = "https://api.github.com/repos/slingdata-io/sling-cli/releases"
216- _ , respB , _ := net .ClientDo ("GET" , url , nil , nil )
217- arr := []map [string ]any {}
218- g .JSONUnmarshal (respB , & arr )
219- if len (arr ) > 0 && arr [0 ] != nil {
220- updateVersion = strings .TrimPrefix (cast .ToString (arr [0 ]["tag_name" ]), "v" )
221- isNew , err := g .CompareVersions (core .Version , updateVersion )
222- if err != nil {
223- g .DebugLow ("Error comparing versions: %s" , err .Error ())
224- } else if isNew {
225- updateMessage = g .F ("FYI there is a new sling version released (%s). %s" , updateVersion , instruction )
211+ _ , respB , _ := net .ClientDo (
212+ "POST" , "https://version.slingdata.io" ,
213+ strings .NewReader (g .Marshal (g .M (
214+ "exec_id" , os .Getenv ("SLING_EXEC_ID" ),
215+ "channel" , lo .Ternary (isDevChannel , "dev" , "stable" ),
216+ "version_cli" , core .Version ,
217+ ))),
218+ nil ,
219+ 5 ,
220+ )
221+ respMap := map [string ]string {}
222+ g .JSONUnmarshal (respB , & respMap )
223+ if time .Now ().Second ()% 4 != 0 && len (respMap ) > 0 {
224+ updateVersion = respMap ["version_latest" ]
225+ if isDevChannel {
226+ if core .Version != updateVersion && updateVersion != "" {
227+ updateMessage = env .GreenString (g .F ("FYI there is a new sling dev build released => %s. You can run `sling update` to download it." , updateVersion ))
228+ }
229+ } else {
230+ isNew , err := g .CompareVersions (core .Version , updateVersion )
231+ if err != nil {
232+ g .Debug ("Error comparing versions: %s" , err .Error ())
233+ } else if isNew {
234+ updateMessage = env .GreenString (g .F ("FYI there is a new sling version released (%s). %s" , updateVersion , instruction ))
235+ }
236+ }
237+ if message := respMap ["media" ]; message != "" {
238+ if updateMessage != "" {
239+ updateMessage = updateMessage + "\n " + env .BlueString (message )
240+ } else {
241+ updateMessage = env .BlueString (message )
242+ }
226243 }
227244 }
228245}
0 commit comments