1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-09-16 09:26:52 +02:00

feat: write actual config to dist

Writes the actual config file (with defaults
merged, etc) into the dist folder.

Can be useful for debug purposes.
This commit is contained in:
Carlos Alexandro Becker
2017-12-08 22:30:02 -02:00
committed by Carlos Alexandro Becker
parent bb5e27b0c4
commit 06ddedf12a
6 changed files with 61 additions and 23 deletions

1
.gitignore vendored
View File

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

View File

@@ -16,10 +16,11 @@ 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/env"
"github.com/goreleaser/goreleaser/pipeline/finalconfig"
"github.com/goreleaser/goreleaser/pipeline/fpm"
"github.com/goreleaser/goreleaser/pipeline/git"
"github.com/goreleaser/goreleaser/pipeline/release"
@@ -37,19 +38,20 @@ 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
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
defaults.Pipe{}, // load default configs
dist.Pipe{}, // ensure ./dist is clean
finalconfig.Pipe{}, // writes the actual config (with defaults et al set) to dist
git.Pipe{}, // get and validate git repo state
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
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
}
// Flags interface represents an extractor of cli flags

View File

@@ -48,6 +48,6 @@ 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,9 @@ func (Pipe) Run(ctx *context.Context) (err error) {
)
}
log.Debug("./dist is empty")
return
return mkdir(ctx)
}
func mkdir(ctx *context.Context) error {
return os.Mkdir(ctx.Config.Dist, 0755)
}

View File

@@ -1,4 +1,4 @@
package cleandist
package dist
import (
"io/ioutil"

View File

@@ -0,0 +1,27 @@
package finalconfig
import (
"io/ioutil"
"path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context"
yaml "gopkg.in/yaml.v2"
)
type Pipe struct {
}
func (Pipe) String() string {
return "writing the final config file to dist folder"
}
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("path", path).Info("writting")
return ioutil.WriteFile(path, bts, 0644)
}