Skip to content

Commit

Permalink
feat: added built at to version command (#94)
Browse files Browse the repository at this point in the history
* feat: added built at to version command

---------

Co-authored-by: John McBride <[email protected]>
  • Loading branch information
nickytonline and jpmcb authored Aug 27, 2024
1 parent 02b5925 commit 9960fc0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG VERSION
ARG SHA
ARG DATETIME

# Get the dependencies downloaded
WORKDIR /app
Expand All @@ -15,7 +16,8 @@ COPY . ./
# Build Go CLI binary
RUN go build -ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}'" \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o pizza .

# Runner layer
Expand Down
2 changes: 1 addition & 1 deletion cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewVersionCommand() *cobra.Command {
Use: "version",
Short: "Displays the build version of the CLI",
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("Version: %s\nSha: %s\n", utils.Version, utils.Sha)
fmt.Printf("Version: %s\nSha: %s\nBuilt at: %s\n", utils.Version, utils.Sha, utils.Datetime)
},
}
}
19 changes: 17 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ build:
echo "Building for local arch"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d %H:%M:%S")

go build \
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o build/pizza

install: build
Expand All @@ -26,6 +28,7 @@ build-darwin-amd64:
echo "Building darwin amd64"

export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d %H:%M:%S")
export CGO_ENABLED=0
export GOOS="darwin"
export GOARCH="amd64"
Expand All @@ -34,6 +37,7 @@ build-darwin-amd64:
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o build/pizza-${GOOS}-${GOARCH}

build-darwin-arm64:
Expand All @@ -42,6 +46,7 @@ build-darwin-arm64:
echo "Building darwin arm64"

export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d %H:%M:%S")
export CGO_ENABLED=0
export GOOS="darwin"
export GOARCH="arm64"
Expand All @@ -50,6 +55,7 @@ build-darwin-arm64:
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o build/pizza-${GOOS}-${GOARCH}

build-linux-amd64:
Expand All @@ -58,6 +64,7 @@ build-linux-amd64:
echo "Building linux amd64"

export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d %H:%M:%S")
export CGO_ENABLED=0
export GOOS="linux"
export GOARCH="amd64"
Expand All @@ -66,6 +73,7 @@ build-linux-amd64:
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o build/pizza-${GOOS}-${GOARCH}

build-linux-arm64:
Expand All @@ -74,6 +82,7 @@ build-linux-arm64:
echo "Building linux arm64"

export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d %H:%M:%S")
export CGO_ENABLED=0
export GOOS="linux"
export GOARCH="arm64"
Expand All @@ -82,6 +91,7 @@ build-linux-arm64:
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o build/pizza-${GOOS}-${GOARCH}

build-windows-amd64:
Expand All @@ -90,6 +100,7 @@ build-windows-amd64:
echo "Building windows amd64"

export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d %H:%M:%S")
export CGO_ENABLED=0
export GOOS="windows"
export GOARCH="amd64"
Expand All @@ -98,6 +109,7 @@ build-windows-amd64:
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o build/pizza-${GOOS}-${GOARCH}

build-windows-arm64:
Expand All @@ -106,6 +118,7 @@ build-windows-arm64:
echo "Building windows arm64"

export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d %H:%M:%S")
export CGO_ENABLED=0
export GOOS="windows"
export GOARCH="arm64"
Expand All @@ -114,13 +127,15 @@ build-windows-arm64:
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-o build/pizza-${GOOS}-${GOARCH}

# Builds the container and marks it tagged as "dev" locally
build-container:
docker build \
--build-arg VERSION=$(git describe --tags --always) \
--build-arg SHA=$(git rev-parse HEAD) \
--build-arg VERSION="$(git describe --tags --always)" \
--build-arg SHA="$(git rev-parse HEAD)" \
--build-arg DATETIME="$(date -u +'%Y-%m-%d %H:%M:%S')" \
-t pizza:dev .

clean:
Expand Down
5 changes: 3 additions & 2 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

var (
Version = "dev"
Sha = "HEAD"
Version = "dev"
Sha = "HEAD"
Datetime = "dev"
)

0 comments on commit 9960fc0

Please sign in to comment.