Skip to content

Commit 833d533

Browse files
authored
Merge branch 'v3-alpha' into windows-improvements
2 parents 66ba876 + da0da5f commit 833d533

File tree

5 files changed

+382
-1
lines changed

5 files changed

+382
-1
lines changed

docs/src/content/docs/changelog.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8080
- Add `SetMenu()` on window to allow for setting a menu on a window by [@leaanthony](https://github.com/leaanthony)
8181
- Add Notification support by [@popaprozac] in [#4098](https://github.com/wailsapp/wails/pull/4098)
8282
-  Add File Association support for mac by [@wimaha](https://github.com/wimaha) in [#4177](https://github.com/wailsapp/wails/pull/4177)
83-
83+
- Add `wails3 tool version` for semantic version bumping by [@leaanthony](https://github.com/leaanthony)
8484
### Fixed
8585

8686
- Fixed Windows+Linux Edit Menu issues by [@leaanthony](https://github.com/leaanthony) in [#3f78a3a](https://github.com/wailsapp/wails/commit/3f78a3a8ce7837e8b32242c8edbbed431c68c062)

docs/src/content/docs/guides/cli.mdx

+26
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,32 @@ Shows build information about the application.
325325
wails3 tool buildinfo
326326
```
327327

328+
### `tool version`
329+
Bumps a semantic version based on the provided flags.
330+
331+
```bash
332+
wails3 tool version [flags]
333+
```
334+
335+
#### Flags
336+
| Flag | Description | Default |
337+
|---------------|--------------------------------------------------|---------|
338+
| `-v` | Current version to bump | |
339+
| `-major` | Bump major version | `false` |
340+
| `-minor` | Bump minor version | `false` |
341+
| `-patch` | Bump patch version | `false` |
342+
| `-prerelease` | Bump prerelease version (e.g., alpha.5 to alpha.6) | `false` |
343+
344+
The command follows the precedence order: major > minor > patch > prerelease. It preserves the "v" prefix if present in the input version, as well as any prerelease and metadata components.
345+
346+
Example usage:
347+
```bash
348+
wails3 tool version -v 1.2.3 -major # Output: 2.0.0
349+
wails3 tool version -v v1.2.3 -minor # Output: v1.3.0
350+
wails3 tool version -v 1.2.3-alpha -patch # Output: 1.2.4-alpha
351+
wails3 tool version -v v3.0.0-alpha.5 -prerelease # Output: v3.0.0-alpha.6
352+
```
353+
328354
### `tool package`
329355
Generates Linux packages (deb, rpm, archlinux).
330356

v3/cmd/wails3/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func main() {
7979
tool.NewSubCommandFunction("cp", "Copy files", commands.Cp)
8080
tool.NewSubCommandFunction("buildinfo", "Show Build Info", commands.BuildInfo)
8181
tool.NewSubCommandFunction("package", "Generate Linux packages (deb, rpm, archlinux)", commands.ToolPackage)
82+
tool.NewSubCommandFunction("version", "Bump semantic version", commands.ToolVersion)
8283

8384
app.NewSubCommandFunction("version", "Print the version", commands.Version)
8485
app.NewSubCommand("sponsor", "Sponsor the project").Action(openSponsor)

v3/internal/commands/tool_version.go

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
8+
"github.com/wailsapp/wails/v3/internal/github"
9+
)
10+
11+
type ToolVersionOptions struct {
12+
Version string `name:"v" description:"Current version to bump"`
13+
Major bool `name:"major" description:"Bump major version"`
14+
Minor bool `name:"minor" description:"Bump minor version"`
15+
Patch bool `name:"patch" description:"Bump patch version"`
16+
Prerelease bool `name:"prerelease" description:"Bump prerelease version (e.g., alpha.5 to alpha.6)"`
17+
}
18+
19+
// bumpPrerelease increments the numeric part of a prerelease string
20+
// For example, "alpha.5" becomes "alpha.6"
21+
func bumpPrerelease(prerelease string) string {
22+
// If prerelease is empty, return it as is
23+
if prerelease == "" {
24+
return prerelease
25+
}
26+
27+
// Split the prerelease string by dots
28+
parts := strings.Split(prerelease, ".")
29+
30+
// If there's only one part (e.g., "alpha"), return it as is
31+
if len(parts) == 1 {
32+
return prerelease
33+
}
34+
35+
// Try to parse the last part as a number
36+
lastPart := parts[len(parts)-1]
37+
num, err := strconv.Atoi(lastPart)
38+
if err != nil {
39+
// If the last part is not a number, return the prerelease as is
40+
return prerelease
41+
}
42+
43+
// Increment the number
44+
num++
45+
46+
// Replace the last part with the incremented number
47+
parts[len(parts)-1] = strconv.Itoa(num)
48+
49+
// Join the parts back together
50+
return strings.Join(parts, ".")
51+
}
52+
53+
// ToolVersion bumps a semantic version based on the provided flags
54+
func ToolVersion(options *ToolVersionOptions) error {
55+
DisableFooter = true
56+
57+
if options.Version == "" {
58+
return fmt.Errorf("please provide a version using the -v flag")
59+
}
60+
61+
// Check if the version has a "v" prefix
62+
hasVPrefix := false
63+
versionStr := options.Version
64+
if len(versionStr) > 0 && versionStr[0] == 'v' {
65+
hasVPrefix = true
66+
versionStr = versionStr[1:]
67+
}
68+
69+
// Parse the current version
70+
semver, err := github.NewSemanticVersion(versionStr)
71+
if err != nil {
72+
return fmt.Errorf("invalid version format: %v", err)
73+
}
74+
75+
// Get the current version components
76+
major := semver.Version.Major()
77+
minor := semver.Version.Minor()
78+
patch := semver.Version.Patch()
79+
prerelease := semver.Version.Prerelease()
80+
metadata := semver.Version.Metadata()
81+
82+
// Check if at least one flag is specified
83+
if !options.Major && !options.Minor && !options.Patch && !options.Prerelease {
84+
return fmt.Errorf("please specify one of -major, -minor, -patch, or -prerelease")
85+
}
86+
87+
// Bump the version based on the flags (major takes precedence over minor, which takes precedence over patch)
88+
if options.Major {
89+
major++
90+
minor = 0
91+
patch = 0
92+
} else if options.Minor {
93+
minor++
94+
patch = 0
95+
} else if options.Patch {
96+
patch++
97+
} else if options.Prerelease {
98+
// If only prerelease flag is specified, bump the prerelease version
99+
if prerelease == "" {
100+
return fmt.Errorf("cannot bump prerelease version: no prerelease part in the version")
101+
}
102+
prerelease = bumpPrerelease(prerelease)
103+
}
104+
105+
// Format the new version
106+
newVersion := fmt.Sprintf("%d.%d.%d", major, minor, patch)
107+
if prerelease != "" {
108+
newVersion += "-" + prerelease
109+
}
110+
if metadata != "" {
111+
newVersion += "+" + metadata
112+
}
113+
114+
// Add the "v" prefix back if it was present in the input
115+
if hasVPrefix {
116+
newVersion = "v" + newVersion
117+
}
118+
119+
// Print the new version
120+
fmt.Println(newVersion)
121+
122+
return nil
123+
}

0 commit comments

Comments
 (0)