Console friendly switches and documentation

+ Add ARM64 binary release
+ Draft for github actions.
This commit is contained in:
2021-05-09 04:32:20 +01:00
parent c2efa43dcb
commit 8bbde1f600
8 changed files with 155 additions and 40 deletions
+37
View File
@@ -0,0 +1,37 @@
/*
Copyright © 2021 LUKASZ RACZYLO <lukasz$raczylo,com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"github.com/spf13/cobra"
)
// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "generate [flags]",
Short: "Generates semantic version",
Long: `Semantic version generation using your configuration file and fuzzy matching of git commit messages.
Please refer to documentation on https://github.com/lukaszraczylo/semver-generator for more information.`,
Run: func(cmd *cobra.Command, args []string) {
repo.Generate = true
repo.setupCobra()
main()
},
}
func init() {
rootCmd.AddCommand(generateCmd)
}
+22 -15
View File
@@ -64,6 +64,7 @@ type Setup struct {
Force Force
Generate bool
LocalConfigFile string
UseLocal bool
}
type CommitDetails struct {
@@ -90,18 +91,15 @@ func (s *Setup) CalculateSemver() SemVer {
matchMajor := checkMatches(commitSlice, s.Wording.Major)
if matchPatch {
s.Semver.Patch++
// fmt.Println("Patch version bumped:", commit.Message)
}
if matchMinor {
s.Semver.Minor++
s.Semver.Patch = 1
// fmt.Println("Minor version bumped:", commit.Message)
}
if matchMajor {
s.Semver.Major++
s.Semver.Minor = 0
s.Semver.Patch = 1
// fmt.Println("Major version bumped:", commit.Message)
}
}
return s.Semver
@@ -125,14 +123,27 @@ func (s *Setup) ListCommits() ([]CommitDetails, error) {
}
func (s *Setup) Prepare() error {
u, _ := url.Parse(s.RepositoryName)
s.RepositoryLocalPath = fmt.Sprintf("/tmp/foo/%s", u.Path)
os.RemoveAll(s.RepositoryLocalPath)
s.RepositoryHandler, err = git.PlainClone(s.RepositoryLocalPath, false, &git.CloneOptions{
URL: s.RepositoryName,
})
if err != nil {
fmt.Println("Unable to reach repository", err.Error())
if !repo.UseLocal {
u, err := url.Parse(s.RepositoryName)
if err != nil {
fmt.Println("Unable to parse repository URL", err.Error())
return err
}
s.RepositoryLocalPath = fmt.Sprintf("/tmp/foo/%s", u.Path)
os.RemoveAll(s.RepositoryLocalPath)
s.RepositoryHandler, err = git.PlainClone(s.RepositoryLocalPath, false, &git.CloneOptions{
URL: s.RepositoryName,
})
if err != nil {
fmt.Println("Unable to reach repository", err.Error())
return err
}
} else {
s.RepositoryHandler, err = git.PlainOpen(s.RepositoryLocalPath)
if err != nil {
fmt.Println("Unable to reach repository", err.Error())
return err
}
}
return err
}
@@ -165,10 +176,6 @@ func (s *Setup) getSemver() string {
return fmt.Sprintf("%d.%d.%d", s.Semver.Major, s.Semver.Minor, s.Semver.Patch)
}
func (s *Setup) parseFlags() {
}
func main() {
if repo.Generate {
err := repo.ReadConfig(repo.LocalConfigFile)
+25 -7
View File
@@ -22,11 +22,9 @@ import (
"github.com/spf13/cobra"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "semver-gen",
Use: "semver-gen generate [flags]",
Short: "An effortless semantic version generator",
Long: `semver-gen // Lukasz Raczylo, raczylo.com
@@ -39,12 +37,32 @@ func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
func (r *Setup) setupCobra() {
r.RepositoryName, err = rootCmd.Flags().GetString("repository")
if err != nil {
panic(err)
}
r.LocalConfigFile, err = rootCmd.Flags().GetString("config")
if err != nil {
panic(err)
}
r.UseLocal = varUseLocal
if err != nil {
panic(err)
}
}
var (
varRepoName, varLocalCfg string
varUseLocal bool
)
func init() {
repo = &Setup{}
if !strings.HasSuffix(os.Args[0], ".test") {
rootCmd.PersistentFlags().StringVarP(&repo.RepositoryName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Repository URL. If not specified local dir will be used.")
rootCmd.PersistentFlags().StringVarP(&repo.LocalConfigFile, "config", "c", "config.yaml", "Path to config file")
rootCmd.PersistentFlags().BoolVarP(&repo.Generate, "generate", "g", true, "Generate semantic version")
main()
cobra.OnInitialize(repo.setupCobra)
rootCmd.PersistentFlags().StringVarP(&varRepoName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Remote repository URL.")
rootCmd.PersistentFlags().StringVarP(&varLocalCfg, "config", "c", "config.yaml", "Path to config file")
rootCmd.PersistentFlags().BoolVarP(&varUseLocal, "local", "l", false, "Use local repository")
}
}