Closed arendjantetteroo closed 10 months ago
Hey @arendjantetteroo
Currently there is no command line flag to limit the amount of tags in any way.
I would expect it to continue from 10.0.3 if you change your configuration to include the following:
[git.tags]
prefix = ""
If this does not work, you've found a bug! Let me know if this works for you.
Hi, I've got the same issue and can reproduce it.
→ git --no-pager tag
0.1.5
0.1.6
1.0.0
1.0.1
1.0.2
1.1.0
1.2.0
1.2.1
1.2.2
1.2.3
1.2.4
1.3.0
1.3.1
v0.1.0
v0.1.1
v0.1.2
v0.1.3
v0.1.4
→ grep prefix .semverbot.toml -C 3
name = "semverbot"
[git.tags]
prefix = ""
[semver]
patch = ["fix", "bug"]
→ sbot predict version -m patch
0.1.5
→ sbot predict version -m minor
0.2.0
→ sbot predict version -m major
1.0.0
I would expect the results to be: 1.3.2
, 1.4.0
and 2.0.0
respectively.
There doesn't seem to be a version arg to see if I'm running latest sbot
EDIT: I've just updated and still experience this issue.
→ go install github.com/restechnica/semverbot/cmd/sbot@latest
go: downloading github.com/restechnica/semverbot v1.3.1
go: downloading github.com/restechnica/go-cmder v0.1.1
go: downloading github.com/rs/zerolog v1.29.1
go: downloading golang.org/x/crypto v0.1.0
go: downloading golang.org/x/term v0.1.0
I've done some digging and the issues seems to be in semver.Find()
. It returns the first tag that is a valid semver. In my example above, it seems to loop through the tags starting with v
to begin with.
I've done played with it and managed to get it working. Its pretty hacky, but it gives an idea on whats needed to fix:
→ cat find.patch --plain
diff --git a/pkg/semver/find.go b/pkg/semver/find.go
index 694ba2e..9afd42e 100644
--- a/pkg/semver/find.go
+++ b/pkg/semver/find.go
@@ -1,15 +1,36 @@
package semver
-import "fmt"
+import (
+ "fmt"
+
+ blangsemver "github.com/blang/semver/v4"
+)
// Find finds a valid semver version in a slice of strings.
// Returns a version when found, otherwise an error stating no valid semver version has been found.
func Find(versions []string) (found string, err error) {
+ var parsedVersions blangsemver.Versions
+
for _, version := range versions {
- if _, err = Parse(version); err == nil {
- return version, err
+ parsedVersion, err := Parse(version)
+ if err != nil {
+ fmt.Println("some error that should probably be swallowed")
+ continue
}
+
+ parsedVersions = append(parsedVersions, parsedVersion)
}
- return found, fmt.Errorf("could not find a valid semver version")
+ // Return an error if no parsedVersions are found
+ if parsedVersions.Len() == 0 {
+ return found, fmt.Errorf("could not find a valid semver version")
+ }
+
+ // Sort the tags
+ blangsemver.Sort(parsedVersions)
+
+ // Get the last element for parsedVersions
+ found = parsedVersions[parsedVersions.Len()-1].String()
+
+ return found, nil
}
This now works as expected:
→ sbot predict version -m major
2.0.0
→ sbot predict version -m minor
1.4.0
→ sbot predict version -m patch
1.3.2
Hi @bryanhorstmann
I set up a PR with the necessary changes and added tests for this case too https://github.com/restechnica/semverbot/pull/57
I appreciate you took the time to dig around! Your findings were spot on.
@arendjantetteroo @bryanhorstmann
latest release (1.3.2) should fix your issues - homebrew tap has been updated
https://github.com/restechnica/semverbot/releases/tag/v1.3.2
We have started with a tagging strategy of using vx.y.z when we started to tag our versions, but at some point switched to not using a v prefix.
I saw https://github.com/restechnica/semverbot/issues/41 and this seems related.
We now have something like ... 10.0.1 10.0.2 10.0.3 v3.0.1 v3.0.2
Running sbot get version returns v3.0.2 while i want to continue on from 10.0.3. I see that with the changes for 41 it's sorting with git.
Is there a way to pass a command line flag to only look at the last x tags made? Or ignore certain tags with a wildcard?
Just checked that on v1.0.0 i do get 10.0.3. So i could use that version instead of v1.1.0 but maybe a --cli flag would be possible to have both behaviours available in 1 version? Or did i miss this flag?
We are currently using gitversion, which handles this well, but is taking several minutes to calculate the next version in my pipelines, so looking for a more lean and faster alternative. Semverbot looks like a great tool if the above can somehow be managed :)