1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

Merge branch 'master' into artifactory-support

* master:
  fix: lint warnings
  test: fixed tests
  test: added tests to effective config pipe
  feat: write actual config to dist
This commit is contained in:
Andy Grunwald 2017-12-10 16:55:55 +01:00
commit 5358724f0b
7 changed files with 103 additions and 27 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
dist/
!pipeline/dist
vendor
coverage.txt
goreleaser

View File

@ -17,9 +17,10 @@ import (
"github.com/goreleaser/goreleaser/pipeline/build"
"github.com/goreleaser/goreleaser/pipeline/changelog"
"github.com/goreleaser/goreleaser/pipeline/checksums"
"github.com/goreleaser/goreleaser/pipeline/cleandist"
"github.com/goreleaser/goreleaser/pipeline/defaults"
"github.com/goreleaser/goreleaser/pipeline/dist"
"github.com/goreleaser/goreleaser/pipeline/docker"
"github.com/goreleaser/goreleaser/pipeline/effectiveconfig"
"github.com/goreleaser/goreleaser/pipeline/env"
"github.com/goreleaser/goreleaser/pipeline/fpm"
"github.com/goreleaser/goreleaser/pipeline/git"
@ -38,20 +39,21 @@ func init() {
}
var pipes = []pipeline.Piper{
defaults.Pipe{}, // load default configs
git.Pipe{}, // get and validate git repo state
changelog.Pipe{}, // builds the release changelog
env.Pipe{}, // load and validate environment variables
cleandist.Pipe{}, // ensure ./dist is clean
build.Pipe{}, // build
archive.Pipe{}, // archive (tar.gz, zip, etc)
fpm.Pipe{}, // archive via fpm (deb, rpm, etc)
snapcraft.Pipe{}, // archive via snapcraft (snap)
checksums.Pipe{}, // checksums of the files
docker.Pipe{}, // create and push docker images
artifactory.Pipe{}, // push to artifactory
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
defaults.Pipe{}, // load default configs
dist.Pipe{}, // ensure ./dist is clean
git.Pipe{}, // get and validate git repo state
effectiveconfig.Pipe{}, // writes the actual config (with defaults et al set) to dist
changelog.Pipe{}, // builds the release changelog
env.Pipe{}, // load and validate environment variables
build.Pipe{}, // build
archive.Pipe{}, // archive (tar.gz, zip, etc)
fpm.Pipe{}, // archive via fpm (deb, rpm, etc)
snapcraft.Pipe{}, // archive via snapcraft (snap)
checksums.Pipe{}, // checksums of the files
docker.Pipe{}, // create and push docker images
artifactory.Pipe{}, // push to artifactory
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
}
// Flags interface represents an extractor of cli flags

View File

@ -17,7 +17,7 @@ import (
"github.com/goreleaser/goreleaser/pipeline/snapshot"
)
// Pipe for brew deployment
// Pipe that sets the defaults
type Pipe struct{}
func (Pipe) String() string {
@ -50,6 +50,5 @@ func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.ProjectName == "" {
ctx.Config.ProjectName = ctx.Config.Release.GitHub.Name
}
log.WithField("config", ctx.Config).Debug("defaults set")
return nil
}

View File

@ -1,6 +1,6 @@
// Package cleandist provides checks to make sure the dist folder is always
// Package dist provides checks to make sure the dist folder is always
// empty.
package cleandist
package dist
import (
"fmt"
@ -22,12 +22,16 @@ func (Pipe) String() string {
func (Pipe) Run(ctx *context.Context) (err error) {
_, err = os.Stat(ctx.Config.Dist)
if os.IsNotExist(err) {
log.Debug("./dist doesn't exist, moving on")
return nil
log.Debug("./dist doesn't exist, creating empty folder")
return mkdir(ctx)
}
if ctx.RmDist {
log.Info("--rm-dist is set, removing ./dist")
return os.RemoveAll(ctx.Config.Dist)
log.Info("--rm-dist is set, cleaning it up")
err = os.RemoveAll(ctx.Config.Dist)
if err == nil {
err = mkdir(ctx)
}
return err
}
files, err := ioutil.ReadDir(ctx.Config.Dist)
if err != nil {
@ -41,5 +45,10 @@ func (Pipe) Run(ctx *context.Context) (err error) {
)
}
log.Debug("./dist is empty")
return
return mkdir(ctx)
}
func mkdir(ctx *context.Context) error {
// #nosec
return os.MkdirAll(ctx.Config.Dist, 0755)
}

View File

@ -1,4 +1,4 @@
package cleandist
package dist
import (
"io/ioutil"
@ -12,12 +12,15 @@ import (
)
func TestDistDoesNotExist(t *testing.T) {
folder, err := ioutil.TempDir("", "disttest")
assert.NoError(t, err)
var dist = filepath.Join(folder, "dist")
assert.NoError(
t,
Pipe{}.Run(
&context.Context{
Config: config.Project{
Dist: "/wtf-this-shouldnt-exist",
Dist: dist,
},
},
),
@ -55,7 +58,7 @@ func TestEmptyDistExists(t *testing.T) {
}
assert.NoError(t, Pipe{}.Run(ctx))
_, err = os.Stat(dist)
assert.False(t, os.IsExist(err))
assert.False(t, os.IsNotExist(err))
}
func TestDescription(t *testing.T) {

View File

@ -0,0 +1,29 @@
package effectiveconfig
import (
"io/ioutil"
"path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context"
yaml "gopkg.in/yaml.v2"
)
// Pipe that writes the effective config file to dist
type Pipe struct {
}
func (Pipe) String() string {
return "writing effective config file"
}
// Run the pipe
func (Pipe) Run(ctx *context.Context) (err error) {
var path = filepath.Join(ctx.Config.Dist, "config.yaml")
bts, err := yaml.Marshal(ctx.Config)
if err != nil {
return err
}
log.WithField("config", path).Info("writting")
return ioutil.WriteFile(path, bts, 0644)
}

View File

@ -0,0 +1,33 @@
package effectiveconfig
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/stretchr/testify/assert"
)
func TestPipeDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.String())
}
func Test(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
dist := filepath.Join(folder, "dist")
assert.NoError(t, os.Mkdir(dist, 0755))
var ctx = context.New(
config.Project{
Dist: dist,
},
)
assert.NoError(t, Pipe{}.Run(ctx))
bts, err := ioutil.ReadFile(filepath.Join(dist, "config.yaml"))
assert.NoError(t, err)
assert.NotEmpty(t, string(bts))
}