Skip to content

Commit

Permalink
Merge pull request #103 from nokia/porchctl-version
Browse files Browse the repository at this point in the history
Show git commit in `porchctl version`
  • Loading branch information
efiacor authored Sep 3, 2024
2 parents 2eb2dcc + eca68a6 commit 376321e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/porchctl-cli-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ jobs:
chmod: 0755
- name: Build and install porchctl
run: |
go build -o ${GITHUB_WORKSPACE}.build/ ./cmd/porchctl
mv ${GITHUB_WORKSPACE}.build/porchctl /usr/local/bin/porchctl
make porchctl
mv ${GITHUB_WORKSPACE}/.build/porchctl /usr/local/bin/porchctl
sudo chmod 755 /usr/local/bin/porchctl
porchctl version
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
with:
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CACHEDIR=$(CURDIR)/.cache
export DEPLOYPORCHCONFIGDIR ?= $(BUILDDIR)/deploy
DEPLOYKPTCONFIGDIR=$(BUILDDIR)/kpt_pkgs
PORCHDIR=$(abspath $(CURDIR))
PORCHCTL_VERSION := $(shell date '+development-%Y-%m-%dT%H:%M:%S')

# This includes the following targets:
# test, unit, unit-clean,
Expand Down Expand Up @@ -192,7 +193,7 @@ porch:

.PHONY: porchctl
porchctl:
go build -o $(PORCHCTL) ./cmd/porchctl
go build -ldflags="-X github.com/nephio-project/porch/cmd/porchctl/run.version=$(PORCHCTL_VERSION)" -o $(PORCHCTL) ./cmd/porchctl

.PHONY: fix-headers
fix-headers:
Expand Down
17 changes: 16 additions & 1 deletion cmd/porchctl/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"os/exec"
"runtime/debug"
"strconv"
"strings"

Expand Down Expand Up @@ -163,7 +164,21 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of porchctl",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s\n", version)
var hash, dirty string
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
hash = setting.Value
case "vcs.modified":
if strings.ToLower(setting.Value) == "true" {
dirty = " (dirty)"
}
}
}
}
fmt.Printf("Version: %s\n", version)
fmt.Printf("Git commit: %s%s\n", hash, dirty)
},
}

Expand Down

0 comments on commit 376321e

Please sign in to comment.