Skip to content

version string logic updated to use v0.0.0-dev when no string set#398

Merged
LandonTClipp merged 1 commit intovektra:masterfrom
williambanfield:wb/397
Sep 16, 2021
Merged

version string logic updated to use v0.0.0-dev when no string set#398
LandonTClipp merged 1 commit intovektra:masterfrom
williambanfield:wb/397

Conversation

@williambanfield
Copy link
Contributor

This change is aimed at addressing issues where mockery will use the incorrect version if SemVer variable is not set during build using the -ldflag option.

When running with ld flag set:

go build -ldflags="-X 'github.com/vektra/mockery/v2/pkg/config.SemVer=v1.2.3'"
[Fri 12:27] mockery[wb/397]:. ◯ ./mockery --version
Using config file: /home/william/repos/mockery/.mockery.yaml
30 Jul 21 12:27 EDT INF Starting mockery dry-run=false version=v1.2.3
v1.2.3

When running as module:

[Fri 12:40] ~/repos ◯ mkdir testmodule
[Fri 12:40] ~/repos ◯ cd testmodule
[Fri 12:40] ~/repos/testmodule ◯ go mod init github.com/testmodule
go: creating new go.mod: module github.com/testmodule
[Fri 12:40] ~/repos/testmodule ◯ go get github.com/vektra/mockery/v2/.../@v2.9.0
go get: added github.com/vektra/mockery/v2 v2.9.0
[Fri 12:41] ~/repos/testmodule ◯ go mod edit -replace github.com/vektra/mockery/v2@v2.9.0=../mockery
[Fri 12:41] ~/repos/testmodule ◯ go run github.com/vektra/mockery/v2 --version
30 Jul 21 12:41 EDT INF Starting mockery dry-run=false version=v2.9.0
v2.9.0

When running otherwise

go run main.go --version
Using config file: /home/william/repos/mockery/.mockery.yaml
30 Jul 21 12:24 EDT INF Starting mockery dry-run=false version=v0.0.0-dev
v0.0.0-dev

closes: #397

@LandonTClipp
Copy link
Member

This will probably work. I'll test tonight and see if it fixes it. I'm tempted to move towards hard coding the semver variable to the actual version, then the build pipeline would key off that to create the git tag. But, if this works we can go with it.

@williambanfield
Copy link
Contributor Author

Thanks so much for taking a look @LandonTClipp ! Let me know if there's anything I can do to support. Both solutions seem pretty good.

@LandonTClipp
Copy link
Member

LandonTClipp commented Sep 16, 2021

I actually think I'm going to go with hard-coding the version string and having that be the source of truth, instead of relying on two disjointed methods (i.e. variable injection for builds, and ReadDebugInfo for modules). I've been getting pretty frustrated with this issue and it would solve it once and for all. The trick is getting the build pipelines to correctly key off of it and tag as appropriate.

I appreciate the PR and the engagement, but will close this for now.

@LandonTClipp
Copy link
Member

Actually, I changed my mind. I'll give this a shot. Might be easier.

@LandonTClipp LandonTClipp reopened this Sep 16, 2021
@LandonTClipp LandonTClipp merged commit 207f441 into vektra:master Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2.9.0 has wrong version string

2 participants