Skip to content

Commit

Permalink
Feature auto-gen version string
Browse files Browse the repository at this point in the history
  • Loading branch information
kimw committed Apr 10, 2018
1 parent 27fac11 commit 80a4bb6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
default: all

client:
update-version:
./update-version.sh

client: update-version
go get github.com/cbeuw/gotfo
go build -o ./build/gq-client ./cmd/gq-client

server:
server: update-version
go get github.com/cbeuw/gotfo
go build -o ./build/gq-server ./cmd/gq-server

Expand Down
5 changes: 2 additions & 3 deletions cmd/gq-client/gq-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cbeuw/GoQuiet/gqclient"
"github.com/cbeuw/GoQuiet/gqclient/TLS"
"github.com/cbeuw/gotfo"
"fmt"
"io"
"log"
"net"
Expand Down Expand Up @@ -134,8 +135,6 @@ func initSequence(ssConn net.Conn, sta *gqclient.State) {

}

var version string

func main() {
// Should be 127.0.0.1 to listen to ss-local on this machine
var localHost string
Expand Down Expand Up @@ -167,7 +166,7 @@ func main() {
flag.Parse()

if *askVersion {
log.Println("gq-client version: " + version)
fmt.Printf("gq-client %s\n", version)
return
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/gq-client/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

const version = "master"
5 changes: 2 additions & 3 deletions cmd/gq-server/gq-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"flag"
"github.com/cbeuw/GoQuiet/gqserver"
"github.com/cbeuw/gotfo"
"fmt"
"io"
"log"
"net"
Expand Down Expand Up @@ -197,8 +198,6 @@ func usedRandomCleaner(sta *gqserver.State) {
}
}

var version string

func main() {
// Should be 127.0.0.1 to listen to ss-server on this machine
var localHost string
Expand All @@ -224,7 +223,7 @@ func main() {
flag.Parse()

if *askVersion {
log.Println("gq-server verison: " + version)
fmt.Printf("gq-server %s\n", version)
return
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/gq-server/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

const version = "master"
9 changes: 9 additions & 0 deletions update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

ver=$(git log -n 1 --pretty=oneline --format=%D | awk -F, '{print $1}' | awk '{print $3}')
if [ "$ver" = "master" ]
then
ver="master ($(git log -n 1 --pretty=oneline --format=%h))"
fi
sed -i "s/^const version = .*$/const version = \"$ver\"/" cmd/gq-server/version.go
sed -i "s/^const version = .*$/const version = \"$ver\"/" cmd/gq-client/version.go

0 comments on commit 80a4bb6

Please sign in to comment.