1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-15 01:34:21 +02:00
This commit is contained in:
Carlos Alexandro Becker
2017-06-22 00:09:14 -03:00
parent c80fc0714d
commit 1e9e82d926
15 changed files with 54 additions and 60 deletions

View File

@ -8,10 +8,10 @@ package context
import ( import (
ctx "context" ctx "context"
"log"
"strings" "strings"
"sync" "sync"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
) )
@ -45,7 +45,7 @@ func (ctx *Context) AddArtifact(file string) {
file = strings.TrimPrefix(file, ctx.Config.Dist) file = strings.TrimPrefix(file, ctx.Config.Dist)
file = strings.Replace(file, "/", "", -1) file = strings.Replace(file, "/", "", -1)
ctx.Artifacts = append(ctx.Artifacts, file) ctx.Artifacts = append(ctx.Artifacts, file)
log.Println("Registered artifact", file) log.WithField("artifact", file).Info("Registered")
} }
// New context // New context

View File

@ -3,10 +3,9 @@ package context
import ( import (
"testing" "testing"
"golang.org/x/sync/errgroup"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"golang.org/x/sync/errgroup"
) )
func TestMultipleArtifactAdds(t *testing.T) { func TestMultipleArtifactAdds(t *testing.T) {

View File

@ -1,14 +1,11 @@
package goreleaserlib package goreleaserlib
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
yaml "gopkg.in/yaml.v1" "github.com/apex/log"
"fmt"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline" "github.com/goreleaser/goreleaser/pipeline"
@ -21,6 +18,7 @@ import (
"github.com/goreleaser/goreleaser/pipeline/fpm" "github.com/goreleaser/goreleaser/pipeline/fpm"
"github.com/goreleaser/goreleaser/pipeline/git" "github.com/goreleaser/goreleaser/pipeline/git"
"github.com/goreleaser/goreleaser/pipeline/release" "github.com/goreleaser/goreleaser/pipeline/release"
yaml "gopkg.in/yaml.v1"
) )
var pipes = []pipeline.Pipe{ var pipes = []pipeline.Pipe{
@ -35,10 +33,6 @@ var pipes = []pipeline.Pipe{
brew.Pipe{}, // push to brew tap brew.Pipe{}, // push to brew tap
} }
func init() {
log.SetFlags(0)
}
// Flags interface represents an extractor of cli flags // Flags interface represents an extractor of cli flags
type Flags interface { type Flags interface {
IsSet(s string) bool IsSet(s string) bool
@ -58,7 +52,7 @@ func Release(flags Flags) error {
if !os.IsNotExist(statErr) || flags.IsSet("config") { if !os.IsNotExist(statErr) || flags.IsSet("config") {
return err return err
} }
log.Printf("WARNING: Could not load %v\n", file) log.WithField("file", file).Warn("Could not load")
} }
var ctx = context.New(cfg) var ctx = context.New(cfg)
ctx.Validate = !flags.Bool("skip-validate") ctx.Validate = !flags.Bool("skip-validate")
@ -68,23 +62,21 @@ func Release(flags Flags) error {
if err != nil { if err != nil {
return err return err
} }
log.Println("Loaded custom release notes from", notes) log.WithField("notes", notes).Info("Loaded custom release notes")
ctx.ReleaseNotes = string(bts) ctx.ReleaseNotes = string(bts)
} }
ctx.Snapshot = flags.Bool("snapshot") ctx.Snapshot = flags.Bool("snapshot")
if ctx.Snapshot { if ctx.Snapshot {
log.Println("Publishing disabled in snapshot mode") log.Info("Publishing disabled in snapshot mode")
ctx.Publish = false ctx.Publish = false
} }
for _, pipe := range pipes { for _, pipe := range pipes {
log.Println(pipe.Description()) log.Infof(pipe.Description())
log.SetPrefix(" -> ")
if err := pipe.Run(ctx); err != nil { if err := pipe.Run(ctx); err != nil {
return err return err
} }
log.SetPrefix("")
} }
log.Println("Done!") log.Info("Done!")
return nil return nil
} }

View File

@ -2,16 +2,14 @@ package goreleaserlib
import ( import (
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"testing" "testing"
yaml "gopkg.in/yaml.v1"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
yaml "gopkg.in/yaml.v1"
) )
func init() { func init() {
@ -146,7 +144,6 @@ func setup(t *testing.T) (current string, back func()) {
var assert = assert.New(t) var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleaser") folder, err := ioutil.TempDir("", "goreleaser")
assert.NoError(err) assert.NoError(err)
log.Println("Folder:", folder)
previous, err := os.Getwd() previous, err := os.Getwd()
assert.NoError(err) assert.NoError(err)
assert.NoError(os.Chdir(folder)) assert.NoError(os.Chdir(folder))

View File

@ -2,9 +2,9 @@ package client
import ( import (
"bytes" "bytes"
"log"
"os" "os"
"github.com/apex/log"
"github.com/google/go-github/github" "github.com/google/go-github/github"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
@ -98,7 +98,7 @@ func (c *githubClient) CreateRelease(ctx *context.Context, body string) (release
data, data,
) )
} }
log.Printf("Release updated: %v\n", release.GetHTMLURL()) log.Infof("Release updated: %v\n", release.GetHTMLURL())
return release.GetID(), err return release.GetID(), err
} }

13
main.go
View File

@ -2,9 +2,10 @@ package main
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"github.com/apex/log"
lcli "github.com/apex/log/handlers/cli"
"github.com/goreleaser/goreleaser/goreleaserlib" "github.com/goreleaser/goreleaser/goreleaserlib"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -15,6 +16,10 @@ var (
date = "unknown" date = "unknown"
) )
func init() {
log.SetHandler(lcli.New(os.Stdout))
}
func main() { func main() {
var app = cli.NewApp() var app = cli.NewApp()
app.Name = "goreleaser" app.Name = "goreleaser"
@ -44,7 +49,7 @@ func main() {
}, },
} }
app.Action = func(c *cli.Context) error { 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 { if err := goreleaserlib.Release(c); err != nil {
return cli.NewExitError(err.Error(), 1) return cli.NewExitError(err.Error(), 1)
} }
@ -61,12 +66,12 @@ func main() {
return cli.NewExitError(err.Error(), 1) 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 return nil
}, },
}, },
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
log.Fatalln(err) log.WithError(err).Fatal("Failed")
} }
} }

View File

@ -4,11 +4,11 @@
package archive package archive
import ( import (
"log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/ext" "github.com/goreleaser/goreleaser/internal/ext"
"github.com/goreleaser/goreleaser/internal/tar" "github.com/goreleaser/goreleaser/internal/tar"
@ -51,7 +51,7 @@ func create(ctx *context.Context, platform, name string) error {
if err != nil { if err != nil {
return err return err
} }
log.Println("Creating", file.Name()) log.WithField("archive", file.Name()).Info("Creating")
defer func() { _ = file.Close() }() defer func() { _ = file.Close() }()
var archive = archiveFor(file, format) var archive = archiveFor(file, format)
defer func() { _ = archive.Close() }() defer func() { _ = archive.Close() }()

View File

@ -5,11 +5,11 @@ package brew
import ( import (
"bytes" "bytes"
"errors" "errors"
"log"
"path/filepath" "path/filepath"
"strings" "strings"
"text/template" "text/template"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/checksum" "github.com/goreleaser/goreleaser/checksum"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "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 { func doRun(ctx *context.Context, client client.Client) error {
if !ctx.Publish { if !ctx.Publish {
log.Println("Skipped because --skip-publish is set") log.Info("Skipped because --skip-publish is set")
return nil return nil
} }
if ctx.Config.Brew.GitHub.Name == "" { if ctx.Config.Brew.GitHub.Name == "" {
log.Println("Skipped because brew section is not configured") log.Info("Skipped because brew section is not configured")
return nil return nil
} }
if ctx.Config.Release.Draft { if ctx.Config.Release.Draft {
log.Println("Skipped because release is marked as draft") log.Info("Skipped because release is marked as draft")
return nil return nil
} }
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb") 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) content, err := buildFormula(ctx, client)
if err != nil { if err != nil {
return err return err

View File

@ -4,12 +4,12 @@ package build
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/ext" "github.com/goreleaser/goreleaser/internal/ext"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -56,7 +56,7 @@ func runHook(env []string, hook string) error {
if hook == "" { if hook == "" {
return nil return nil
} }
log.Println("Running hook", hook) log.WithField("hook", hook).Info("Running hook")
cmd := strings.Fields(hook) cmd := strings.Fields(hook)
return run(runtimeTarget, cmd, env) return run(runtimeTarget, cmd, env)
} }
@ -67,7 +67,7 @@ func build(ctx *context.Context, name string, target buildTarget) error {
name, name,
ctx.Config.Build.Binary+ext.For(target.goos), ctx.Config.Build.Binary+ext.For(target.goos),
) )
log.Println("Building", output) log.WithField("binary", output).Info("Building")
cmd := []string{"go", "build"} cmd := []string{"go", "build"}
if ctx.Config.Build.Flags != "" { if ctx.Config.Build.Flags != "" {
cmd = append(cmd, strings.Fields(ctx.Config.Build.Flags)...) cmd = append(cmd, strings.Fields(ctx.Config.Build.Flags)...)

View File

@ -2,9 +2,9 @@ package build
import ( import (
"fmt" "fmt"
"log"
"runtime" "runtime"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
) )
@ -26,11 +26,11 @@ func (t buildTarget) PrettyString() string {
func buildTargets(ctx *context.Context) (targets []buildTarget) { func buildTargets(ctx *context.Context) (targets []buildTarget) {
for _, target := range allBuildTargets(ctx) { for _, target := range allBuildTargets(ctx) {
if !valid(target) { if !valid(target) {
log.Println("Skipped invalid build target:", target.PrettyString()) log.WithField("target", target.PrettyString()).Info("Skipped invalid build")
continue continue
} }
if ignored(ctx, target) { if ignored(ctx, target) {
log.Println("Skipped ignored build target:", target.PrettyString()) log.WithField("target", target.PrettyString()).Info("Skipped ignored build")
continue continue
} }
targets = append(targets, target) targets = append(targets, target)

View File

@ -4,10 +4,10 @@ package checksums
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/checksum" "github.com/goreleaser/goreleaser/checksum"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"golang.org/x/sync/errgroup" "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 { 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) var artifact = filepath.Join(ctx.Config.Dist, name)
sha, err := checksum.SHA256(artifact) sha, err := checksum.SHA256(artifact)
if err != nil { if err != nil {

6
pipeline/env/env.go vendored
View File

@ -4,9 +4,9 @@ package env
import ( import (
"errors" "errors"
"log"
"os" "os"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
) )
@ -25,11 +25,11 @@ func (Pipe) Description() string {
func (Pipe) Run(ctx *context.Context) (err error) { func (Pipe) Run(ctx *context.Context) (err error) {
ctx.Token = os.Getenv("GITHUB_TOKEN") ctx.Token = os.Getenv("GITHUB_TOKEN")
if !ctx.Publish { 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 return nil
} }
if !ctx.Validate { if !ctx.Validate {
log.Println("Skipped validations because --skip-validate is set") log.Warn("Skipped validations because --skip-validate is set")
return nil return nil
} }
if ctx.Token == "" { if ctx.Token == "" {

View File

@ -3,10 +3,10 @@ package fpm
import ( import (
"errors" "errors"
"log"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
@ -30,7 +30,7 @@ func (Pipe) Description() string {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if len(ctx.Config.FPM.Formats) == 0 { if len(ctx.Config.FPM.Formats) == 0 {
log.Println("No output formats configured, skipping") log.Info("No output formats configured, skipping")
return nil return nil
} }
_, err := exec.LookPath("fpm") _, 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 path = filepath.Join(ctx.Config.Dist, archive)
var file = path + "." + format var file = path + "." + format
var name = ctx.Config.Build.Binary var name = ctx.Config.Build.Binary
log.Println("Creating", file) log.WithField("file", file).Info("Creating")
var options = []string{ var options = []string{
"--input-type", "dir", "--input-type", "dir",

View File

@ -5,13 +5,12 @@ package git
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log"
"regexp" "regexp"
"strings" "strings"
"text/template"
"time" "time"
"text/template" "github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
) )
@ -74,7 +73,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
return return
} }
if !ctx.Validate { if !ctx.Validate {
log.Println("Skipped validations because --skip-validate is set") log.Warn("Skipped validations because --skip-validate is set")
return nil return nil
} }
return validate(ctx, commit, tag) return validate(ctx, commit, tag)
@ -170,7 +169,7 @@ func gitLog(refs ...string) (string, error) {
func getInfo() (tag, commit string, err error) { func getInfo() (tag, commit string, err error) {
tag, err = cleanGit("describe", "--tags", "--abbrev=0") tag, err = cleanGit("describe", "--tags", "--abbrev=0")
if err != nil { 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") commit, err = cleanGit("show", "--format='%H'", "HEAD")
return return

View File

@ -3,10 +3,10 @@
package release package release
import ( import (
"log"
"os" "os"
"path/filepath" "path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/client" "github.com/goreleaser/goreleaser/internal/client"
"golang.org/x/sync/errgroup" "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 { func doRun(ctx *context.Context, client client.Client) error {
if !ctx.Publish { if !ctx.Publish {
log.Println("Skipped because --skip-publish is set") log.Info("Skipped because --skip-publish is set")
return nil 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) body, err := describeBody(ctx)
if err != nil { if err != nil {
return err return err
@ -56,6 +58,6 @@ func upload(ctx *context.Context, client client.Client, releaseID int, artifact
return err return err
} }
defer func() { _ = file.Close() }() defer func() { _ = file.Close() }()
log.Println("Uploading", file.Name()) log.WithField("file", file).Info("Uploading")
return client.Upload(ctx, releaseID, artifact, file) return client.Upload(ctx, releaseID, artifact, file)
} }