1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

Merge branch 'master' into naked-release

This commit is contained in:
Carlos Alexandro Becker 2017-06-23 19:41:27 -03:00
commit 7a955321c4
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
22 changed files with 100 additions and 260 deletions

20
Gopkg.lock generated
View File

@ -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"]
@ -25,12 +31,24 @@
packages = ["query"]
revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a"
[[projects]]
name = "github.com/goreleaser/archive"
packages = [".","tar","zip"]
revision = "caa5f3f5742eb0535631e94fa5e171c74c0144b7"
version = "v1.0.0"
[[projects]]
branch = "master"
name = "github.com/mattn/go-zglob"
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 +100,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "612a8c73aafb0d235fb9758a889e7a2fee0e0155d4c70cec64d544b62f329cdd"
inputs-digest = "15a60b1efa147cc2507589fd45e4b767e118c6853c6ae2e2728a6ba01b818fe4"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -64,7 +64,9 @@
## what source location any dependent projects specify.
# source = "https://github.com/myfork/package.git"
[[constraint]]
name = "github.com/goreleaser/archive"
version = "1.0.0"
[[constraint]]
branch = "master"

View File

@ -9,7 +9,6 @@
<a href="https://codecov.io/gh/goreleaser/goreleaser"><img alt="Codecov branch" src="https://img.shields.io/codecov/c/github/goreleaser/goreleaser/master.svg?style=flat-square"></a>
<a href="https://goreportcard.com/report/github.com/goreleaser/goreleaser"><img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/goreleaser/goreleaser?style=flat-square"></a>
<a href="http://godoc.org/github.com/goreleaser/goreleaser"><img alt="Go Doc" src="https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square"></a>
<a href="https://beerpay.io/goreleaser/goreleaser"><img src="https://beerpay.io/goreleaser/goreleaser/badge.svg?style=flat-square" /></a>
<a href="https://saythanks.io/to/caarlos0"><img alt="SayThanks.io" src="https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg?style=flat-square"></a>
<a href="https://github.com/goreleaser"><img alt="Powered By: GoReleaser" src="https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square"></a>
</p>
@ -57,7 +56,7 @@ func main() {
}
```
By default GoReleaser will build the your current directory, but you can change the build package path in the GoReleaser configuration file.
By default GoReleaser will build the current directory, but you can change the build package path in the GoReleaser configuration file.
```yml
# goreleaser.yml

View File

@ -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

View File

@ -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) {

View File

@ -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 config")
}
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
}

View File

@ -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))

View File

@ -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.WithField("url", release.GetHTMLURL()).Info("release updated")
return release.GetID(), err
}

View File

@ -1,64 +0,0 @@
// Package tar implements the Archive interface providing tar.gz archiving
// and compression.
package tar
import (
"archive/tar"
"compress/gzip"
"io"
"os"
)
// Archive as tar.gz
type Archive struct {
gw *gzip.Writer
tw *tar.Writer
}
// Close all closeables
func (a Archive) Close() error {
if err := a.tw.Close(); err != nil {
return err
}
if err := a.gw.Close(); err != nil {
return err
}
return nil
}
// New tar.gz archive
func New(target *os.File) Archive {
gw := gzip.NewWriter(target)
tw := tar.NewWriter(gw)
return Archive{
gw: gw,
tw: tw,
}
}
// Add file to the archive
func (a Archive) Add(name, path string) (err error) {
file, err := os.Open(path)
if err != nil {
return
}
defer func() {
_ = file.Close()
}()
stat, err := file.Stat()
if err != nil || stat.IsDir() {
return
}
header := new(tar.Header)
header.Name = name
header.Size = stat.Size()
header.Mode = int64(stat.Mode())
header.ModTime = stat.ModTime()
if err := a.tw.WriteHeader(header); err != nil {
return err
}
if _, err := io.Copy(a.tw, file); err != nil {
return err
}
return
}

View File

@ -1,34 +0,0 @@
package tar
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTarGzFile(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "targztest")
assert.NoError(err)
file, err := os.Create(folder + "/folder.tar.gz")
assert.NoError(err)
empty, err := os.Create(folder + "/empty.txt")
assert.NoError(err)
empty2, err := os.Create(folder + "/empty2.txt")
assert.NoError(err)
assert.NoError(os.Mkdir(folder+"/folder-inside", 0755))
archive := New(file)
assert.NoError(archive.Add("empty.txt", empty.Name()))
assert.Error(archive.Add("dont.txt", empty.Name()+"_nope"))
assert.NoError(archive.Add("empty.txt", folder+"/folder-inside"))
assert.NoError(archive.Close())
assert.Error(archive.Add("empty2.txt", empty2.Name()))
}

View File

@ -1,45 +0,0 @@
// Package zip implements the Archive interface providing zip archiving
// and compression.
package zip
import (
"archive/zip"
"io"
"os"
)
// Archive zip struct
type Archive struct {
z *zip.Writer
}
// Close all closeables
func (a Archive) Close() error {
return a.z.Close()
}
// New zip archive
func New(target *os.File) Archive {
return Archive{
z: zip.NewWriter(target),
}
}
// Add a file to the zip archive
func (a Archive) Add(name, path string) (err error) {
file, err := os.Open(path)
if err != nil {
return
}
stat, err := file.Stat()
if err != nil || stat.IsDir() {
return
}
defer func() { _ = file.Close() }()
f, err := a.z.Create(name)
if err != nil {
return err
}
_, err = io.Copy(f, file)
return err
}

View File

@ -1,30 +0,0 @@
package zip
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestZipFile(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "ziptest")
assert.NoError(err)
file, err := os.Create(folder + "/folder.zip")
assert.NoError(err)
empty, err := os.Create(folder + "/empty.txt")
assert.NoError(err)
assert.NoError(os.Mkdir(folder+"/folder-inside", 0755))
archive := New(file)
assert.NoError(archive.Add("empty.txt", empty.Name()))
assert.NoError(archive.Add("empty.txt", folder+"/folder-inside"))
assert.Error(archive.Add("dont.txt", empty.Name()+"_nope"))
assert.NoError(archive.Close())
}

18
main.go
View File

@ -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,13 @@ func main() {
return cli.NewExitError(err.Error(), 1)
}
log.Printf("%s created. Please edit accordingly to your needs.", filename)
log.WithField("file", filename).
Info("config create, please edit accordingly to your needs")
return nil
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatalln(err)
log.WithError(err).Fatal("failed")
}
}

View File

@ -4,15 +4,14 @@
package archive
import (
"log"
"os"
"path/filepath"
"strings"
"github.com/apex/log"
"github.com/goreleaser/archive"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/ext"
"github.com/goreleaser/goreleaser/internal/tar"
"github.com/goreleaser/goreleaser/internal/zip"
"github.com/mattn/go-zglob"
"golang.org/x/sync/errgroup"
)
@ -41,12 +40,6 @@ func (Pipe) Run(ctx *context.Context) error {
return g.Wait()
}
// Archive represents a compression archive files from disk can be written to.
type Archive interface {
Close() error
Add(name, path string) error
}
func create(ctx *context.Context, platform, name string) error {
var folder = filepath.Join(ctx.Config.Dist, name)
var format = formatFor(ctx, platform)
@ -54,9 +47,9 @@ 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)
var archive = archive.New(file)
defer func() { _ = archive.Close() }()
files, err := findFiles(ctx)
@ -95,13 +88,6 @@ func findFiles(ctx *context.Context) (result []string, err error) {
return
}
func archiveFor(file *os.File, format string) Archive {
if format == "zip" {
return zip.New(file)
}
return tar.New(file)
}
func formatFor(ctx *context.Context, platform string) string {
for _, override := range ctx.Config.Archive.FormatOverrides {
if strings.HasPrefix(platform, override.Goos) {

View File

@ -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,15 +95,15 @@ 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
}
if ctx.Config.Archive.Format == "binary" {
@ -111,7 +111,9 @@ func doRun(ctx *context.Context, client client.Client) error {
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

View File

@ -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)
}
@ -84,15 +84,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))
}

View File

@ -2,9 +2,9 @@ package build
import (
"fmt"
"log"
"runtime"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context"
)
@ -26,11 +26,13 @@ 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)

View File

@ -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
View File

@ -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 == "" {

View File

@ -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
}
if ctx.Config.Archive.Format == "binary" {
@ -44,6 +44,7 @@ func (Pipe) Run(ctx *context.Context) error {
var g errgroup.Group
for _, format := range ctx.Config.FPM.Formats {
format := format
for _, goarch := range ctx.Config.Build.Goarch {
if ctx.Archives["linux"+goarch] == "" {
continue
@ -62,7 +63,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",

View File

@ -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

View File

@ -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.Name()).Info("uploading")
return client.Upload(ctx, releaseID, artifact, file)
}