mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-13 13:48:40 +02:00
Merge pull request #264 from goreleaser/log
Added debug and improved logs
This commit is contained in:
commit
beb62646c3
14
Gopkg.lock
generated
14
Gopkg.lock
generated
@ -1,6 +1,12 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/apex/log"
|
||||
packages = [".","handlers/cli"]
|
||||
revision = "8f3a15d95392c8fc202d1e1059f46df21dff2992"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
@ -31,6 +37,12 @@
|
||||
packages = [".","fastwalk"]
|
||||
revision = "95345c4e1c0ebc9d16a3284177f09360f4d20fab"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pkg/errors"
|
||||
packages = ["."]
|
||||
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
|
||||
version = "v0.8.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pmezard/go-difflib"
|
||||
packages = ["difflib"]
|
||||
@ -82,6 +94,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "612a8c73aafb0d235fb9758a889e7a2fee0e0155d4c70cec64d544b62f329cdd"
|
||||
inputs-digest = "d6da23d2c5d62fbc0e9d6effeeea88169d4c5add4eb620087f17af4853a41cc4"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
@ -8,10 +8,10 @@ package context
|
||||
|
||||
import (
|
||||
ctx "context"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
)
|
||||
|
||||
@ -45,7 +45,7 @@ func (ctx *Context) AddArtifact(file string) {
|
||||
file = strings.TrimPrefix(file, ctx.Config.Dist)
|
||||
file = strings.Replace(file, "/", "", -1)
|
||||
ctx.Artifacts = append(ctx.Artifacts, file)
|
||||
log.Println("Registered artifact", file)
|
||||
log.WithField("artifact", file).Info("Registered")
|
||||
}
|
||||
|
||||
// New context
|
||||
|
@ -3,10 +3,9 @@ package context
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func TestMultipleArtifactAdds(t *testing.T) {
|
||||
|
@ -1,14 +1,12 @@
|
||||
package goreleaserlib
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
yaml "gopkg.in/yaml.v1"
|
||||
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
@ -21,6 +19,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/pipeline/fpm"
|
||||
"github.com/goreleaser/goreleaser/pipeline/git"
|
||||
"github.com/goreleaser/goreleaser/pipeline/release"
|
||||
yaml "gopkg.in/yaml.v1"
|
||||
)
|
||||
|
||||
var pipes = []pipeline.Pipe{
|
||||
@ -35,10 +34,6 @@ var pipes = []pipeline.Pipe{
|
||||
brew.Pipe{}, // push to brew tap
|
||||
}
|
||||
|
||||
func init() {
|
||||
log.SetFlags(0)
|
||||
}
|
||||
|
||||
// Flags interface represents an extractor of cli flags
|
||||
type Flags interface {
|
||||
IsSet(s string) bool
|
||||
@ -50,6 +45,9 @@ type Flags interface {
|
||||
func Release(flags Flags) error {
|
||||
var file = flags.String("config")
|
||||
var notes = flags.String("release-notes")
|
||||
if flags.Bool("debug") {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
cfg, err := config.Load(file)
|
||||
if err != nil {
|
||||
// Allow file not found errors if config file was not
|
||||
@ -58,7 +56,7 @@ func Release(flags Flags) error {
|
||||
if !os.IsNotExist(statErr) || flags.IsSet("config") {
|
||||
return err
|
||||
}
|
||||
log.Printf("WARNING: Could not load %v\n", file)
|
||||
log.WithField("file", file).Warn("Could not load")
|
||||
}
|
||||
var ctx = context.New(cfg)
|
||||
ctx.Validate = !flags.Bool("skip-validate")
|
||||
@ -68,23 +66,21 @@ func Release(flags Flags) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("Loaded custom release notes from", notes)
|
||||
log.WithField("notes", notes).Info("Loaded custom release notes")
|
||||
ctx.ReleaseNotes = string(bts)
|
||||
}
|
||||
ctx.Snapshot = flags.Bool("snapshot")
|
||||
if ctx.Snapshot {
|
||||
log.Println("Publishing disabled in snapshot mode")
|
||||
log.Info("Publishing disabled in snapshot mode")
|
||||
ctx.Publish = false
|
||||
}
|
||||
for _, pipe := range pipes {
|
||||
log.Println(pipe.Description())
|
||||
log.SetPrefix(" -> ")
|
||||
log.Infof("\033[1m%s\033[0m", strings.ToUpper(pipe.Description()))
|
||||
if err := pipe.Run(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
log.SetPrefix("")
|
||||
}
|
||||
log.Println("Done!")
|
||||
log.Infof("\033[1mSUCCESS!\033[0m")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2,16 +2,14 @@ package goreleaserlib
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
yaml "gopkg.in/yaml.v1"
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
yaml "gopkg.in/yaml.v1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -26,6 +24,7 @@ func TestRelease(t *testing.T) {
|
||||
flags: map[string]string{
|
||||
"skip-publish": "true",
|
||||
"skip-validate": "true",
|
||||
"debug": "true",
|
||||
},
|
||||
}
|
||||
assert.NoError(Release(flags))
|
||||
@ -146,7 +145,6 @@ func setup(t *testing.T) (current string, back func()) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "goreleaser")
|
||||
assert.NoError(err)
|
||||
log.Println("Folder:", folder)
|
||||
previous, err := os.Getwd()
|
||||
assert.NoError(err)
|
||||
assert.NoError(os.Chdir(folder))
|
||||
|
@ -2,9 +2,9 @@ package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"golang.org/x/oauth2"
|
||||
@ -98,7 +98,7 @@ func (c *githubClient) CreateRelease(ctx *context.Context, body string) (release
|
||||
data,
|
||||
)
|
||||
}
|
||||
log.Printf("Release updated: %v\n", release.GetHTMLURL())
|
||||
log.Infof("Release updated: %v\n", release.GetHTMLURL())
|
||||
return release.GetID(), err
|
||||
}
|
||||
|
||||
|
17
main.go
17
main.go
@ -2,9 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/apex/log"
|
||||
lcli "github.com/apex/log/handlers/cli"
|
||||
"github.com/goreleaser/goreleaser/goreleaserlib"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -15,6 +16,10 @@ var (
|
||||
date = "unknown"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetHandler(lcli.New(os.Stdout))
|
||||
}
|
||||
|
||||
func main() {
|
||||
var app = cli.NewApp()
|
||||
app.Name = "goreleaser"
|
||||
@ -42,9 +47,13 @@ func main() {
|
||||
Name: "snapshot",
|
||||
Usage: "Generate an unversioned snapshot release",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "Enable debug mode",
|
||||
},
|
||||
}
|
||||
app.Action = func(c *cli.Context) error {
|
||||
log.Printf("Running goreleaser %v\n", version)
|
||||
log.Infof("Running goreleaser %v", version)
|
||||
if err := goreleaserlib.Release(c); err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
@ -61,12 +70,12 @@ func main() {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
|
||||
log.Printf("%s created. Please edit accordingly to your needs.", filename)
|
||||
log.Infof("%s created. Please edit accordingly to your needs.", filename)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatalln(err)
|
||||
log.WithError(err).Fatal("Failed")
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/ext"
|
||||
"github.com/goreleaser/goreleaser/internal/tar"
|
||||
@ -51,7 +51,7 @@ func create(ctx *context.Context, platform, name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("Creating", file.Name())
|
||||
log.WithField("archive", file.Name()).Info("Creating")
|
||||
defer func() { _ = file.Close() }()
|
||||
var archive = archiveFor(file, format)
|
||||
defer func() { _ = archive.Close() }()
|
||||
|
@ -5,11 +5,11 @@ package brew
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/checksum"
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
@ -95,19 +95,19 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
|
||||
func doRun(ctx *context.Context, client client.Client) error {
|
||||
if !ctx.Publish {
|
||||
log.Println("Skipped because --skip-publish is set")
|
||||
log.Warn("Skipped because --skip-publish is set")
|
||||
return nil
|
||||
}
|
||||
if ctx.Config.Brew.GitHub.Name == "" {
|
||||
log.Println("Skipped because brew section is not configured")
|
||||
log.Warn("Skipped because brew section is not configured")
|
||||
return nil
|
||||
}
|
||||
if ctx.Config.Release.Draft {
|
||||
log.Println("Skipped because release is marked as draft")
|
||||
log.Warn("Skipped because release is marked as draft")
|
||||
return nil
|
||||
}
|
||||
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb")
|
||||
log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String())
|
||||
log.WithField("formula", path).WithField("repo", ctx.Config.Brew.GitHub.String()).Info("Pushing")
|
||||
content, err := buildFormula(ctx, client)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -4,12 +4,12 @@ package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/ext"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -56,7 +56,7 @@ func runHook(env []string, hook string) error {
|
||||
if hook == "" {
|
||||
return nil
|
||||
}
|
||||
log.Println("Running hook", hook)
|
||||
log.WithField("hook", hook).Info("Running hook")
|
||||
cmd := strings.Fields(hook)
|
||||
return run(runtimeTarget, cmd, env)
|
||||
}
|
||||
@ -67,7 +67,7 @@ func build(ctx *context.Context, name string, target buildTarget) error {
|
||||
name,
|
||||
ctx.Config.Build.Binary+ext.For(target.goos),
|
||||
)
|
||||
log.Println("Building", output)
|
||||
log.WithField("binary", output).Info("Building")
|
||||
cmd := []string{"go", "build"}
|
||||
if ctx.Config.Build.Flags != "" {
|
||||
cmd = append(cmd, strings.Fields(ctx.Config.Build.Flags)...)
|
||||
@ -81,15 +81,14 @@ func build(ctx *context.Context, name string, target buildTarget) error {
|
||||
}
|
||||
|
||||
func run(target buildTarget, command, env []string) error {
|
||||
cmd := exec.Command(command[0], command[1:]...)
|
||||
var cmd = exec.Command(command[0], command[1:]...)
|
||||
env = append(env, "GOOS="+target.goos, "GOARCH="+target.goarch, "GOARM="+target.goarm)
|
||||
cmd.Env = append(cmd.Env, os.Environ()...)
|
||||
cmd.Env = append(cmd.Env, env...)
|
||||
cmd.Env = append(
|
||||
cmd.Env,
|
||||
"GOOS="+target.goos,
|
||||
"GOARCH="+target.goarch,
|
||||
"GOARM="+target.goarm,
|
||||
)
|
||||
log.WithField("target", target.PrettyString()).
|
||||
WithField("env", env).
|
||||
WithField("args", cmd.Args).
|
||||
Debug("Running")
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("build failed: %s\n%v", target.PrettyString(), string(out))
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
)
|
||||
|
||||
@ -26,11 +26,11 @@ func (t buildTarget) PrettyString() string {
|
||||
func buildTargets(ctx *context.Context) (targets []buildTarget) {
|
||||
for _, target := range allBuildTargets(ctx) {
|
||||
if !valid(target) {
|
||||
log.Println("Skipped invalid build target:", target.PrettyString())
|
||||
log.WithField("target", target.PrettyString()).Warn("Skipped invalid build")
|
||||
continue
|
||||
}
|
||||
if ignored(ctx, target) {
|
||||
log.Println("Skipped ignored build target:", target.PrettyString())
|
||||
log.WithField("target", target.PrettyString()).Warn("Skipped ignored build")
|
||||
continue
|
||||
}
|
||||
targets = append(targets, target)
|
||||
|
@ -4,10 +4,10 @@ package checksums
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/checksum"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -49,7 +49,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
}
|
||||
|
||||
func checksums(ctx *context.Context, file *os.File, name string) error {
|
||||
log.Println("Checksumming", name)
|
||||
log.WithField("file", name).Info("Checksumming")
|
||||
var artifact = filepath.Join(ctx.Config.Dist, name)
|
||||
sha, err := checksum.SHA256(artifact)
|
||||
if err != nil {
|
||||
|
6
pipeline/env/env.go
vendored
6
pipeline/env/env.go
vendored
@ -4,9 +4,9 @@ package env
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
)
|
||||
|
||||
@ -25,11 +25,11 @@ func (Pipe) Description() string {
|
||||
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
ctx.Token = os.Getenv("GITHUB_TOKEN")
|
||||
if !ctx.Publish {
|
||||
log.Println("GITHUB_TOKEN not validated because publishing has been disabled")
|
||||
log.Warn("GITHUB_TOKEN not validated because publishing has been disabled")
|
||||
return nil
|
||||
}
|
||||
if !ctx.Validate {
|
||||
log.Println("Skipped validations because --skip-validate is set")
|
||||
log.Warn("Skipped validations because --skip-validate is set")
|
||||
return nil
|
||||
}
|
||||
if ctx.Token == "" {
|
||||
|
@ -3,10 +3,10 @@ package fpm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
@ -30,7 +30,7 @@ func (Pipe) Description() string {
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) error {
|
||||
if len(ctx.Config.FPM.Formats) == 0 {
|
||||
log.Println("No output formats configured, skipping")
|
||||
log.Info("No output formats configured, skipping")
|
||||
return nil
|
||||
}
|
||||
_, err := exec.LookPath("fpm")
|
||||
@ -59,7 +59,7 @@ func create(ctx *context.Context, format, archive, arch string) error {
|
||||
var path = filepath.Join(ctx.Config.Dist, archive)
|
||||
var file = path + "." + format
|
||||
var name = ctx.Config.Build.Binary
|
||||
log.Println("Creating", file)
|
||||
log.WithField("file", file).Info("Creating")
|
||||
|
||||
var options = []string{
|
||||
"--input-type", "dir",
|
||||
|
@ -5,13 +5,12 @@ package git
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"text/template"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
)
|
||||
|
||||
@ -74,7 +73,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
if !ctx.Validate {
|
||||
log.Println("Skipped validations because --skip-validate is set")
|
||||
log.Warn("Skipped validations because --skip-validate is set")
|
||||
return nil
|
||||
}
|
||||
return validate(ctx, commit, tag)
|
||||
@ -170,7 +169,7 @@ func gitLog(refs ...string) (string, error) {
|
||||
func getInfo() (tag, commit string, err error) {
|
||||
tag, err = cleanGit("describe", "--tags", "--abbrev=0")
|
||||
if err != nil {
|
||||
log.Printf("Failed to retrieve current tag: %s", err.Error())
|
||||
log.WithError(err).Info("Failed to retrieve current tag")
|
||||
}
|
||||
commit, err = cleanGit("show", "--format='%H'", "HEAD")
|
||||
return
|
||||
|
@ -3,10 +3,10 @@
|
||||
package release
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/client"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -27,10 +27,12 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
|
||||
func doRun(ctx *context.Context, client client.Client) error {
|
||||
if !ctx.Publish {
|
||||
log.Println("Skipped because --skip-publish is set")
|
||||
log.Warn("Skipped because --skip-publish is set")
|
||||
return nil
|
||||
}
|
||||
log.Println("Creating or updating release", ctx.Git.CurrentTag, "on", ctx.Config.Release.GitHub.String())
|
||||
log.WithField("tag", ctx.Git.CurrentTag).
|
||||
WithField("repo", ctx.Config.Release.GitHub.String()).
|
||||
Info("Creating or updating release")
|
||||
body, err := describeBody(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -56,6 +58,6 @@ func upload(ctx *context.Context, client client.Client, releaseID int, artifact
|
||||
return err
|
||||
}
|
||||
defer func() { _ = file.Close() }()
|
||||
log.Println("Uploading", file.Name())
|
||||
log.WithField("file", file).Info("Uploading")
|
||||
return client.Upload(ctx, releaseID, artifact, file)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user