Skip to content

Commit

Permalink
add filter to updater (#2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
srliao committed Mar 11, 2024
1 parent 20259f3 commit 47714c6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
16 changes: 15 additions & 1 deletion cmd/gcsim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
Expand Down
33 changes: 27 additions & 6 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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")
Expand Down

0 comments on commit 47714c6

Please sign in to comment.