rhysd / go-github-selfupdate

Binary self-update mechanism for Go commands using GitHub

Home Page:https://godoc.org/github.com/rhysd/go-github-selfupdate/selfupdate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot isolate asset from releases with multiple artifacts

fredbi opened this issue · comments

When building a release with multiple artifacts (e.g. with goreleaser),
I found out that the self update cannot figure out which is the correct one.
As a matter of facts, this line tells that the first asset found with matching release, arch etc is
selected:

if strings.HasSuffix(name, s) {

I am proposing a fix here along the following lines:

  • add a type Option func(*settings) to capture some specific settings
  • add a type settings{filters: []*regexp.Regexp} to capture specifically a filter on assets (might be extended later on)
  • add an option functor like func AssetFilter(filter string) Option` to add some filtering regexp (note: invalid regexp panics...)
  • supplement the line above by a check on optional filters and select the first asset which matches any of the provided filters. If no filter is provided, keep the existing behavior
  • most public API calls (not all of them, though) are amended with a opt ...Option optional parameter, so we may pass the filter down to findAssetFromRelease

Would that approach look acceptable?