Skip to content

Commit

Permalink
include version
Browse files Browse the repository at this point in the history
  • Loading branch information
rendom committed Nov 5, 2017
1 parent 78b05c4 commit d1ecd9f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ before_install:
- go get github.com/tcnksm/ghr
after_success:
- make clean
- GOOS=linux CC=arm-linux-gnueabihf-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 go build -v -o dist/linux_arm_mpdbot/mpdbot ./cmd/mpdbot
- CGO_ENABLED=1 go build -v -o dist/linux_amd64_mpdbot/mpdbot ./cmd/mpdbot
- make build-release
- for i in $(find dist -mindepth 1 -maxdepth 1 -type d); do cp {README.md,config.yml} $i; tar -czf "$i".tar.gz -C "$i" "."; done
- if [ "$TRAVIS_TAG" != "" ]; then ghr --username fulhax --token $GITHUB_TOKEN --replace $TRAVIS_TAG dist/; fi
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
exe = ./cmd/mpdbot

.PHONY: all build install test deps
VERSION = `git describe --tags`
BUILD_DATE=`date +%FT%T%z`
LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE}"

.PHONY: all build build-release install test deps

all: test clean build

Expand All @@ -13,6 +17,10 @@ clean:
build:
go build -v -o dist/mpdbot $(exe)

build-release:
GOOS=linux CC=arm-linux-gnueabihf-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 go build -v ${LDFLAGS} -o dist/linux_arm_mpdbot/mpdbot ./cmd/mpdbot
CGO_ENABLED=1 go build -v ${LDFLAGS} -o dist/linux_amd64_mpdbot/mpdbot ./cmd/mpdbot

install:
go install $(exe)

Expand Down
10 changes: 10 additions & 0 deletions cmd/mpdbot/mpdbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
"os"

"github.com/fulhax/mpdbot/handler"
"github.com/fulhax/mpdbot/irccmd"
Expand Down Expand Up @@ -33,6 +34,8 @@ var (
mpdClient *mpd.MpdClient
stats statistics.Storage
config mpdbotConfig
BuildDate string
Version string
)

func serveHTTP() {
Expand Down Expand Up @@ -86,6 +89,13 @@ func initConfig() {
}

func main() {
if Version != "" && BuildDate != "" {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s (%s %s):\n", os.Args[0], Version, BuildDate)
flag.PrintDefaults()
}
}

initConfig()

var err error
Expand Down

0 comments on commit d1ecd9f

Please sign in to comment.