diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index b5fe508ac..ff4fe2c66 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -16,6 +16,9 @@ Steps to reproduce the behavior: your goreleaser config file ``` +> Make sure your config file is valid by running +> `goreleaser check -f path-to-config-file`. + **Expected behavior** A clear and concise description of what you expected to happen. diff --git a/main.go b/main.go index 934c61d8a..83473e985 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "github.com/goreleaser/goreleaser/internal/static" "github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/context" + "github.com/goreleaser/goreleaser/pkg/defaults" kingpin "gopkg.in/alecthomas/kingpin.v2" ) @@ -50,9 +51,10 @@ func main() { var app = kingpin.New("goreleaser", "Deliver Go binaries as fast and easily as possible") var debug = app.Flag("debug", "Enable debug mode").Bool() + var config = app.Flag("config", "Load configuration from file").Short('c').Short('f').PlaceHolder(".goreleaser.yml").String() var initCmd = app.Command("init", "Generates a .goreleaser.yml file").Alias("i") + var checkCmd = app.Command("check", "Checks if configuration is valid").Alias("c") var releaseCmd = app.Command("release", "Releases the current project").Alias("r").Default() - var config = releaseCmd.Flag("config", "Load configuration from file").Short('c').Short('f').PlaceHolder(".goreleaser.yml").String() var releaseNotes = releaseCmd.Flag("release-notes", "Load custom release notes from a markdown file").PlaceHolder("notes.md").String() var snapshot = releaseCmd.Flag("snapshot", "Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts").Bool() var skipPublish = releaseCmd.Flag("skip-publish", "Skips publishing artifacts").Bool() @@ -73,13 +75,20 @@ func main() { } switch cmd { case initCmd.FullCommand(): - var filename = ".goreleaser.yml" + var filename = *config if err := initProject(filename); err != nil { log.WithError(err).Error("failed to init project") os.Exit(1) return } log.WithField("file", filename).Info("config created; please edit accordingly to your needs") + case checkCmd.FullCommand(): + if err := checkConfig(*config); err != nil { + log.WithError(err).Errorf(color.New(color.Bold).Sprintf("config is invalid")) + os.Exit(1) + return + } + log.Infof(color.New(color.Bold).Sprintf("config is valid")) case releaseCmd.FullCommand(): start := time.Now() log.Infof(color.New(color.Bold).Sprintf("releasing using goreleaser %s...", version)) @@ -103,6 +112,22 @@ func main() { } } +func checkConfig(filename string) error { + cfg, err := loadConfig(filename) + if err != nil { + return err + } + var ctx = context.New(cfg) + return ctrlc.Default.Run(ctx, func() error { + for _, pipe := range defaults.Defaulters { + if err := middleware.ErrHandler(pipe.Default)(ctx); err != nil { + return err + } + } + return nil + }) +} + func releaseProject(options releaseOptions) error { cfg, err := loadConfig(options.Config) if err != nil { diff --git a/main_test.go b/main_test.go index 56d3cbeba..eeca07790 100644 --- a/main_test.go +++ b/main_test.go @@ -25,6 +25,20 @@ func TestReleaseProject(t *testing.T) { assert.NoError(t, releaseProject(testParams())) } +func TestCheckConfig(t *testing.T) { + _, back := setup(t) + defer back() + assert.NoError(t, checkConfig(testParams().Config)) +} + +func TestCheckConfigFails(t *testing.T) { + _, back := setup(t) + defer back() + var filename = "fail.yaml" + assert.NoError(t, ioutil.WriteFile(filename, []byte("nope: 1"), 0644)) + assert.Error(t, checkConfig(filename)) +} + func TestReleaseProjectSkipPublish(t *testing.T) { _, back := setup(t) defer back() diff --git a/www/content/deprecations.md b/www/content/deprecations.md index 943690ecd..f75bdab44 100644 --- a/www/content/deprecations.md +++ b/www/content/deprecations.md @@ -9,6 +9,12 @@ This page will be used to list deprecation notices across GoReleaser. Deprecate code will be removed after ~6 months from the time it was deprecated. +You can check your use of deprecated configurations by running: + +```sh +$ goreleaser check +``` + ## Active deprecation notices