Skip to content

Commit

Permalink
set flags in goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme authored and Antoine Grondin committed Jan 14, 2023
1 parent 417d36d commit 6425fae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
41 changes: 35 additions & 6 deletions cmd/humanlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/signal"
"runtime"
"strconv"

"github.com/aybabtme/rgbterm"
"github.com/blang/semver"
Expand All @@ -24,9 +25,26 @@ import (
)

var (
Version = &types.Version{Minor: 6}
versionMajor string
versionMinor string
versionPatch string
versionPrerelease string
versionBuild string
version = func() *types.Version {
var prerelease []string
if versionPrerelease != "" {
prerelease = append(prerelease, versionPrerelease)
}
return &types.Version{
Major: int32(mustatoi(versionMajor)),
Minor: int32(mustatoi(versionMinor)),
Patch: int32(mustatoi(versionPatch)),
Prereleases: prerelease,
Build: versionBuild,
}
}()
semverVersion = func() semver.Version {
v, err := Version.AsSemver()
v, err := version.AsSemver()
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -195,7 +213,7 @@ func newApp() *cli.App {
req := &checkForUpdateReq{
arch: runtime.GOARCH,
os: runtime.GOOS,
current: Version,
current: version,
}
if statefile != nil {
if statefile.AccountID != nil {
Expand All @@ -212,7 +230,10 @@ func newApp() *cli.App {
app.After = func(c *cli.Context) error {
cancel()
select {
case res := <-updateRes:
case res, ok := <-updateRes:
if !ok {
return nil
}
if semverVersion.LT(res.sem) {
log.Printf("a new version of humanlog is available: please update")
}
Expand All @@ -227,7 +248,7 @@ func newApp() *cli.App {
}
if updateStatefile {
if err := state.WriteStateFile(stateFilepath, statefile); err != nil {
log.Printf("failed to update statefile")
log.Printf("failed to update statefile: %v", err)
}
}
default:
Expand Down Expand Up @@ -339,7 +360,7 @@ func checkForUpdate(ctx context.Context, req *checkForUpdateReq) <-chan *checkFo
updateClient := cliupdatev1connect.NewUpdateServiceClient(client, apiURL)
res, err := updateClient.GetNextUpdate(ctx, &connect.Request[cliupdatepb.GetNextUpdateRequest]{
Msg: &cliupdatepb.GetNextUpdateRequest{
CurrentVersion: Version,
CurrentVersion: version,
AccountId: req.accountID,
MachineId: req.machineID,
MachineArchitecture: req.arch,
Expand Down Expand Up @@ -372,3 +393,11 @@ func checkForUpdate(ctx context.Context, req *checkForUpdateReq) <-chan *checkFo
}()
return out
}

func mustatoi(a string) int {
i, err := strconv.Atoi(a)
if err != nil {
panic(err)
}
return i
}
2 changes: 1 addition & 1 deletion goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build:
main: ./cmd/humanlog/main.go
binary: humanlog
ldflags:
- -s -w -X main.Version={{.Version}}
- -s -w -X main.versionMajor={{.Major}} -X main.versionMinor={{.Minor}} -X main.versionPatch={{.Patch}} -X main.versionPrerelease={{.Prerelease}} -X main.versionBuild={{.ShortCommit}}
goos:
- windows
- darwin
Expand Down

0 comments on commit 6425fae

Please sign in to comment.