Add more details to --version
This commit is contained in:
parent
b755302b93
commit
c45a66bbf9
@ -13,8 +13,10 @@ cache:
|
||||
|
||||
.build-linux: &build-linux
|
||||
stage: build
|
||||
before_script:
|
||||
- export GO_LDFLAGS="-s -w -linkmode external -extldflags -static -X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_SHA -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'"
|
||||
script:
|
||||
- go build -ldflags "-linkmode external -extldflags -static" -o gomuks
|
||||
- go build -o gomuks
|
||||
artifacts:
|
||||
paths:
|
||||
- gomuks
|
||||
@ -35,7 +37,7 @@ windows/amd64:
|
||||
image: dock.mau.dev/tulir/gomuks-build-docker:windows-amd64
|
||||
stage: build
|
||||
script:
|
||||
- go build -ldflags "-linkmode external -extldflags -static" -o gomuks.exe
|
||||
- go build -o gomuks.exe
|
||||
artifacts:
|
||||
paths:
|
||||
- gomuks.exe
|
||||
@ -45,7 +47,8 @@ macos/amd64:
|
||||
tags:
|
||||
- macos
|
||||
- amd64
|
||||
before_script: []
|
||||
before_script:
|
||||
- export GO_LDFLAGS="-X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_SHA -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'"
|
||||
script:
|
||||
- mkdir gomuks-macos-amd64
|
||||
- go build -o gomuks-macos-amd64/gomuks
|
||||
@ -66,6 +69,7 @@ macos/arm64:
|
||||
- export LIBRARY_PATH=/opt/homebrew/lib
|
||||
- export CPATH=/opt/homebrew/include
|
||||
- export PATH=/opt/homebrew/bin:$PATH
|
||||
- export GO_LDFLAGS="-X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_SHA -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'"
|
||||
script:
|
||||
- mkdir gomuks-macos-arm64
|
||||
- go build -o gomuks-macos-arm64/gomuks
|
||||
|
2
build.sh
Executable file
2
build.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
go build -ldflags "-X main.Tag=$(git describe --exact-match --tags 2>/dev/null) -X main.Commit=$(git rev-parse HEAD) -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'" "$@"
|
37
gomuks.go
37
gomuks.go
@ -17,8 +17,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@ -28,6 +30,39 @@ import (
|
||||
"maunium.net/go/gomuks/matrix"
|
||||
)
|
||||
|
||||
// Information to find out exactly which commit gomuks was built from.
|
||||
// These are filled at build time with the -X linker flag.
|
||||
var (
|
||||
Tag = "unknown"
|
||||
Commit = "unknown"
|
||||
BuildTime = "unknown"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version is the version number of gomuks. Changed manually when making a release.
|
||||
Version = "0.2.4"
|
||||
// VersionString is the gomuks version, plus commit information. Filled in init() using the build-time values.
|
||||
VersionString = ""
|
||||
)
|
||||
|
||||
func init() {
|
||||
if len(Tag) > 0 && Tag[0] == 'v' {
|
||||
Tag = Tag[1:]
|
||||
}
|
||||
if Tag != Version {
|
||||
suffix := ""
|
||||
if !strings.HasSuffix(Version, "+dev") {
|
||||
suffix = "+dev"
|
||||
}
|
||||
if len(Commit) > 8 {
|
||||
Version = fmt.Sprintf("%s%s.%s", Version, suffix, Commit[:8])
|
||||
} else {
|
||||
Version = fmt.Sprintf("%s%s.unknown", Version, suffix)
|
||||
}
|
||||
}
|
||||
VersionString = fmt.Sprintf("gomuks %s (%s)", Version, BuildTime)
|
||||
}
|
||||
|
||||
// Gomuks is the wrapper for everything.
|
||||
type Gomuks struct {
|
||||
ui ifc.GomuksUI
|
||||
@ -56,7 +91,7 @@ func NewGomuks(uiProvider ifc.UIProvider, configDir, dataDir, cacheDir, download
|
||||
}
|
||||
|
||||
func (gmx *Gomuks) Version() string {
|
||||
return "v0.2.4"
|
||||
return Version
|
||||
}
|
||||
|
||||
// Save saves the active session and message history.
|
||||
|
2
main.go
2
main.go
@ -82,7 +82,7 @@ func main() {
|
||||
gmx := NewGomuks(MainUIProvider, configDir, dataDir, cacheDir, downloadDir)
|
||||
|
||||
if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "-v") {
|
||||
fmt.Printf("gomuks version %s\n", gmx.Version())
|
||||
fmt.Println(VersionString)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ func (c *Container) InitClient() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create mautrix client: %w", err)
|
||||
}
|
||||
c.client.UserAgent = fmt.Sprintf("gomuks %s (with mautrix-go %s)", c.gmx.Version(), mautrix.Version)
|
||||
c.client.UserAgent = fmt.Sprintf("gomuks/%s %s", c.gmx.Version(), mautrix.DefaultUserAgent)
|
||||
c.client.Logger = mxLogger{}
|
||||
c.client.DeviceID = c.config.DeviceID
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user