Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 7-app-update-is-not-working #8

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.2
v2.0.3
9 changes: 9 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/abhijitWakchaure/run-flogo-app/config"
"github.com/abhijitWakchaure/run-flogo-app/files"
"github.com/abhijitWakchaure/run-flogo-app/software"
"github.com/spf13/viper"
)

// App holds the environment variables for the user
Expand Down Expand Up @@ -46,6 +47,7 @@ func NewApp(appConfig *config.AppConfig, updateConfig *software.UpdateConfig) *A
if a.AppsDir == "" {
a.AppsDir = filepath.Join(config.GetUserHomeDir(), "Downloads")
}
WriteAppConfig(a.AppConfig)
software.PrintUpdateInfo(a.UpdateConfig)
return a
}
Expand All @@ -59,6 +61,13 @@ func (a *App) PrintConfig() {
config.Print(c)
}

// WriteAppConfig will write the app config
func WriteAppConfig(appConfig *config.AppConfig) {
viper.Set("appsDir", appConfig.AppsDir)
viper.Set("appPattern", appConfig.AppPattern)
viper.WriteConfig()
}

// RunLatestApp will run the latest app
func (a *App) RunLatestApp(logLevel string, args []string) {
latestFlogoApp := files.FindLatestApp(a.AppsDir, a.AppPattern)
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ var rootCmd = &cobra.Command{
name, _ := cmd.Flags().GetString("name")
go func() {
updateConfig := software.CheckForUpdates()
// TODO: write update config
_ = updateConfig
software.WriteUpdateConfig(updateConfig)
}()
logLevel := config.LogLevelInfo
if trace {
Expand Down Expand Up @@ -115,6 +114,7 @@ func initConfig() {
if err := viper.ReadInConfig(); err == nil {
fmt.Printf("i> Using config file: %s\n", viper.ConfigFileUsed())
}

appsDir := viper.GetString("appsDir")
appPattern := viper.GetString("appPattern")
isUpdateAvailable := viper.GetBool("isUpdateAvailable")
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// VERSION ...
var VERSION string
var VERSION = "undefined"

// AppConfig ...
type AppConfig struct {
Expand Down
30 changes: 22 additions & 8 deletions software/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/abhijitWakchaure/run-flogo-app/config"
"github.com/spf13/viper"
)

// UpdateConfig ...
Expand Down Expand Up @@ -104,6 +105,7 @@ func Uninstall(installPath string) {
func CheckForUpdates() *UpdateConfig {
resp, err := http.Get(config.GithubLastestReleaseURL)
if err != nil {
fmt.Printf("\n\nE> run-flogo-app Error: ERR_CHKUPDATE_HTTPGET %s\n", err)
return nil
}
defer resp.Body.Close()
Expand All @@ -118,27 +120,39 @@ func CheckForUpdates() *UpdateConfig {
fmt.Printf("\nE> run-flogo-app Error: ERR_CHKUPDATE_DECODE %s\n", err)
return nil
}
OSAndArch := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
for _, d := range assets {
durl := d.(map[string]interface{})["browser_download_url"].(string)
if strings.Contains(durl, runtime.GOOS) && !strings.Contains(durl, config.VERSION) {
return &UpdateConfig{
IsUpdateAvailable: true,
UpdateURL: durl,
ReleaseNotes: strings.Replace(strings.TrimSpace(gitdata["body"].(string)), "\n", "\n\t", -1),
}
} else if strings.Contains(durl, runtime.GOOS) {
if !strings.Contains(durl, OSAndArch) {
continue
}
if strings.Contains(durl, config.VERSION) {
// fmt.Println()
// fmt.Println("Your app is up to date 👍")
return nil
}
return &UpdateConfig{
IsUpdateAvailable: true,
UpdateURL: durl,
ReleaseNotes: strings.Replace(strings.TrimSpace(gitdata["body"].(string)), "\n", "\n\t", -1),
}

}
return nil
}

// WriteUpdateConfig will write the update info
func WriteUpdateConfig(updateConfig *UpdateConfig) {
viper.Set("isUpdateAvailable", updateConfig.IsUpdateAvailable)
viper.Set("updateURL", updateConfig.UpdateURL)
viper.Set("releaseNotes", updateConfig.ReleaseNotes)
viper.WriteConfig()
}

// PrintUpdateInfo will print the update info
func PrintUpdateInfo(updateConfig *UpdateConfig) {
if updateConfig.IsUpdateAvailable {
fmt.Println("#> New version of the app is available at:", updateConfig.UpdateURL)
fmt.Println("#> New version of the app is available!")
fmt.Println("#> Release Notes:")
fmt.Printf("\t%s\n\n", updateConfig.ReleaseNotes)
}
Expand Down