feat(config): add config file

This commit is contained in:
Nightapes
2019-05-15 22:09:52 +02:00
parent abede95350
commit d7664eb8e8
7 changed files with 165 additions and 24 deletions

View File

@@ -4,7 +4,9 @@ package main
import (
"os"
"github.com/Nightapes/go-semantic-release/pkg/config"
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
log "github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)
@@ -15,17 +17,22 @@ var (
nextCommand = app.Command("next", "Print next version")
nextRepository = nextCommand.Flag("repository", "Path to repository").String()
nextConfigPath = nextCommand.Flag("config", "Path to config file").Default(".release.yml").String()
nextForce = nextCommand.Flag("force", "Ignore cache, don't use in ci build").Bool()
setCommand = app.Command("set", "Set version for current build.")
setRepository = setCommand.Flag("repository", "Path to repository").String()
setConfigPath = setCommand.Flag("config", "Path to config file").Default(".release.yml").String()
setVersion = setCommand.Arg("version", "semver version").Required().String()
)
func main() {
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case nextCommand.FullCommand():
setLoglevel(*loglevel)
err := semanticrelease.GetNextVersion(*nextRepository)
s := semanticrelease.New(readConfig(nextConfigPath))
err := s.GetNextVersion(*nextRepository, *nextForce)
if err != nil {
log.Fatal(err)
}
@@ -33,7 +40,8 @@ func main() {
case setCommand.FullCommand():
setLoglevel(*loglevel)
log.Infof("Version %s", *setVersion)
err := semanticrelease.SetVersion(*setVersion, *setRepository)
s := semanticrelease.New(readConfig(setConfigPath))
err := s.SetVersion(*setVersion, *setRepository)
if err != nil {
log.Fatal(err)
}
@@ -41,6 +49,14 @@ func main() {
}
func readConfig(path *string) *config.ReleaseConfig {
releaseConfig, err := config.Read(*path)
if err != nil {
log.Fatal(err)
}
return releaseConfig
}
func setLoglevel(level string) {
parsed, err := log.ParseLevel(level)
if err != nil {