From 80109fbbc2ad71a23f9a1de97ac00ff70c58de1d Mon Sep 17 00:00:00 2001 From: carabasdaniel Date: Wed, 22 Nov 2023 11:40:32 +0200 Subject: [PATCH 1/2] Add git describe options flag --- cmd/sver/main.go | 12 +++++++----- pkg/sver/versioning.go | 8 ++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/sver/main.go b/cmd/sver/main.go index 40afc4e..bd0c3a6 100644 --- a/cmd/sver/main.go +++ b/cmd/sver/main.go @@ -20,9 +20,10 @@ var ( flagReleaseOnly = false flagPrefix = false - flagTagsServerURL = "" - flagTagsUsername = "" - flagTagsPassword = "" + flagTagsServerURL = "" + flagTagsUsername = "" + flagTagsPassword = "" + flagGitDescribeOptions = []string{} ) var rootCmd = &cobra.Command{ @@ -32,7 +33,7 @@ var rootCmd = &cobra.Command{ return errors.New("Asked for a pre-release version, but the --release flag is on.") } - version, err := sver.CurrentVersion(flagReleaseOnly, flagForce) + version, err := sver.CurrentVersion(flagReleaseOnly, flagForce, flagGitDescribeOptions...) if err != nil { return err } @@ -108,7 +109,7 @@ it's the latest one, it returns the appropriate tags to be pushed.`, return errors.New("Asked for a pre-release version, but the --release flag is on.") } - version, err := sver.CurrentVersion(flagReleaseOnly, flagForce) + version, err := sver.CurrentVersion(flagReleaseOnly, flagForce, flagGitDescribeOptions...) if err != nil { return err } @@ -159,6 +160,7 @@ func main() { rootCmd.Flags().BoolVarP(&flagReleaseOnly, "release", "", false, "Fail if this is a dev, pre-release or dirty version.") rootCmd.Flags().BoolVarP(&flagForce, "force", "f", false, "Ignore a dirty repository.") rootCmd.Flags().BoolVarP(&flagPrefix, "prefix", "p", false, "Add the 'v' prefix to the output version.") + rootCmd.Flags().StringArrayVarP(&flagGitDescribeOptions, "git-describe-options", "g", []string{}, "Add extra options to git describe used to determine the correct version.(ex. --match='v*', --exclude='prefix/*')") tagsCmd.Flags().StringVarP(&flagTagsServerURL, "server", "s", "https://registry-1.docker.io/", "Registry server to connect to.") tagsCmd.Flags().StringVarP(&flagTagsUsername, "user", "u", "", "Username for the registry.") diff --git a/pkg/sver/versioning.go b/pkg/sver/versioning.go index cd30069..649a860 100644 --- a/pkg/sver/versioning.go +++ b/pkg/sver/versioning.go @@ -21,14 +21,18 @@ var ( regexTail = regexp.MustCompile(`^\d+\.\d+\.\d+(.*)`) ) -func CurrentVersion(releaseOnly, force bool) (string, error) { +func CurrentVersion(releaseOnly, force bool, options ...string) (string, error) { err := verifyGit() if err != nil { return "", errors.Wrap(err, "git error") } hasTag := true - tag, err := git("describe", "--tags", "--abbrev=0") + params := []string{"describe", "--tags", "--abbrev=0"} + if len(options) > 0 { + params = append(params, options...) + } + tag, err := git(params...) if err != nil { if !strings.Contains(err.Error(), "cannot describe anything") { return "", errors.Wrap(err, "exec error") From 5f7781b6498d7755f549ed596bf470e97fd00bea Mon Sep 17 00:00:00 2001 From: carabasdaniel Date: Wed, 22 Nov 2023 15:29:48 +0200 Subject: [PATCH 2/2] Increase allowed complexity level to 20 --- .golangci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index cae0328..b54e90a 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -34,7 +34,7 @@ linters-settings: - whyNoLint - wrapperFunc gocyclo: - min-complexity: 18 + min-complexity: 20 goimports: local-prefixes: github.com/golangci/golangci-lint golint: