Skip to content

Commit

Permalink
Add versioning for v1.0.0 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
SapphicCode authored Oct 1, 2019
1 parent d1ee80d commit 909309e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ pipeline {
stage('Prepare') {
steps {
checkout scm
sh 'git fetch --depth=500'
sh 'go get github.com/mitchellh/gox'
sh 'go get -u -v .'
sh 'go get -d -u -v ./cmd/protoplex'
sh 'mkdir -p builds'
}
}
Expand All @@ -19,7 +20,15 @@ pipeline {
CGO_ENABLED = '0'
}
steps {
sh 'gox -parallel=2 -ldflags="-s -w" -output="builds/{{.Dir}}_{{.OS}}_{{.Arch}}" ./cmd/protoplex'
sh '''
version="$(git describe --tags --abbrev=0 HEAD || true)"
if [ -z "${version}" ]; then
version="v0.0.0"
fi
build="$(git rev-parse --short HEAD)"
fullver="${version}+${build}"
gox -parallel=2 -ldflags="-s -w -X main.version=${fullver}" -output="builds/{{.Dir}}_{{.OS}}_{{.Arch}}" ./cmd/protoplex
'''
}
}
stage('Cleanup') {
Expand Down
19 changes: 19 additions & 0 deletions cmd/protoplex/protoplex.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/Pandentia/protoplex/protoplex"
Expand All @@ -9,10 +10,24 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

var version string

func printVersion() {
if version == "" {
fmt.Println("Version has not been set.")
os.Exit(1)
return
}
fmt.Println(version)
os.Exit(0)
}

func main() {
app := kingpin.New("protoplex", "A fast and simple protocol multiplexer.")
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()

version := app.Flag("version", "Prints the current program version").Short('V').Bool()

bind := app.Flag("bind", "The address to bind to").Short('b').Default("0.0.0.0:8443").String()
verbose := app.Flag("verbose", "Enables debug logging").Short('v').Bool()
pretty := app.Flag("pretty", "Enables pretty logging").Short('p').Bool()
Expand All @@ -27,6 +42,10 @@ func main() {

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

if *version {
printVersion()
}

if *pretty {
logger = logger.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
Expand Down

0 comments on commit 909309e

Please sign in to comment.