mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-29 01:44:39 +02:00
feat: add goreleaser check (#1096)
* feat: add goreleaser check Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * docs: added to deprecations.md Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * docs: added to bug.md Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: added tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
844f95a2d0
commit
ba0e472247
3
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
3
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
@ -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.
|
||||
|
29
main.go
29
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 {
|
||||
|
14
main_test.go
14
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()
|
||||
|
@ -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
|
||||
|
||||
<!--
|
||||
|
Loading…
Reference in New Issue
Block a user