From 47714c6d913a47fdc38fb5e82c16f194f05855a9 Mon Sep 17 00:00:00 2001 From: srl <906239+srliao@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:48:54 -0400 Subject: [PATCH] add filter to updater (#2047) --- cmd/gcsim/main.go | 16 +++++++++++++++- cmd/server/main.go | 33 +++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/cmd/gcsim/main.go b/cmd/gcsim/main.go index d3f99cdf1..e0dd6e384 100644 --- a/cmd/gcsim/main.go +++ b/cmd/gcsim/main.go @@ -325,7 +325,19 @@ func writeSample(seed uint64, outputPath, config string, gz bool, simopt simulat } func update(version string) error { - latest, found, err := selfupdate.DetectLatest(context.Background(), selfupdate.ParseSlug("genshinsim/gcsim")) + src, err := selfupdate.NewGitHubSource(selfupdate.GitHubConfig{}) + if err != nil { + return fmt.Errorf("error creating GitHub source: %w", err) + } + updater, err := selfupdate.NewUpdater(selfupdate.Config{ + Source: src, + Filters: []string{"gcsim_.+"}, + }) + if err != nil { + return fmt.Errorf("error creating updater: %w", err) + } + + latest, found, err := updater.DetectLatest(context.Background(), selfupdate.ParseSlug("genshinsim/gcsim")) if err != nil { return fmt.Errorf("error occurred while detecting version: %w", err) } @@ -338,6 +350,8 @@ func update(version string) error { return nil } + log.Printf("Found latest version %v published at %v (%v), greater than current version %v\n", latest.Name, latest.PublishedAt, latest.AssetName, version) + exe, err := os.Executable() if err != nil { return errors.New("could not locate executable path") diff --git a/cmd/server/main.go b/cmd/server/main.go index bfbca4776..913c16371 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -22,11 +22,12 @@ var ( ) type opts struct { - host string - port string - shareKey string - timeout int - update bool + host string + port string + shareKey string + timeout int + update bool + showVersion bool } func main() { @@ -40,8 +41,14 @@ func main() { flag.StringVar(&opt.shareKey, "sharekey", "", "share key to use (default: build flag OR GCSIM_SHARE_KEY env variable if not available)") flag.IntVar(&opt.timeout, "timeout", 5*60, "how long to run each sim for in seconds before timing out (default: 300s)") flag.BoolVar(&opt.update, "update", false, "run autoupdater (default: false)") + flag.BoolVar(&opt.showVersion, "version", false, "show currrent version") flag.Parse() + if opt.showVersion { + fmt.Println("Running version: ", version) + return + } + if opt.update { err := update(version) if err != nil { @@ -70,7 +77,19 @@ func main() { } func update(version string) error { - latest, found, err := selfupdate.DetectLatest(context.Background(), selfupdate.ParseSlug("genshinsim/gcsim")) + src, err := selfupdate.NewGitHubSource(selfupdate.GitHubConfig{}) + if err != nil { + return fmt.Errorf("error creating GitHub source: %w", err) + } + updater, err := selfupdate.NewUpdater(selfupdate.Config{ + Source: src, + Filters: []string{"server_.+"}, + }) + if err != nil { + return fmt.Errorf("error creating updater: %w", err) + } + + latest, found, err := updater.DetectLatest(context.Background(), selfupdate.ParseSlug("genshinsim/gcsim")) if err != nil { return fmt.Errorf("error occurred while detecting version: %w", err) } @@ -83,6 +102,8 @@ func update(version string) error { return nil } + log.Printf("Found latest version %v published at %v (%v), greater than current version %v\n", latest.Name, latest.PublishedAt, latest.AssetName, version) + exe, err := os.Executable() if err != nil { return errors.New("could not locate executable path")