Skip to content

Commit

Permalink
Merge pull request #146 from fission/include-git-version
Browse files Browse the repository at this point in the history
Include git info in versioning
  • Loading branch information
erwinvaneyk authored May 18, 2018
2 parents d793d36 + 4e19239 commit 46f1ae3
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 164 deletions.
8 changes: 4 additions & 4 deletions build/build-linux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
#!/usr/bin/env bash

rm -f ./fission-workflows-bundle ./wfcli
GOOS=linux GOARCH=386 go build github.com/fission/fission-workflows/cmd/fission-workflows-bundle/
GOOS=linux GOARCH=386 go build github.com/fission/fission-workflows/cmd/wfcli/
$(dirname $0)/build.sh --os linux --arch amd64 \
--output-bundle "fission-workflows-bundle" \
--output-cli "wfcli"
7 changes: 4 additions & 3 deletions build/build-osx.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#!/usr/bin/env bash

GOOS=darwin GOARCH=386 CGO_ENABLED=0 go build -o wfcli-osx github.com/fission/fission-workflows/cmd/wfcli/
GOOS=darwin GOARCH=386 CGO_ENABLED=0 go build -o fission-workflows-bundle-osx github.com/fission/fission-workflows/cmd/fission-workflows-bundle/
$(dirname $0)/build.sh --os darwin --arch 386 \
--output-bundle "fission-workflows-bundle-osx" \
--output-cli "wfcli-osx"
7 changes: 4 additions & 3 deletions build/build-windows.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#!/usr/bin/env bash

GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o fission-workflows-bundle-windows.exe github.com/fission/fission-workflows/cmd/fission-workflows-bundle/
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o wfcli-windows.exe github.com/fission/fission-workflows/cmd/wfcli/
$(dirname $0)/build.sh --os windows --arch 386 \
--output-bundle "fission-workflows-bundle-windows" \
--output-cli "wfcli-windows"
89 changes: 89 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail

# Constants
versionPath="github.com/fission/fission-workflows/pkg/version"

# Handle arguments
while [[ $# -gt 0 ]]; do
case $1 in
-d| --date)
date=$2
shift
;;
-c| --commit)
gitcommit=$2
shift
;;
-v| --version)
version=$2
shift
;;
--os)
goos=$2
shift
;;
--arch)
goarch=$2
shift
;;
--output-bundle)
output_bundle=$2
shift
;;
--output-cli)
output_cli=$2
shift
;;
-h| --help)
echo "usage: build.sh [-c commit] [-d date] [-v version] [--arch arch] [--os os] [--output-bundle name] [--output-cli name]"
exit 0;
esac
shift
done

# Set defaults
if [ -z ${version:-} ]; then
version=$(git rev-parse HEAD)
fi

if [ -z ${date:-} ] ; then
date=$(date -R)
fi

if [ -z ${gitcommit:-} ] ; then
gitcommit=$(git rev-parse HEAD)
fi
goos=${goos:-linux}
goarch=${goarch:-amd64}
output_cli=${output_cli:-wfcli}
output_bundle=${output_bundle:-fission-workflows-bundle}

echo "-------- Build config --------"
echo "version: ${version}"
echo "date: ${date}"
echo "commit: ${gitcommit}"
echo "goarch: ${goarch}"
echo "goos: ${goos}"
echo "output-cli: ${output_cli}"
echo "output-bundle: ${output_bundle}"
echo "------------------------------"

# Build client
CGO_ENABLED=0 GOOS=${goos} GOARCH=${goarch} go build \
-gcflags=-trimpath=${GOPATH} -asmflags=-trimpath=${GOPATH}\
-ldflags '-X "${versionPath}.BuildDate=${date}"'\
-o ${output_cli}\
github.com/fission/fission-workflows/cmd/wfcli/
echo "$(pwd)/${output_cli}"

# Build bundle
CGO_ENABLED=0 GOOS=${goos} GOARCH=${goarch} go build\
-gcflags=-trimpath=${GOPATH} -asmflags=-trimpath=${GOPATH}\
-ldflags '-X "${versionPath}.BuildDate=${date}"'\
-o ${output_bundle}\
github.com/fission/fission-workflows/cmd/fission-workflows-bundle/
echo "$(pwd)/${output_bundle}"
2 changes: 1 addition & 1 deletion cmd/fission-workflows-bundle/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type FissionOptions struct {

// Run serves enabled components in a blocking way
func Run(ctx context.Context, opts *Options) error {
log.WithField("version", version.VERSION).Info("Starting bundle...")
log.WithField("version", version.VersionInfo()).Info("Starting bundle...")

var es fes.Backend
var esPub pubsub.Publisher
Expand Down
2 changes: 1 addition & 1 deletion cmd/wfcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
app := cli.NewApp()
app.Author = "Erwin van Eyk"
app.Email = "[email protected]"
app.Version = version.VERSION
app.Version = version.Version
app.EnableBashCompletion = true
app.Usage = "Fission Workflows CLI"
app.Description = "CLI for Fission Workflows"
Expand Down
4 changes: 2 additions & 2 deletions cmd/wfcli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var versionPrinter = commandContext(func(ctx Context) error {

// Print client version
if c {
fmt.Printf("client: %s\n", version.VERSION)
fmt.Printf("client: %s\n", version.VersionInfo().Json())
}

// Print server version
Expand All @@ -27,7 +27,7 @@ var versionPrinter = commandContext(func(ctx Context) error {
if err != nil {
fmt.Printf("server: failed to get version (%v)\n", err)
} else {
fmt.Printf("server: %s\n", resp.Version)
fmt.Printf("server: %s\n", resp)
}
}
return nil
Expand Down
6 changes: 6 additions & 0 deletions hack/codegen-golang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

gopath=`find pkg -type f -name "*.go" | xargs -n 1 dirname | sort --unique`
while read -r path; do
(cd ${path} && go generate -x)
done <<< "$gopath"
26 changes: 8 additions & 18 deletions hack/codegen-grpc.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
#!/bin/bash

set -e
set -o nounset
set -o errexit
set -o pipefail

protopaths=`find pkg -type f -name "*.proto"`
while read -r path; do
echo "Generating golang implementations for proto-file: $path"
echo "$path"
protoc -I . \
-I /usr/local/include \
-I ./pkg/ \
-I $GOPATH/src \
-I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I ${GOPATH}/src \
-I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--proto_path=.\
--go_out=plugins=grpc:.\
--grpc-gateway_out=logtostderr=true:. \
${path}
done <<< "$protopaths"

echo "Generating golang HTTP gateway for proto-file: pkg/apiserver/apiserver.proto"
protoc -I . \
-I/usr/local/include \
-I ./pkg/ \
-I $GOPATH/src \
-I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--grpc-gateway_out=logtostderr=true:. \
--go_out=plugins=grpc:. \
pkg/apiserver/apiserver.proto

done <<< "$protopaths"
82 changes: 82 additions & 0 deletions hack/codegen-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

# Handle arguments
while [[ $# -gt 0 ]]; do
case $1 in
-d| --date)
GIT_DATE=$2
shift
;;
-c| --commit)
GIT_COMMIT=$2
shift
;;
-v| --version)
VERSION=$2
shift
;;
-o| --output)
OUTPUT=$2
shift
;;
-h| --help)
echo "usage: codegen-version.sh [-c commit] [-d RFC3339] [-v version]"
exit 0;
esac
shift
done

if [ -z ${VERSION:-} ]; then
VERSION=$(git rev-parse HEAD)
fi

if [ -z ${GIT_DATE:-} ] ; then
# or use `date -R`
GIT_DATE=$(git show -s --format="%cD" HEAD)
fi

if [ -z ${GIT_COMMIT:-} ] ; then
GIT_COMMIT=$(git rev-parse HEAD)
fi

read -r -d '' VERSION << EOM
// Code generated by hack/codegen-version.sh. DO NOT EDIT.
package version
import "time"
const (
dateFormat string = time.RFC1123Z
// Git commit (e.g. 1b4716ab84903b2e477135a3dc5afdb07f685cb7)
GitCommit string = "${GIT_COMMIT}"
// Version contains a (potentially) human-readable version
// For example 1.1.0 or 1b4716ab84903b2e477135a3dc5afdb07f685cb7
Version string = "${VERSION}"
// gitDate is a date in RFC1123Z format
gitDate string = "${GIT_DATE}"
)
var (
GitDate time.Time
)
func init() {
d, err := time.Parse(dateFormat, gitDate)
if err != nil {
panic(err)
}
GitDate = d
}
EOM

if [ -z ${OUTPUT:-} ] ; then
echo "${VERSION}"
else
echo "${VERSION}" > ${OUTPUT}
fi
7 changes: 3 additions & 4 deletions pkg/apiserver/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ func (as *GrpcAdminApiServer) Status(ctx context.Context, _ *empty.Empty) (*Heal
}, nil
}

func (as *GrpcAdminApiServer) Version(ctx context.Context, _ *empty.Empty) (*VersionResp, error) {
return &VersionResp{
Version: version.VERSION,
}, nil
func (as *GrpcAdminApiServer) Version(ctx context.Context, _ *empty.Empty) (*version.Info, error) {
version := version.VersionInfo()
return &version, nil
}

func (as *GrpcAdminApiServer) Resume(context.Context, *empty.Empty) (*empty.Empty, error) {
Expand Down
Loading

0 comments on commit 46f1ae3

Please sign in to comment.