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

Allow the override of all version package variables #61

Merged
merged 1 commit into from
Jul 21, 2022

Conversation

saschagrunert
Copy link
Member

@saschagrunert saschagrunert commented Jul 14, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

This now makes it possible to override all variables via the -X ldflag, for example:

package main

import (
	"fmt"

	"sigs.k8s.io/release-utils/version"
)

func main() {
	v := version.GetVersionInfo()
	fmt.Print(v.String())
}
> go run -ldflags '\
    -X sigs.k8s.io/release-utils/version.gitVersion=1 \
    -X sigs.k8s.io/release-utils/version.gitCommit=2 \
    -X sigs.k8s.io/release-utils/version.gitTreeState=3 \
    -X sigs.k8s.io/release-utils/version.buildDate=4 \
    -X sigs.k8s.io/release-utils/version.goVersion=5 \
    -X sigs.k8s.io/release-utils/version.compiler=6 \
    -X sigs.k8s.io/release-utils/version.platform=7' \
    main.go
GitVersion:    1
GitCommit:     2
GitTreeState:  3
BuildDate:     4
GoVersion:     5
Compiler:      6
Platform:      7

Which issue(s) this PR fixes:

Fixes #59

Special notes for your reviewer:

None

Does this PR introduce a user-facing change?

Allow overriding of all variables in the `version` package by using the `-ldflags` `-X` flag.

This now makes it possible to override all variables via the `-X`
ldflag, for example:

```go
package main

import (
	"fmt"

	"sigs.k8s.io/release-utils/version"
)

func main() {
	v := version.GetVersionInfo()
	fmt.Print(v.String())
}
```

```
> go run -ldflags '\
    -X sigs.k8s.io/release-utils/version.gitVersion=1 \
    -X sigs.k8s.io/release-utils/version.gitCommit=2 \
    -X sigs.k8s.io/release-utils/version.gitTreeState=3 \
    -X sigs.k8s.io/release-utils/version.buildDate=4 \
    -X sigs.k8s.io/release-utils/version.goVersion=5 \
    -X sigs.k8s.io/release-utils/version.compiler=6 \
    -X sigs.k8s.io/release-utils/version.platform=7' \
    main.go
GitVersion:    1
GitCommit:     2
GitTreeState:  3
BuildDate:     4
GoVersion:     5
Compiler:      6
Platform:      7
```

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 14, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: saschagrunert

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

@k8s-ci-robot k8s-ci-robot added the sig/release Categorizes an issue or PR as relevant to SIG Release. label Jul 14, 2022
@k8s-ci-robot k8s-ci-robot requested a review from puerco July 14, 2022 12:11
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 14, 2022
@06kellyjac
Copy link

Nice. Im happy with this as is, but another option would be to use buildinfo first and if its empty use the vars

Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

/lgtm

should we do a release after this get merged?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 21, 2022
@k8s-ci-robot k8s-ci-robot merged commit 3581e4f into kubernetes-sigs:main Jul 21, 2022
@saschagrunert saschagrunert deleted the version-override branch July 21, 2022 12:58
@saschagrunert
Copy link
Member Author

@cpanato yes, do you wanna take care of that?

@cpanato
Copy link
Member

cpanato commented Jul 21, 2022

@cpanato yes, do you wanna take care of that?

will do!

@cpanato
Copy link
Member

cpanato commented Jul 26, 2022

released: https://github.com/kubernetes-sigs/release-utils/releases/tag/v0.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/release Categorizes an issue or PR as relevant to SIG Release. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buildinfo is not always available
4 participants