Skip to content

Commit 6425fae

Browse files
aybabtmeAntoine Grondin
authored andcommitted
set flags in goreleaser
1 parent 417d36d commit 6425fae

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

cmd/humanlog/main.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/signal"
1010
"runtime"
11+
"strconv"
1112

1213
"github.com/aybabtme/rgbterm"
1314
"github.com/blang/semver"
@@ -24,9 +25,26 @@ import (
2425
)
2526

2627
var (
27-
Version = &types.Version{Minor: 6}
28+
versionMajor string
29+
versionMinor string
30+
versionPatch string
31+
versionPrerelease string
32+
versionBuild string
33+
version = func() *types.Version {
34+
var prerelease []string
35+
if versionPrerelease != "" {
36+
prerelease = append(prerelease, versionPrerelease)
37+
}
38+
return &types.Version{
39+
Major: int32(mustatoi(versionMajor)),
40+
Minor: int32(mustatoi(versionMinor)),
41+
Patch: int32(mustatoi(versionPatch)),
42+
Prereleases: prerelease,
43+
Build: versionBuild,
44+
}
45+
}()
2846
semverVersion = func() semver.Version {
29-
v, err := Version.AsSemver()
47+
v, err := version.AsSemver()
3048
if err != nil {
3149
panic(err)
3250
}
@@ -195,7 +213,7 @@ func newApp() *cli.App {
195213
req := &checkForUpdateReq{
196214
arch: runtime.GOARCH,
197215
os: runtime.GOOS,
198-
current: Version,
216+
current: version,
199217
}
200218
if statefile != nil {
201219
if statefile.AccountID != nil {
@@ -212,7 +230,10 @@ func newApp() *cli.App {
212230
app.After = func(c *cli.Context) error {
213231
cancel()
214232
select {
215-
case res := <-updateRes:
233+
case res, ok := <-updateRes:
234+
if !ok {
235+
return nil
236+
}
216237
if semverVersion.LT(res.sem) {
217238
log.Printf("a new version of humanlog is available: please update")
218239
}
@@ -227,7 +248,7 @@ func newApp() *cli.App {
227248
}
228249
if updateStatefile {
229250
if err := state.WriteStateFile(stateFilepath, statefile); err != nil {
230-
log.Printf("failed to update statefile")
251+
log.Printf("failed to update statefile: %v", err)
231252
}
232253
}
233254
default:
@@ -339,7 +360,7 @@ func checkForUpdate(ctx context.Context, req *checkForUpdateReq) <-chan *checkFo
339360
updateClient := cliupdatev1connect.NewUpdateServiceClient(client, apiURL)
340361
res, err := updateClient.GetNextUpdate(ctx, &connect.Request[cliupdatepb.GetNextUpdateRequest]{
341362
Msg: &cliupdatepb.GetNextUpdateRequest{
342-
CurrentVersion: Version,
363+
CurrentVersion: version,
343364
AccountId: req.accountID,
344365
MachineId: req.machineID,
345366
MachineArchitecture: req.arch,
@@ -372,3 +393,11 @@ func checkForUpdate(ctx context.Context, req *checkForUpdateReq) <-chan *checkFo
372393
}()
373394
return out
374395
}
396+
397+
func mustatoi(a string) int {
398+
i, err := strconv.Atoi(a)
399+
if err != nil {
400+
panic(err)
401+
}
402+
return i
403+
}

goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ build:
22
main: ./cmd/humanlog/main.go
33
binary: humanlog
44
ldflags:
5-
- -s -w -X main.Version={{.Version}}
5+
- -s -w -X main.versionMajor={{.Major}} -X main.versionMinor={{.Minor}} -X main.versionPatch={{.Patch}} -X main.versionPrerelease={{.Prerelease}} -X main.versionBuild={{.ShortCommit}}
66
goos:
77
- windows
88
- darwin

0 commit comments

Comments
 (0)