Skip to content

Commit 909309e

Browse files
authored
Add versioning for v1.0.0 (#11)
1 parent d1ee80d commit 909309e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Jenkinsfile

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ pipeline {
99
stage('Prepare') {
1010
steps {
1111
checkout scm
12+
sh 'git fetch --depth=500'
1213
sh 'go get github.com/mitchellh/gox'
13-
sh 'go get -u -v .'
14+
sh 'go get -d -u -v ./cmd/protoplex'
1415
sh 'mkdir -p builds'
1516
}
1617
}
@@ -19,7 +20,15 @@ pipeline {
1920
CGO_ENABLED = '0'
2021
}
2122
steps {
22-
sh 'gox -parallel=2 -ldflags="-s -w" -output="builds/{{.Dir}}_{{.OS}}_{{.Arch}}" ./cmd/protoplex'
23+
sh '''
24+
version="$(git describe --tags --abbrev=0 HEAD || true)"
25+
if [ -z "${version}" ]; then
26+
version="v0.0.0"
27+
fi
28+
build="$(git rev-parse --short HEAD)"
29+
fullver="${version}+${build}"
30+
gox -parallel=2 -ldflags="-s -w -X main.version=${fullver}" -output="builds/{{.Dir}}_{{.OS}}_{{.Arch}}" ./cmd/protoplex
31+
'''
2332
}
2433
}
2534
stage('Cleanup') {

cmd/protoplex/protoplex.go

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56

67
"github.com/Pandentia/protoplex/protoplex"
@@ -9,10 +10,24 @@ import (
910
"gopkg.in/alecthomas/kingpin.v2"
1011
)
1112

13+
var version string
14+
15+
func printVersion() {
16+
if version == "" {
17+
fmt.Println("Version has not been set.")
18+
os.Exit(1)
19+
return
20+
}
21+
fmt.Println(version)
22+
os.Exit(0)
23+
}
24+
1225
func main() {
1326
app := kingpin.New("protoplex", "A fast and simple protocol multiplexer.")
1427
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
1528

29+
version := app.Flag("version", "Prints the current program version").Short('V').Bool()
30+
1631
bind := app.Flag("bind", "The address to bind to").Short('b').Default("0.0.0.0:8443").String()
1732
verbose := app.Flag("verbose", "Enables debug logging").Short('v').Bool()
1833
pretty := app.Flag("pretty", "Enables pretty logging").Short('p').Bool()
@@ -27,6 +42,10 @@ func main() {
2742

2843
app.Parse(os.Args[1:])
2944

45+
if *version {
46+
printVersion()
47+
}
48+
3049
if *pretty {
3150
logger = logger.Output(zerolog.ConsoleWriter{Out: os.Stderr})
3251
}

0 commit comments

Comments
 (0)