Skip to content

Commit 2b38e11

Browse files
committed
feat: include version info in the binaries
1 parent f8c5228 commit 2b38e11

File tree

6 files changed

+69
-4
lines changed

6 files changed

+69
-4
lines changed

.github/workflows/binaries.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ jobs:
4242
- os: windows-latest
4343
asmnasm: C:\Users\runneradmin\nasm\nasm
4444
output: sointu-track.exe
45-
params: -ldflags -H=windowsgui cmd/sointu-track/main.go
45+
params: cmd/sointu-track/main.go
46+
ldflags: -H=windowsgui
4647
- os: windows-latest
4748
asmnasm: C:\Users\runneradmin\nasm\nasm
4849
output: sointu-compile.exe
4950
params: cmd/sointu-compile/main.go
5051
- os: windows-latest
5152
asmnasm: C:\Users\runneradmin\nasm\nasm
5253
output: sointu-track-native.exe
53-
params: -ldflags -H=windowsgui -tags=native cmd/sointu-track/main.go
54+
params: -tags=native cmd/sointu-track/main.go
55+
ldflags: -H=windowsgui
5456
- os: windows-latest
5557
asmnasm: C:\Users\runneradmin\nasm\nasm
5658
output: sointu-vsti.dll
@@ -103,6 +105,8 @@ jobs:
103105
length: 7
104106
- uses: lukka/get-cmake@latest
105107
- uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 0
106110
- uses: actions/setup-go@v5 # has to be after checkout, see https://medium.com/@s0k0mata/github-actions-and-go-the-new-cache-feature-in-actions-setup-go-v4-and-what-to-watch-out-for-aeea373ed07d
107111
with:
108112
go-version: '>=1.21.0'
@@ -122,7 +126,7 @@ jobs:
122126
ninja sointu
123127
- name: Build binary
124128
run: |
125-
go build -o ${{ matrix.config.output }} ${{ matrix.config.params }}
129+
go build -ldflags "-X github.com/vsariola/sointu/version.Version=$(git describe) ${{ matrix.config.ldflags}}" -o ${{ matrix.config.output }} ${{ matrix.config.params }}
126130
- name: Upload binary
127131
uses: actions/upload-artifact@v4
128132
with:

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

6+
## [Unreleased]
7+
### Added
8+
- Include version info in the binaries, as given be `git describe`. This version
9+
info is shown as a label in the tracker and can be checked with `-v` flag in
10+
the command line tools.
11+
612
## [0.4.1]
713
### Added
814
- Clicking the parameter slider also selects that parameter ([#112][i112])

cmd/sointu-compile/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"gopkg.in/yaml.v3"
1515

1616
"github.com/vsariola/sointu"
17+
"github.com/vsariola/sointu/version"
1718
"github.com/vsariola/sointu/vm/compiler"
1819
)
1920

@@ -43,8 +44,13 @@ func main() {
4344
targetArch := flag.String("arch", runtime.GOARCH, "Target architecture. Defaults to OS architecture. Possible values: 386, amd64, wasm")
4445
output16bit := flag.Bool("i", false, "Compiled song should output 16-bit integers, instead of floats.")
4546
targetOs := flag.String("os", runtime.GOOS, "Target OS. Defaults to current OS. Possible values: windows, darwin, linux. Anything else is assumed linuxy. Ignored when targeting wasm.")
47+
versionFlag := flag.Bool("v", false, "Print version.")
4648
flag.Usage = printUsage
4749
flag.Parse()
50+
if *versionFlag {
51+
fmt.Println(version.VersionOrHash)
52+
os.Exit(0)
53+
}
4854
if (flag.NArg() == 0 && !*library) || *help {
4955
flag.Usage()
5056
os.Exit(0)

cmd/sointu-play/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/vsariola/sointu"
1515
"github.com/vsariola/sointu/oto"
16+
"github.com/vsariola/sointu/version"
1617
"github.com/vsariola/sointu/vm/compiler/bridge"
1718
)
1819

@@ -27,8 +28,13 @@ func main() {
2728
rawOut := flag.Bool("r", false, "Output the rendered song as .raw file. By default, saves stereo float32 buffer to disk.")
2829
wavOut := flag.Bool("w", false, "Output the rendered song as .wav file. By default, saves stereo float32 buffer to disk.")
2930
pcm := flag.Bool("c", false, "Convert audio to 16-bit signed PCM when outputting.")
31+
versionFlag := flag.Bool("v", false, "Print version.")
3032
flag.Usage = printUsage
3133
flag.Parse()
34+
if *versionFlag {
35+
fmt.Println(version.VersionOrHash)
36+
os.Exit(0)
37+
}
3238
if flag.NArg() == 0 || *help {
3339
flag.Usage()
3440
os.Exit(0)

tracker/gioui/songpanel.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"gioui.org/unit"
1010
"gioui.org/widget"
1111
"github.com/vsariola/sointu/tracker"
12+
"github.com/vsariola/sointu/version"
1213
"golang.org/x/exp/shiny/materialdesign/icons"
1314
)
1415

@@ -92,7 +93,7 @@ func (t *SongPanel) layoutMenuBar(gtx C, tr *Tracker) D {
9293
gtx.Constraints.Max.Y = gtx.Dp(unit.Dp(36))
9394
gtx.Constraints.Min.Y = gtx.Dp(unit.Dp(36))
9495

95-
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
96+
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.End}.Layout(gtx,
9697
layout.Rigid(tr.layoutMenu(gtx, "File", &t.MenuBar[0], &t.Menus[0], unit.Dp(200), t.fileMenuItems...)),
9798
layout.Rigid(tr.layoutMenu(gtx, "Edit", &t.MenuBar[1], &t.Menus[1], unit.Dp(200), t.editMenuItems...)),
9899
)
@@ -181,5 +182,10 @@ func (t *SongPanel) layoutSongOptions(gtx C, tr *Tracker) D {
181182
)
182183
}),
183184
layout.Rigid(panicBtnStyle.Layout),
185+
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
186+
layout.Rigid(func(gtx C) D {
187+
labelStyle := LabelStyle{Text: version.VersionOrHash, FontSize: unit.Sp(12), Color: mediumEmphasisTextColor, Shaper: tr.Theme.Shaper}
188+
return labelStyle.Layout(gtx)
189+
}),
184190
)
185191
}

version/version.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package version
2+
3+
import "runtime/debug"
4+
5+
// You can set the version at build time using something like:
6+
// go build -ldflags "-X github.com/vsariola/sointu/version.Version=$(git describe --dirty)"
7+
8+
var Version string
9+
10+
var Hash = func() string {
11+
if info, ok := debug.ReadBuildInfo(); ok {
12+
modified := false
13+
for _, setting := range info.Settings {
14+
if setting.Key == "vcs.modified" && setting.Value == "true" {
15+
modified = true
16+
break
17+
}
18+
}
19+
for _, setting := range info.Settings {
20+
if setting.Key == "vcs.revision" {
21+
shortHash := setting.Value[:7]
22+
if modified {
23+
return shortHash + "-dirty"
24+
}
25+
return shortHash
26+
}
27+
}
28+
}
29+
return ""
30+
}()
31+
32+
var VersionOrHash = func() string {
33+
if Version != "" {
34+
return Version
35+
}
36+
return Hash
37+
}()

0 commit comments

Comments
 (0)