Skip to content

Commit

Permalink
feat: moved sign log to info and stream output (#1276)
Browse files Browse the repository at this point in the history
* fix: moved sign log to info

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* feat: stream cmd output

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* chore: fmt

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: log writer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: log

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: wait already closes

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: wait for wg first

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: use lib

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: version

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Dec 27, 2019
1 parent 6edf669 commit 60f4fe7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -7,6 +7,7 @@ require (
github.com/Masterminds/semver/v3 v3.0.3
github.com/apex/log v1.1.1
github.com/aws/aws-sdk-go v1.25.11
github.com/caarlos0/cmdstream v0.1.0
github.com/caarlos0/ctrlc v1.0.0
github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e
github.com/fatih/color v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -44,6 +44,8 @@ github.com/aws/aws-sdk-go v1.25.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb h1:m935MPodAbYS46DG4pJSv7WO+VECIWUQ7OJYSoTrMh4=
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
github.com/caarlos0/cmdstream v0.1.0 h1:Y9EOUEp0e7Lh09vaVXq0psc6gqUYXnLzfD+WAciRW50=
github.com/caarlos0/cmdstream v0.1.0/go.mod h1:JV0/yP9NA7jR+rYk7gDk0K43FxcxaduXpGhYEe8olNc=
github.com/caarlos0/ctrlc v1.0.0 h1:2DtF8GSIcajgffDFJzyG15vO+1PuBWOMUdFut7NnXhw=
github.com/caarlos0/ctrlc v1.0.0/go.mod h1:CdXpj4rmq0q/1Eb44M9zi2nKB0QraNKuRGYGrrHhcQw=
github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e h1:V9a67dfYqPLAvzk5hMQOXYJlZ4SLIXgyKIE+ZiHzgGQ=
Expand Down
18 changes: 18 additions & 0 deletions internal/logext/writer.go
@@ -0,0 +1,18 @@
package logext

import "github.com/apex/log"

// Writer writes with log.Info
type Writer struct {
ctx *log.Entry
}

// NewWriter creates a new log writer
func NewWriter(ctx *log.Entry) Writer {
return Writer{ctx: ctx}
}

func (t Writer) Write(p []byte) (n int, err error) {
t.ctx.Info(string(p))
return len(p), nil
}
14 changes: 14 additions & 0 deletions internal/logext/writer_test.go
@@ -0,0 +1,14 @@
package logext

import (
"testing"

"github.com/apex/log"
"github.com/stretchr/testify/require"
)

func TestWriter(t *testing.T) {
l, err := NewWriter(log.WithField("foo", "bar")).Write([]byte("foo bar"))
require.NoError(t, err)
require.Equal(t, 7, l)
}
12 changes: 8 additions & 4 deletions internal/pipe/sign/sign.go
Expand Up @@ -8,8 +8,11 @@ import (
"reflect"

"github.com/apex/log"
"github.com/caarlos0/cmdstream"

"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/deprecate"
"github.com/goreleaser/goreleaser/internal/logext"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/pkg/config"
Expand Down Expand Up @@ -114,10 +117,11 @@ func signone(ctx *context.Context, cfg config.Sign, a *artifact.Artifact) (*arti
// tells the scanner to ignore this.
// #nosec
cmd := exec.CommandContext(ctx, cfg.Cmd, args...)
log.WithField("cmd", cmd.Args).Debug("running")
output, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("sign: %s failed with %q", cfg.Cmd, string(output))
log.WithField("cmd", cmd.Args).Info("signing")
if err := cmdstream.Stream(
cmd, logext.NewWriter(log.WithField("cmd", cfg.Cmd)),
); err != nil {
return nil, fmt.Errorf("sign: %s failed", cfg.Cmd)
}

artifactPathBase, _ := filepath.Split(a.Path)
Expand Down

0 comments on commit 60f4fe7

Please sign in to comment.