forked from MirrorHub/mautrix-whatsapp
Include commit information in CI builds. Fixes #158
This commit is contained in:
parent
7b75d763ed
commit
09385713de
5 changed files with 59 additions and 6 deletions
|
@ -14,8 +14,9 @@ stages:
|
||||||
- apk add build-base olm-dev@edge_community
|
- apk add build-base olm-dev@edge_community
|
||||||
- mkdir -p .cache
|
- mkdir -p .cache
|
||||||
- export GOPATH="$CI_PROJECT_DIR/.cache"
|
- export GOPATH="$CI_PROJECT_DIR/.cache"
|
||||||
|
- export GO_LDFLAGS="-X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_REF_NAME -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'"
|
||||||
script:
|
script:
|
||||||
- go build -o mautrix-whatsapp
|
- go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- mautrix-whatsapp
|
- mautrix-whatsapp
|
||||||
|
@ -43,13 +44,14 @@ build static:
|
||||||
before_script:
|
before_script:
|
||||||
- mkdir -p .cache
|
- mkdir -p .cache
|
||||||
- export GOPATH="$CI_PROJECT_DIR/.cache"
|
- export GOPATH="$CI_PROJECT_DIR/.cache"
|
||||||
|
- export GO_LDFLAGS="-X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_REF_NAME -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'"
|
||||||
variables:
|
variables:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
script:
|
script:
|
||||||
- GOOS=linux GOARCH=amd64 go build -o mautrix-whatsapp_linux_amd64
|
- GOOS=linux GOARCH=amd64 go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_amd64
|
||||||
- GOOS=linux GOARCH=arm64 go build -o mautrix-whatsapp_linux_arm64
|
- GOOS=linux GOARCH=arm64 go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_arm64
|
||||||
- GOOS=linux GOARCH=arm go build -o mautrix-whatsapp_linux_arm
|
- GOOS=linux GOARCH=arm go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_arm
|
||||||
- GOOS=linux GOARCH=386 go build -o mautrix-whatsapp_linux_386
|
- GOOS=linux GOARCH=386 go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_386
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- mautrix-whatsapp_linux_amd64
|
- mautrix-whatsapp_linux_amd64
|
||||||
|
|
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'`'" "$@"
|
17
commands.go
17
commands.go
|
@ -105,6 +105,8 @@ func (handler *CommandHandler) CommandMux(ce *CommandEvent) {
|
||||||
handler.CommandLogoutMatrix(ce)
|
handler.CommandLogoutMatrix(ce)
|
||||||
case "help":
|
case "help":
|
||||||
handler.CommandHelp(ce)
|
handler.CommandHelp(ce)
|
||||||
|
case "version":
|
||||||
|
handler.CommandVersion(ce)
|
||||||
case "reconnect":
|
case "reconnect":
|
||||||
handler.CommandReconnect(ce)
|
handler.CommandReconnect(ce)
|
||||||
case "disconnect":
|
case "disconnect":
|
||||||
|
@ -174,6 +176,21 @@ func (handler *CommandHandler) CommandDevTest(_ *CommandEvent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cmdVersionHelp = `version - View the bridge version`
|
||||||
|
|
||||||
|
func (handler *CommandHandler) CommandVersion(ce *CommandEvent) {
|
||||||
|
version := fmt.Sprintf("%s+dev.unknown", Version)
|
||||||
|
if Tag == Version {
|
||||||
|
version = fmt.Sprintf("[%s](%s/releases/%s) (%s)", Version, URL, Tag, BuildTime)
|
||||||
|
} else if len(Commit) > 8 {
|
||||||
|
if !strings.HasSuffix(Version, "+dev") {
|
||||||
|
Version += "+dev"
|
||||||
|
}
|
||||||
|
version = fmt.Sprintf("%s.[%s](%s/commit/%s) (%s)", Version, Commit[:8], URL, Commit, BuildTime)
|
||||||
|
}
|
||||||
|
ce.Reply(fmt.Sprintf("[%s](%s) %s", Name, URL, version))
|
||||||
|
}
|
||||||
|
|
||||||
const cmdSetPowerLevelHelp = `set-pl [user ID] <power level> - Change the power level in a portal room. Only for bridge admins.`
|
const cmdSetPowerLevelHelp = `set-pl [user ID] <power level> - Change the power level in a portal room. Only for bridge admins.`
|
||||||
|
|
||||||
func (handler *CommandHandler) CommandSetPowerLevel(ce *CommandEvent) {
|
func (handler *CommandHandler) CommandSetPowerLevel(ce *CommandEvent) {
|
||||||
|
|
32
main.go
32
main.go
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -38,11 +39,30 @@ import (
|
||||||
"maunium.net/go/mautrix-whatsapp/types"
|
"maunium.net/go/mautrix-whatsapp/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// These are static
|
||||||
|
Name = "mautrix-whatsapp"
|
||||||
|
URL = "https://github.com/tulir/mautrix-whatsapp"
|
||||||
|
// This is changed when making a release
|
||||||
|
Version = "0.1.0+dev"
|
||||||
|
// These are filled at build time with the -X linker flag
|
||||||
|
Tag = "unknown"
|
||||||
|
Commit = "unknown"
|
||||||
|
BuildTime = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if len(Tag) > 0 && Tag[0] == 'v' {
|
||||||
|
Tag = Tag[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String()
|
var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String()
|
||||||
|
|
||||||
//var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String()
|
//var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String()
|
||||||
var registrationPath = flag.MakeFull("r", "registration", "The path where to save the appservice registration.", "registration.yaml").String()
|
var registrationPath = flag.MakeFull("r", "registration", "The path where to save the appservice registration.", "registration.yaml").String()
|
||||||
var generateRegistration = flag.MakeFull("g", "generate-registration", "Generate registration and quit.", "false").Bool()
|
var generateRegistration = flag.MakeFull("g", "generate-registration", "Generate registration and quit.", "false").Bool()
|
||||||
|
var version = flag.MakeFull("v", "version", "View bridge version and quit.", "false").Bool()
|
||||||
var ignoreUnsupportedDatabase = flag.Make().LongKey("ignore-unsupported-database").Usage("Run even if database is too new").Default("false").Bool()
|
var ignoreUnsupportedDatabase = flag.Make().LongKey("ignore-unsupported-database").Usage("Run even if database is too new").Default("false").Bool()
|
||||||
var migrateFrom = flag.Make().LongKey("migrate-db").Usage("Source database type and URI to migrate from.").Bool()
|
var migrateFrom = flag.Make().LongKey("migrate-db").Usage("Source database type and URI to migrate from.").Bool()
|
||||||
var wantHelp, _ = flag.MakeHelpFlag()
|
var wantHelp, _ = flag.MakeHelpFlag()
|
||||||
|
@ -347,6 +367,18 @@ func (bridge *Bridge) Main() {
|
||||||
} else if *migrateFrom {
|
} else if *migrateFrom {
|
||||||
bridge.MigrateDatabase()
|
bridge.MigrateDatabase()
|
||||||
return
|
return
|
||||||
|
} else if *version {
|
||||||
|
if Tag == Version {
|
||||||
|
fmt.Printf("%s %s (%s)\n", Name, Tag, BuildTime)
|
||||||
|
} else if len(Commit) > 8 {
|
||||||
|
if !strings.HasSuffix(Version, "+dev") {
|
||||||
|
Version += "+dev"
|
||||||
|
}
|
||||||
|
fmt.Printf("%s %s.%s (%s)\n", Name, Version, Commit[:8], BuildTime)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s %s+dev.unknown\n", Name, Version)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge.Init()
|
bridge.Init()
|
||||||
|
|
2
user.go
2
user.go
|
@ -235,7 +235,7 @@ func (user *User) Connect(evenIfNoSession bool) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
user.Conn = whatsappExt.ExtendConn(conn)
|
user.Conn = whatsappExt.ExtendConn(conn)
|
||||||
_ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa", "0.1.0")
|
_ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa", Version)
|
||||||
user.log.Debugln("WhatsApp connection successful")
|
user.log.Debugln("WhatsApp connection successful")
|
||||||
user.Conn.AddHandler(user)
|
user.Conn.AddHandler(user)
|
||||||
return user.RestoreSession()
|
return user.RestoreSession()
|
||||||
|
|
Loading…
Reference in a new issue