Skip to content

Commit c88f02c

Browse files
committed
Add build info tool
1 parent 212f5c7 commit c88f02c

File tree

11 files changed

+231
-11
lines changed

11 files changed

+231
-11
lines changed

mkdocs-website/docs/en/changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
## [Unreleased]
1919

20+
## v3.0.0-alpha.5 - 2024-07-30
21+
2022

2123
### Added
2224
- [linux] WindowDidMove / WindowDidResize events in [#3580](https://github.com/wailsapp/wails/pull/3580)

v3/Taskfile.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ tasks:
5656
- cmd: go run ../../../tasks/sed/sed.go replace -dir frontend -old wailsjs.dev -new wails.io -ext .ts,.js,.html -ignore vite.config.js,vite.config.ts,vite-env.d.ts
5757
- cmd: go run ../../../tasks/sed/sed.go replace -dir frontend -old "framework powered by Wails" -new "framework powered by Vite" -ext .ts,.js,.html,.svelte -ignore vite.config.js,vite.config.ts,vite-env.d.ts
5858

59+
release:
60+
summary: Release a new version of Wails. Call with `task v3:release -- <version>`
61+
dir: tasks/release
62+
cmds:
63+
- go run release.go {{.CLI_ARGS}}
64+
5965
taskfile:upgrade:
6066
cmds:
6167
- go get -u github.com/go-task/task/v3

v3/cmd/wails3/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func main() {
6565
tool.NewSubCommandFunction("checkport", "Checks if a port is open. Useful for testing if vite is running.", commands.ToolCheckPort)
6666
tool.NewSubCommandFunction("watcher", "Watches files and runs a command when they change", commands.Watcher)
6767
tool.NewSubCommandFunction("cp", "Copy files", commands.Cp)
68+
tool.NewSubCommandFunction("buildinfo", "Show Build Info", commands.BuildInfo)
6869

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

v3/internal/buildinfo/buildinfo.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package buildinfo
2+
3+
import (
4+
"fmt"
5+
"github.com/samber/lo"
6+
"runtime/debug"
7+
)
8+
9+
type Info struct {
10+
Development bool
11+
Version string
12+
BuildSettings map[string]string
13+
wailsPackage *debug.Module
14+
}
15+
16+
func Get() (*Info, error) {
17+
18+
var result Info
19+
20+
// BuildInfo contains the build info for the application
21+
var BuildInfo *debug.BuildInfo
22+
23+
var ok bool
24+
BuildInfo, ok = debug.ReadBuildInfo()
25+
if !ok {
26+
return nil, fmt.Errorf("could not read build info from binary")
27+
}
28+
result.BuildSettings = lo.Associate(BuildInfo.Settings, func(setting debug.BuildSetting) (string, string) {
29+
return setting.Key, setting.Value
30+
})
31+
result.Version = BuildInfo.Main.Version
32+
result.Development = BuildInfo.Main.Version == "(devel)"
33+
34+
return &result, nil
35+
36+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package buildinfo
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestGet(t *testing.T) {
8+
result, err := Get()
9+
if err != nil {
10+
t.Error(err)
11+
}
12+
_ = result
13+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"github.com/wailsapp/wails/v3/internal/buildinfo"
6+
)
7+
8+
type BuildInfoOptions struct{}
9+
10+
func BuildInfo(_ *BuildInfoOptions) error {
11+
12+
info, err := buildinfo.Get()
13+
if err != nil {
14+
return err
15+
}
16+
fmt.Printf("%+v\n", info)
17+
return nil
18+
}

v3/internal/doctor/doctor.go

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package doctor
22

33
import (
44
"fmt"
5+
"github.com/wailsapp/wails/v3/internal/buildinfo"
56
"path/filepath"
67
"runtime"
78
"runtime/debug"
@@ -19,6 +20,12 @@ import (
1920

2021
func Run() (err error) {
2122

23+
get, err := buildinfo.Get()
24+
if err != nil {
25+
return err
26+
}
27+
_ = get
28+
2229
pterm.DefaultSection = *pterm.DefaultSection.
2330
WithBottomPadding(0).
2431
WithStyle(pterm.NewStyle(pterm.FgBlue, pterm.Bold))

v3/internal/templates/_common/go.mod.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module changeme
22

33
go 1.21
44

5-
require github.com/wailsapp/wails/v3 v3.0.0-alpha.0
5+
require github.com/wailsapp/wails/v3 {{.WailsVersion}}
66

77
require (
88
github.com/json-iterator/go v1.1.12 // indirect

v3/internal/templates/templates.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"embed"
55
"encoding/json"
66
"fmt"
7+
"github.com/wailsapp/wails/v3/internal/buildinfo"
8+
"github.com/wailsapp/wails/v3/internal/version"
79
"io/fs"
810
"os"
911
"os/exec"
@@ -72,6 +74,7 @@ type TemplateOptions struct {
7274
*flags.Init
7375
LocalModulePath string
7476
UseTypescript bool
77+
WailsVersion string
7578
}
7679

7780
func getInternalTemplate(templateName string) (*Template, error) {
@@ -214,24 +217,35 @@ func Install(options *flags.Init) error {
214217
return err
215218
}
216219

217-
// Calculate relative path from project directory to LocalModulePath
218-
var relativePath string
219-
// Check if the project directory and LocalModulePath are in the same drive
220-
if filepath.VolumeName(wd) != filepath.VolumeName(debug.LocalModulePath) {
221-
relativePath = debug.LocalModulePath
222-
} else {
223-
relativePath, err = filepath.Rel(projectDir, debug.LocalModulePath)
224-
}
220+
buildInfo, err := buildinfo.Get()
225221
if err != nil {
226222
return err
227223
}
228224

225+
// Calculate relative path from project directory to LocalModulePath
226+
var localModulePath string
227+
228+
// Use module path if it is set
229+
if buildInfo.Development {
230+
var relativePath string
231+
// Check if the project directory and LocalModulePath are in the same drive
232+
if filepath.VolumeName(wd) != filepath.VolumeName(debug.LocalModulePath) {
233+
relativePath = debug.LocalModulePath
234+
} else {
235+
relativePath, err = filepath.Rel(projectDir, debug.LocalModulePath)
236+
}
237+
if err != nil {
238+
return err
239+
}
240+
localModulePath = filepath.ToSlash(relativePath + "/")
241+
}
229242
UseTypescript := strings.HasSuffix(options.TemplateName, "-ts")
230243

231244
templateData := TemplateOptions{
232245
Init: options,
233-
LocalModulePath: filepath.ToSlash(relativePath + "/"),
246+
LocalModulePath: localModulePath,
234247
UseTypescript: UseTypescript,
248+
WailsVersion: version.VersionString,
235249
}
236250

237251
defer func() {

v3/internal/version/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.0.0-alpha.4
1+
v3.0.0-alpha.5

v3/tasks/release/release.go

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"strconv"
6+
"strings"
7+
"time"
8+
9+
"github.com/wailsapp/wails/v3/internal/s"
10+
)
11+
12+
const versionFile = "../../internal/version/version.txt"
13+
14+
func checkError(err error) {
15+
if err != nil {
16+
println(err.Error())
17+
os.Exit(1)
18+
}
19+
}
20+
21+
// TODO:This can be replaced with "https://github.com/coreos/go-semver/blob/main/semver/semver.go"
22+
func updateVersion() string {
23+
currentVersionData, err := os.ReadFile(versionFile)
24+
checkError(err)
25+
currentVersion := string(currentVersionData)
26+
vsplit := strings.Split(currentVersion, ".")
27+
minorVersion, err := strconv.Atoi(vsplit[len(vsplit)-1])
28+
checkError(err)
29+
minorVersion++
30+
vsplit[len(vsplit)-1] = strconv.Itoa(minorVersion)
31+
newVersion := strings.Join(vsplit, ".")
32+
err = os.WriteFile(versionFile, []byte(newVersion), 0o755)
33+
checkError(err)
34+
return newVersion
35+
}
36+
37+
//func runCommand(name string, arg ...string) {
38+
// cmd := exec.Command(name, arg...)
39+
// cmd.Stdout = os.Stdout
40+
// cmd.Stderr = os.Stderr
41+
// err := cmd.Run()
42+
// checkError(err)
43+
//}
44+
45+
//func IsPointRelease(currentVersion string, newVersion string) bool {
46+
// // The first n-1 parts of the version should be the same
47+
// if currentVersion[:len(currentVersion)-2] != newVersion[:len(newVersion)-2] {
48+
// return false
49+
// }
50+
// // split on the last dot in the string
51+
// currentVersionSplit := strings.Split(currentVersion, ".")
52+
// newVersionSplit := strings.Split(newVersion, ".")
53+
// // if the last part of the version is the same, it's a point release
54+
// currentMinor := lo.Must(strconv.Atoi(currentVersionSplit[len(currentVersionSplit)-1]))
55+
// newMinor := lo.Must(strconv.Atoi(newVersionSplit[len(newVersionSplit)-1]))
56+
// return newMinor == currentMinor+1
57+
//}
58+
59+
func main() {
60+
var newVersion string
61+
if len(os.Args) > 1 {
62+
newVersion = os.Args[1]
63+
//currentVersion, err := os.ReadFile(versionFile)
64+
//checkError(err)
65+
err := os.WriteFile(versionFile, []byte(newVersion), 0o755)
66+
checkError(err)
67+
//isPointRelease = IsPointRelease(string(currentVersion), newVersion)
68+
} else {
69+
newVersion = updateVersion()
70+
}
71+
72+
// Update ChangeLog
73+
s.CD("../../../mkdocs-website")
74+
75+
// Read in `src/pages/changelog.mdx`
76+
changelogData, err := os.ReadFile("docs/en/changelog.md")
77+
checkError(err)
78+
changelog := string(changelogData)
79+
// Split on the line that has `## [Unreleased]`
80+
changelogSplit := strings.Split(changelog, "## [Unreleased]")
81+
// Get today's date in YYYY-MM-DD format
82+
today := time.Now().Format("2006-01-02")
83+
// Add the new version to the top of the changelog
84+
newChangelog := changelogSplit[0] + "## [Unreleased]\n\n## " + newVersion + " - " + today + changelogSplit[1]
85+
// Write the changelog back
86+
err = os.WriteFile("docs/en/changelog.md", []byte(newChangelog), 0o755)
87+
checkError(err)
88+
89+
// TODO: Documentation Versioning and Translations
90+
91+
//if !isPointRelease {
92+
// runCommand("npx", "-y", "pnpm", "install")
93+
//
94+
// s.ECHO("Generating new Docs for version: " + newVersion)
95+
//
96+
// runCommand("npx", "pnpm", "run", "docusaurus", "docs:version", newVersion)
97+
//
98+
// runCommand("npx", "pnpm", "run", "write-translations")
99+
//
100+
// // Load the version list/*
101+
// versionsData, err := os.ReadFile("versions.json")
102+
// checkError(err)
103+
// var versions []string
104+
// err = json.Unmarshal(versionsData, &versions)
105+
// checkError(err)
106+
// oldestVersion := versions[len(versions)-1]
107+
// s.ECHO(oldestVersion)
108+
// versions = versions[0 : len(versions)-1]
109+
// newVersions, err := json.Marshal(&versions)
110+
// checkError(err)
111+
// err = os.WriteFile("versions.json", newVersions, 0o755)
112+
// checkError(err)
113+
//
114+
// s.ECHO("Removing old version: " + oldestVersion)
115+
// s.CD("versioned_docs")
116+
// s.RMDIR("version-" + oldestVersion)
117+
// s.CD("../versioned_sidebars")
118+
// s.RM("version-" + oldestVersion + "-sidebars.json")
119+
// s.CD("..")
120+
//
121+
// runCommand("npx", "pnpm", "run", "build")
122+
//}
123+
}

0 commit comments

Comments
 (0)