Skip to content

Commit

Permalink
feat: automatic support for distillery pre-releases, better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Sep 2, 2024
1 parent 5f0495b commit 4501b09
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/checksum/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCompareHashWithChecksumFile(t *testing.T) {
defer os.Remove(checksumFile.Name())

// Write the hash and filename to the checksum file
_, err = checksumFile.WriteString(fmt.Sprintf("%s %s\n", hash, tmpFile.Name()))
_, err = fmt.Fprintf(checksumFile, "%s %s\n", hash, tmpFile.Name())
assert.NoError(t, err)
checksumFile.Close()

Expand All @@ -69,7 +69,7 @@ func TestCompareHashWithChecksumFile(t *testing.T) {
assert.NoError(t, err)
defer os.Remove(checksumFile.Name())

_, err = checksumFile.WriteString(fmt.Sprintf("%s %s\n", hash, tmpFile.Name()))
_, err = fmt.Fprintf(checksumFile, "%s %s\n", hash, tmpFile.Name())
assert.NoError(t, err)
checksumFile.Close()

Expand Down
13 changes: 8 additions & 5 deletions pkg/commands/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ import (
"strings"

"github.com/apex/log"
clilog "github.com/apex/log/handlers/cli"

"github.com/urfave/cli/v2"

"github.com/ekristen/distillery/pkg/common"
"github.com/ekristen/distillery/pkg/source"
)

func Execute(c *cli.Context) error {
log.SetHandler(clilog.Default)
log.SetLevel(log.DebugLevel)

homeDir, err := os.UserHomeDir()
if err != nil {
return err
Expand All @@ -38,6 +33,10 @@ func Execute(c *cli.Context) error {
_ = os.MkdirAll(metadataDir, 0755)
_ = os.MkdirAll(downloadsDir, 0755)

if c.Args().First() == "ekristen/distillery" {
_ = c.Set("include-pre-releases", "true")
}

src, err := source.New(c.Args().First(), &source.Options{
OS: c.String("os"),
Arch: c.String("arch"),
Expand Down Expand Up @@ -66,6 +65,10 @@ func Execute(c *cli.Context) error {
log.Infof(" os: %s", c.String("os"))
log.Infof(" arch: %s", c.String("arch"))

if c.Bool("include-pre-releases") {
log.Infof("including pre-releases")
}

if err := src.Run(c.Context, c.String("version"), c.String("github-token")); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/common/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"runtime"

"github.com/apex/log"
clilog "github.com/apex/log/handlers/cli"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -41,6 +42,8 @@ func Flags() []cli.Flag {
}

func Before(c *cli.Context) error {
log.SetHandler(clilog.Default)

formatter := &logrus.TextFormatter{
DisableColors: c.Bool("log-disable-color"),
FullTimestamp: c.Bool("log-full-timestamp"),
Expand Down
2 changes: 2 additions & 0 deletions pkg/source/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func (s *GitHub) FindRelease(ctx context.Context) error {
return fmt.Errorf("release not found")
}

log.Infof("installing version: %s", release.GetTagName())

s.Release = release

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *Source) GetArch() string {
}

func (s *Source) Download(ctx context.Context) error {
logrus.Info("download called")
log.Info("downloading assets")
if s.Binary != nil {
if err := s.Binary.Download(ctx); err != nil {
return err
Expand Down

0 comments on commit 4501b09

Please sign in to comment.