Skip to content

Commit

Permalink
Adding improved version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jkueh committed Apr 16, 2024
1 parent 034e84b commit d1b99da
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
on:
push:
tags: ['v*']
tags-ignore: ['v*-beta*']

name: Create Release

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM golang:1.19 as builder

ARG roo_version="unknown"

WORKDIR /go/src/github.com/zerocube/roo

Expand All @@ -15,7 +16,7 @@ RUN go test -v ./...

# -s and -w will strip out debugging information
# From https://blog.filippo.io/shrink-your-go-binaries-with-this-one-weird-trick/
RUN go build -ldflags "-s -w" -o /roo -v .
RUN go build -ldflags "-s -w -X 'main.rooVersion=${roo_version}'" -o /roo -v .

ENTRYPOINT ["go", "run", "."]

Expand Down
18 changes: 14 additions & 4 deletions auto/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

set -eu

GOOS="${GOOS:-linux}"
GOARCH="${GOARCH:-amd64}"
GITHUB_REF="${GITHUB_REF:-""}"
GIT_SHA="$(git rev-parse --verify HEAD)"

function getVersion() {
if [ ! -z "${GITHUB_REF_NAME}" ]; then
echo "${GITHUB_REF_NAME}"
elif [ ! -z "${GIT_SHA}" ]; then
echo "${GIT_SHA}"
else
echo "unknown"
fi
}

ROO_VERSION="$(getVersion)"

function buildCommand() {
OUTPUT_PATH="build/roo_${GOOS}_${GOARCH}"
echo "Building: ${OUTPUT_PATH}"
go build -v \
-ldflags \
"-X 'main.cacheDir=${CACHE_DIR:-""}' -X 'main.version=${GITHUB_REF##*/}'" \
"-X 'main.cacheDir=${CACHE_DIR:-""}' -X 'main.rooVersion=${ROO_VERSION}'" \
-o "${OUTPUT_PATH}${FILE_EXT:-""}" \
"${@}"
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/aws/aws-sdk-go/service/sts"
)

const rooVersion = "0.3.1"
var rooVersion string

var debug bool
var verbose bool
Expand Down Expand Up @@ -71,8 +71,8 @@ func main() {
config.Debug, config.Verbose = debug, verbose

if showVersionInfo {
if verbose {
fmt.Println("Roo version", rooVersion)
if rooVersion == "" {
fmt.Println("unknown_version")
} else {
fmt.Println(rooVersion)
}
Expand Down

0 comments on commit d1b99da

Please sign in to comment.