You've already forked go-semantic-release
refactor(*): add missing files
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
|||||||
*.dylib
|
*.dylib
|
||||||
go-semantic-release
|
go-semantic-release
|
||||||
|
|
||||||
|
!cmd/go-semantic-release
|
||||||
# Test binary, build with `go test -c`
|
# Test binary, build with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
|
||||||
|
|||||||
59
cmd/go-semantic-release/commands/changelog.go
Normal file
59
cmd/go-semantic-release/commands/changelog.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
changelogCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file")
|
||||||
|
rootCmd.AddCommand(changelogCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var changelogCmd = &cobra.Command{
|
||||||
|
Use: "changelog",
|
||||||
|
Short: "Generate changelog and save to file",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
config, err := cmd.Flags().GetString("config")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
repository, err := cmd.Flags().GetString("repository")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
force, err := cmd.Flags().GetBool("no-cache")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := cmd.Flags().GetString("out")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := semanticrelease.New(readConfig(config), repository)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVersion, err := s.GetNextVersion(force)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
generatedChangelog, err := s.GetChangelog(releaseVersion)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = s.WriteChangeLog(generatedChangelog.Content, file); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
45
cmd/go-semantic-release/commands/next.go
Normal file
45
cmd/go-semantic-release/commands/next.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(nextCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var nextCmd = &cobra.Command{
|
||||||
|
Use: "next",
|
||||||
|
Short: "Get next release version",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
config, err := cmd.Flags().GetString("config")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
repository, err := cmd.Flags().GetString("repository")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
force, err := cmd.Flags().GetBool("no-cache")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := semanticrelease.New(readConfig(config), repository)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVersion, err := s.GetNextVersion(force)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(releaseVersion.Next.Version.String())
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
37
cmd/go-semantic-release/commands/release.go
Normal file
37
cmd/go-semantic-release/commands/release.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(releaseCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var releaseCmd = &cobra.Command{
|
||||||
|
Use: "release",
|
||||||
|
Short: "Make a release",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
config, err := cmd.Flags().GetString("config")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
repository, err := cmd.Flags().GetString("repository")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
force, err := cmd.Flags().GetBool("force")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := semanticrelease.New(readConfig(config), repository)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return s.Release(force)
|
||||||
|
},
|
||||||
|
}
|
||||||
56
cmd/go-semantic-release/commands/root.go
Normal file
56
cmd/go-semantic-release/commands/root.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "go-semantic-release",
|
||||||
|
Short: "Make simple releases",
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
level, err := cmd.Flags().GetString("loglevel")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
setLoglevel(level)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
//Execute rootCmd
|
||||||
|
func Execute() {
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.PersistentFlags().StringP("repository", "r", "", "Path to repository")
|
||||||
|
rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel")
|
||||||
|
rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file")
|
||||||
|
rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build")
|
||||||
|
}
|
||||||
|
|
||||||
|
func readConfig(file string) *config.ReleaseConfig {
|
||||||
|
releaseConfig, err := config.Read(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return releaseConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func setLoglevel(level string) {
|
||||||
|
parsed, err := log.ParseLevel(level)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Invalid loglevel %s", level)
|
||||||
|
} else {
|
||||||
|
log.SetLevel(parsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
36
cmd/go-semantic-release/commands/set.go
Normal file
36
cmd/go-semantic-release/commands/set.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(setCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var setCmd = &cobra.Command{
|
||||||
|
Use: "set [version]",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Short: "Set next release version",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
|
config, err := cmd.Flags().GetString("config")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
repository, err := cmd.Flags().GetString("repository")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := semanticrelease.New(readConfig(config), repository)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.SetVersion(args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user