Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show git commit in porchctl version #103

Merged
merged 3 commits into from
Sep 3, 2024

Conversation

kispaljr
Copy link
Collaborator

@kispaljr kispaljr commented Sep 2, 2024

No description provided.

@liamfallon
Copy link
Member

liamfallon commented Sep 2, 2024

I think adding the git commit is very useful. But maybe we could also set the version itself.

This change will do it:

diff --git a/Makefile b/Makefile
index e6b7d32..a9b771a 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,8 @@ export DEPLOYPORCHCONFIGDIR ?= $(BUILDDIR)/deploy
 DEPLOYKPTCONFIGDIR=$(BUILDDIR)/kpt_pkgs
 PORCHDIR=$(abspath $(CURDIR))
 
+PORCHCTL_VERSION := $(shell date | sed -e 's/\s/_/g' -e 's/^/development:/')
+
 # This includes the following targets:
 #   test, unit, unit-clean,
 #   gosec, lint,
@@ -192,7 +194,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:

Here, we are using the current date to set the PORCHCTL_VERSION env var but we could set that using some more official method.

The line var version = "unknown" here creates a global constant called github.com/nephio-project/porch/cmd/porchctl/run.version

var version = "unknown"

You can examine the contants in the built porchctl binary just like in c with:
nm -ax build/porchctl | grep '\.version'

Then you build porchctl and set the value of the global constant at link time as follows:

go build -ldflags="-X github.com/nephio-project/porch/cmd/porchctl/run.version=1.2.3" -o build/porchctl ./cmd/porchctl
liam@saor porch % build/porchctl version                                                                                         
Version: 1.2.3
Git commit: 4ccec7d01918b599f59eca99f44c002a85ca88df (dirty)

@kispaljr
Copy link
Collaborator Author

kispaljr commented Sep 3, 2024

thanks @liamfallon, it is a good idea to set the version not just during the release process, but also on every build. I've modified the Makefile as you suggested.

@liamfallon
Copy link
Member

thanks @liamfallon, it is a good idea to set the version not just during the release process, but also on every build. I've modified the Makefile as you suggested.

I was looking for this yesterday, you solved my puzzlement as to how the version was set during the release!

@efiacor
Copy link
Collaborator

efiacor commented Sep 3, 2024

/approve

@nephio-prow nephio-prow bot added the approved label Sep 3, 2024
Copy link
Member

@liamfallon liamfallon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to merge this so we can figure out if the correct Porch version is being used in the failing e2e tests.

/approve
/lgtm

Copy link
Contributor

nephio-prow bot commented Sep 3, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: efiacor, kispaljr, liamfallon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@efiacor
Copy link
Collaborator

efiacor commented Sep 3, 2024

/retest

2 similar comments
@efiacor
Copy link
Collaborator

efiacor commented Sep 3, 2024

/retest

@liamfallon
Copy link
Member

/retest

@efiacor efiacor merged commit 376321e into nephio-project:main Sep 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants