diff --git a/pkg/commands/install/install.go b/pkg/commands/install/install.go index fccbd85..c4c0e40 100644 --- a/pkg/commands/install/install.go +++ b/pkg/commands/install/install.go @@ -49,10 +49,11 @@ func Execute(c *cli.Context) error { MetadataDir: metadataDir, DownloadsDir: downloadsDir, Settings: map[string]interface{}{ - "version": c.String("version"), - "github-token": c.String("github-token"), - "gitlab-token": c.String("gitlab-token"), - "no-checksum-verify": c.Bool("no-checksum-verify"), + "version": c.String("version"), + "github-token": c.String("github-token"), + "gitlab-token": c.String("gitlab-token"), + "no-checksum-verify": c.Bool("no-checksum-verify"), + "include-pre-releases": c.Bool("include-pre-releases"), }, }) if err != nil { @@ -150,6 +151,12 @@ func Flags() []cli.Flag { EnvVars: []string{"DISTILLERY_GITLAB_TOKEN"}, Category: "Authentication", }, + &cli.BoolFlag{ + Name: "include-pre-releases", + Usage: "Include pre-releases in the list of available versions", + EnvVars: []string{"DISTILLERY_INCLUDE_PRE_RELEASES"}, + Aliases: []string{"pre"}, + }, &cli.BoolFlag{ Name: "no-checksum-verify", Usage: "Disable checksum verification", diff --git a/pkg/source/github.go b/pkg/source/github.go index 76ac7e9..fd50ab3 100644 --- a/pkg/source/github.go +++ b/pkg/source/github.go @@ -101,17 +101,27 @@ func (s *GitHub) FindRelease(ctx context.Context) error { if s.Version == "latest" { release, _, err = s.client.Repositories.GetLatestRelease(ctx, s.GetOwner(), s.GetRepo()) - if err != nil { + if err != nil && !strings.Contains(err.Error(), "404 Not Found") { return err } - s.Version = strings.TrimPrefix(release.GetTagName(), "v") - } else { + if release != nil { + s.Version = strings.TrimPrefix(release.GetTagName(), "v") + } + } + + if release == nil { releases, _, err := s.client.Repositories.ListReleases(ctx, s.GetOwner(), s.GetRepo(), nil) if err != nil { return err } for _, r := range releases { + includePreReleases := s.Options.Settings["include-pre-releases"].(bool) + if includePreReleases && r.GetPrerelease() { + release = r + break + } + if r.GetTagName() == s.Version || r.GetName() == fmt.Sprintf("v%s", s.Version) { release = r break @@ -155,6 +165,10 @@ func (s *GitHub) GetReleaseAssets(ctx context.Context) error { params.Page = res.NextPage } + if len(s.Assets) == 0 { + return fmt.Errorf("no assets found") + } + return nil } diff --git a/pkg/source/source.go b/pkg/source/source.go index 3db9bfe..65d8976 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "errors" "fmt" + "github.com/apex/log" "github.com/ekristen/distillery/pkg/checksum" "os" "strings" @@ -162,7 +163,7 @@ func (s *Source) verifyChecksum() error { return fmt.Errorf("checksum verification failed") } - logrus.Info("checksum verified") + log.Info("checksum verified") return nil }