Skip to content

Commit

Permalink
feat: support preleases on github
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Sep 1, 2024
1 parent 5fa2c02 commit 9943de5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
15 changes: 11 additions & 4 deletions pkg/commands/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 17 additions & 3 deletions pkg/source/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/apex/log"
"github.com/ekristen/distillery/pkg/checksum"
"os"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 9943de5

Please sign in to comment.