diff --git a/README.md b/README.md index b818ba0..54c9689 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ relevant files, reducing the risk of human error and saving you valuable time. 0.0.0 ─┬─ major ─ 1.0.0 ├─ minor ─ 0.1.0 ├─ patch ─ 0.0.1 + ├─ release ─ 0.0.0 ├─ new-pre-major ─ 1.0.0-alpha ├─ new-pre-minor ─ 0.1.0-alpha ├─ new-pre-patch ─ 0.0.1-alpha @@ -104,6 +105,7 @@ relevant files, reducing the risk of human error and saving you valuable time. 0.0.1-alpha ─┬─ major ─ 1.0.0 ├─ minor ─ 0.1.0 ├─ patch ─ 0.0.2 + ├─ release ─ 0.0.1 ├─ new-pre-major ─ 1.0.0-alpha ├─ new-pre-minor ─ 0.1.0-alpha ├─ new-pre-patch ─ 0.0.2-alpha @@ -259,6 +261,7 @@ Available Commands: new-pre-minor Bump the minor version and apply the first pre-release label (e.g. 1.2.3 -> 1.3.0-alpha). new-pre-patch Bump the patch version and apply the first pre-release label (e.g. 1.2.3 -> 1.2.4-alpha). patch Bump the patch version number (e.g. 1.2.3 -> 1.2.4). + release Bump the pre-release version to a release version (e.g. 1.2.3-alpha -> 1.2.3). pre Bump the next pre-release version label (e.g. 1.2.3-alpha -> 1.2.3-beta). pre-build Bump the pre-release build version number (e.g. 1.2.3 -> 1.2.3+build.1). pre-major Bump the pre-release major version number (e.g. 1.2.3-alpha -> 1.2.3-alpha.1). @@ -270,7 +273,7 @@ Available Commands: ``` -The commands `major`, `minor` `patch`, `set`, `new-pre-major`, `new-pre-minor`, `new-pre-patch`, `pre`, `pre-major`, +The commands `major`, `minor` `patch`, `release`, `set`, `new-pre-major`, `new-pre-minor`, `new-pre-patch`, `pre`, `pre-major`, `pre-minor`, `pre-patch` and `pre-build` support the following flags:' - `-c`, `-config`: Path to the configuration file (default: `./versionbump.yaml`). - `-no-prompt`: Do not prompt the user for confirmation before making changes. @@ -495,6 +498,7 @@ Without parameters, the `show` command will display the potential versioning pat $ 0.6.0-alpha.1 ─┬─ major ─ 1.0.0 ├─ minor ─ 0.7.0 ├─ patch ─ 0.6.1 + ├─ release ─ 0.6.0 ├─ pre-new-major ─ 1.0.0-alpha ├─ pre-new-minor ─ 0.7.0-alpha ├─ pre-new-patch ─ 0.6.1-alpha @@ -512,6 +516,7 @@ Potential versioning paths for version: 0.4.1-alpha 0.4.1-alpha ─┬─ major ─ 1.0.0 ├─ minor ─ 0.5.0 ├─ patch ─ 0.4.2 + ├─ release ─ 0.4.1 ├─ pre-new-major ─ 1.0.0-alpha ├─ pre-new-minor ─ 0.5.0-alpha ├─ pre-new-patch ─ 0.4.2-alpha @@ -531,6 +536,9 @@ considered valid semantic version numbers. ```console $ versionbump history version History: + - 0.7.0 + - 0.7.0-alpha + - 0.6.0 - 0.6.0-alpha.1 - 0.6.0-alpha - 0.5.4 diff --git a/cmd/versionbump/main.go b/cmd/versionbump/main.go index 43e5dfc..0c3287c 100644 --- a/cmd/versionbump/main.go +++ b/cmd/versionbump/main.go @@ -2,12 +2,13 @@ package main import ( "fmt" + "os" + "github.com/ptgoetz/go-versionbump/internal" vbc "github.com/ptgoetz/go-versionbump/internal/config" "github.com/ptgoetz/go-versionbump/pkg/semver" "github.com/spf13/cobra" "github.com/spf13/pflag" - "os" ) func main() { @@ -131,7 +132,7 @@ var gitTagHistoryCmd = &cobra.Command{ var preReleaseNextCmd = &cobra.Command{ Use: semver.PreRelease.String(), Short: `Bump the next pre-release version label (e.g. 1.2.3-alpha -> 1.2.3-beta).`, - Long: `Bump the patch version number (e.g. 1.2.3 -> 1.2.4).`, + Long: `Bump the next pre-release version label (e.g. 1.2.3-alpha -> 1.2.3-beta).`, RunE: bumpPreReleaseNext, // Use RunE for better error handling } @@ -177,6 +178,13 @@ var preReleaseNewPatchCmd = &cobra.Command{ RunE: bumpNewPreReleasePatch, // Use RunE for better error handling } +var releaseCmd = &cobra.Command{ + Use: semver.Release.String(), + Short: `Bump the pre-release version to a release version (e.g. 1.2.3-alpha -> 1.2.3).`, + Long: `Bump the pre-release version to a release version (e.g. 1.2.3-alpha -> 1.2.3).`, + RunE: bumpRelease, // Use RunE for better error handling +} + var preReleaseBuildCmd = &cobra.Command{ Use: semver.PreReleaseBuild.String(), Short: `Bump the pre-release build version number (e.g. 1.2.3 -> 1.2.3+build.1).`, @@ -216,6 +224,7 @@ func init() { preReleaseNewMajorCmd.Flags().AddFlagSet(prereleaserFlags) preReleaseNewMinorCmd.Flags().AddFlagSet(prereleaserFlags) preReleaseNewPatchCmd.Flags().AddFlagSet(prereleaserFlags) + releaseCmd.Flags().AddFlagSet(prereleaserFlags) showCmd.Flags().AddFlagSet(configColorFlags) showVersionCmd.Flags().AddFlagSet(commonFlags) @@ -239,6 +248,7 @@ func init() { rootCmd.AddCommand(preReleaseNewMajorCmd) rootCmd.AddCommand(preReleaseNewMinorCmd) rootCmd.AddCommand(preReleaseNewPatchCmd) + rootCmd.AddCommand(releaseCmd) rootCmd.AddCommand(showCmd) rootCmd.AddCommand(showVersionCmd) rootCmd.AddCommand(showLatestCmd) @@ -299,6 +309,10 @@ func bumpNewPreReleasePatch(cmd *cobra.Command, args []string) error { return runVersionBump(semver.PreReleaseNewPatch) } +func bumpRelease(cmd *cobra.Command, args []string) error { + return runVersionBump(semver.Release) +} + func runResetCmd(cmd *cobra.Command, args []string) error { opts.ResetVersion = args[0] vb, err := internal.NewVersionBump(opts) diff --git a/internal/versionbump.go b/internal/versionbump.go index 4687bde..ceda55d 100644 --- a/internal/versionbump.go +++ b/internal/versionbump.go @@ -3,16 +3,17 @@ package internal import ( "bufio" "fmt" + "os" + "path" + "strings" + "text/template" + "github.com/ptgoetz/go-versionbump/internal/config" "github.com/ptgoetz/go-versionbump/internal/git" "github.com/ptgoetz/go-versionbump/internal/utils" vbu "github.com/ptgoetz/go-versionbump/internal/utils" "github.com/ptgoetz/go-versionbump/pkg/semver" "gopkg.in/yaml.v2" - "os" - "path" - "strings" - "text/template" ) const Version = "1.0.0-alpha" @@ -116,6 +117,9 @@ func (vb *VersionBump) Show(versionStr string) error { patchVersion, err := curVersion.Bump(semver.Patch, vb.Config.PreReleaseLabels, vb.Config.BuildLabel) patchVersionStr := checkBumpError(vb, patchVersion, err) + releaseVersion, err := curVersion.Bump(semver.Release, vb.Config.PreReleaseLabels, vb.Config.BuildLabel) + releaseVersionStr := checkBumpError(vb, releaseVersion, err) + prNextVersion, err := curVersion.Bump(semver.PreRelease, vb.Config.PreReleaseLabels, vb.Config.BuildLabel) prNextVersionStr := checkBumpError(vb, prNextVersion, err) @@ -147,6 +151,7 @@ func (vb *VersionBump) Show(versionStr string) error { `%s ─┬─ major ─ %s %s├─ minor ─ %s %s├─ patch ─ %s + %s├─ release ─ %s %s├─ new-pre-major ─ %s %s├─ new-pre-minor ─ %s %s├─ new-pre-patch ─ %s @@ -163,6 +168,8 @@ func (vb *VersionBump) Show(versionStr string) error { padding, patchVersionStr, padding, + releaseVersionStr, + padding, prNewMajorVersionStr, padding, prNewMinorVersionStr, diff --git a/pkg/semver/semver.go b/pkg/semver/semver.go index f0c5f2e..38a29bc 100644 --- a/pkg/semver/semver.go +++ b/pkg/semver/semver.go @@ -5,15 +5,17 @@ package semver import ( "fmt" - "github.com/ptgoetz/go-versionbump/internal/utils" "sort" "strings" + + "github.com/ptgoetz/go-versionbump/internal/utils" ) const ( vMajor = iota vMinor vPatch + vRelease prNext prMajor prNewMajor @@ -30,6 +32,7 @@ const ( Major BumpStrategy = "major" Minor BumpStrategy = "minor" Patch BumpStrategy = "patch" + Release BumpStrategy = "release" PreRelease BumpStrategy = "pre" PreReleaseMajor BumpStrategy = "pre-major" PreReleaseMinor BumpStrategy = "pre-minor" @@ -52,6 +55,8 @@ func versionPartInt(part BumpStrategy) int { return vMinor case Patch: return vPatch + case Release: + return vRelease case PreRelease: return prNext case PreReleaseMajor: @@ -128,7 +133,7 @@ func (v *SemanticVersion) Bump(strategy BumpStrategy, preReleaseLabels []string, preReleaseVersion = newPrereleaseVersion("", 0, 0, 0) case versionPart >= prNewMajor && versionPart <= prNewPatch: // bump the root version - version = v.rootVersion.bump(versionPart - 5) + version = v.rootVersion.bump(versionPart - 6) // reset all pre-release versions preReleaseVersion = newPrereleaseVersion(preReleaseLabels[0], 0, 0, 0) case versionPart >= prNext && versionPart <= prPatch: @@ -145,6 +150,10 @@ func (v *SemanticVersion) Bump(strategy BumpStrategy, preReleaseLabels []string, } else { build = newBuild(buildLabel, 1) } + case versionPart == vRelease: + version = v.rootVersion + preReleaseVersion = nil + build = nil default: return nil, fmt.Errorf("invalid version strategy: %d", versionPart) } diff --git a/pkg/semver/semver_test.go b/pkg/semver/semver_test.go index ff05184..6a36f6a 100644 --- a/pkg/semver/semver_test.go +++ b/pkg/semver/semver_test.go @@ -2,9 +2,10 @@ package semver import ( "fmt" + "testing" + "github.com/stretchr/testify/assert" sv "golang.org/x/mod/semver" - "testing" ) func TestParseSemVersion(t *testing.T) { @@ -57,13 +58,20 @@ func TestSemVersion_Bump(t *testing.T) { {"0.0.1", Minor, "0.1.0", false}, {"0.1.0", Major, "1.0.0", false}, {"1.0.0", PreRelease, "1.0.0-alpha", false}, + {"1.0.0-alpha+ptgoetz.1", PreRelease, "1.0.0-beta", false}, {"1.0.0", PreReleaseMajor, "1.0.0-alpha", false}, + {"1.0.0-beta", PreReleaseMajor, "1.0.0-beta.1", false}, {"1.0.0-alpha", PreReleaseBuild, "1.0.0-alpha+ptgoetz.1", false}, {"1.0.0-alpha+ptgoetz.1", PreReleaseBuild, "1.0.0-alpha+ptgoetz.2", false}, - {"1.0.0-alpha+ptgoetz.1", PreRelease, "1.0.0-beta", false}, {"1.0.0-beta", PreReleasePatch, "1.0.0-beta.0.0.1", false}, {"1.0.0-beta", PreReleaseMinor, "1.0.0-beta.0.1", false}, - {"1.0.0-beta", PreReleaseMajor, "1.0.0-beta.1", false}, + {"1.0.0", PreReleaseNewMajor, "2.0.0-alpha", false}, + {"1.0.0-alpha", PreReleaseNewMajor, "2.0.0-alpha", false}, + {"1.0.0", PreReleaseNewMinor, "1.1.0-alpha", false}, + {"1.0.0-alpha", PreReleaseNewMinor, "1.1.0-alpha", false}, + {"1.0.0", PreReleaseNewPatch, "1.0.1-alpha", false}, + {"1.0.0-alpha", PreReleaseNewPatch, "1.0.1-alpha", false}, + {"1.0.0-beta", Release, "1.0.0", false}, } for _, test := range tests {