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

changeset: allow override the revision through ldflags #2601

Merged
merged 1 commit into from
Nov 2, 2022

Conversation

vdemeester
Copy link
Member

Changes

The main reason for this is to support cases where the go build happens on a non git folder but we want to pass a revision anyway.

Signed-off-by: Vincent Demeester [email protected]

/kind enhancement
/cc @imjasonh @dprotaso

Release Note

NONE

@knative-prow knative-prow bot added kind/enhancement size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 28, 2022
// Revision contains the revision of the binary.
// It is exported so that it can be overriden using ldflags.
// By default, it will use 'vcs.revision' property from the embedded build information
// Note: Use changeset.Get() to get it instead of through this variable.
Copy link
Member

Choose a reason for hiding this comment

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

Can ldflags only set an exported var? Can we just unexport this?

Copy link
Member Author

Choose a reason for hiding this comment

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

hum that was my initial though (because it's been a long time since I did that…). Let me test it out.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah seems like it works with unexported, let me update this.

@knative-prow knative-prow bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 28, 2022
The main reason for this is to support cases where the `go build`
happens on a non git folder but we want to pass a revision anyway.

Signed-off-by: Vincent Demeester <[email protected]>
@codecov
Copy link

codecov bot commented Sep 28, 2022

Codecov Report

Base: 81.29% // Head: 81.29% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (5a282d8) compared to base (6d71868).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2601   +/-   ##
=======================================
  Coverage   81.29%   81.29%           
=======================================
  Files         162      162           
  Lines        9820     9821    +1     
=======================================
+ Hits         7983     7984    +1     
  Misses       1597     1597           
  Partials      240      240           
Impacted Files Coverage Δ
changeset/commit.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@vdemeester
Copy link
Member Author

/test unit-tests

@imjasonh
Copy link
Member

Do we still need this if we go with tektoncd/pipeline#5573 ?

@vdemeester
Copy link
Member Author

Do we still need this if we go with tektoncd/pipeline#5573 ?

Yes, this is unrelated with tektoncd/pipeline#5573 👼🏼. Downstream, we are building tekton (and I guess knative as well), through a cachito cache/proxy, which means, when we build the project, we are not in a git repository (we have the information about it but we are not). Hence proposing this to be able to set the correct revision in that case 🙃.

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Oct 5, 2022
@dprotaso
Copy link
Member

dprotaso commented Nov 1, 2022

So what's the ld flag to set rev ?

@vdemeester
Copy link
Member Author

@dprotaso it would be something like

go build -ldflags="-X 'knative.dev/pkg/changeset.rev={the-commit-sha-or-something}'"

@dprotaso
Copy link
Member

dprotaso commented Nov 2, 2022

/lgtm
/approve

@knative-prow
Copy link

knative-prow bot commented Nov 2, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, imjasonh, vdemeester

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

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 2, 2022
@dprotaso
Copy link
Member

dprotaso commented Nov 2, 2022

/retest

@knative-prow knative-prow bot merged commit dc1fae1 into knative:main Nov 2, 2022
@vdemeester vdemeester deleted the changeset-allow-override branch November 3, 2022 07:20
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. kind/enhancement lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants