Skip to content

Add version command #43

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

Merged
merged 5 commits into from
Apr 21, 2023
Merged

Add version command #43

merged 5 commits into from
Apr 21, 2023

Conversation

vdye
Copy link
Collaborator

@vdye vdye commented Apr 20, 2023

Closes #17

This pull request contains a smattering of CI/CD updates as well as the addition of the git-bundle-server version command.

CI/CD changes

  • The first two commits here update the main.yml workflow to run Makefile targets rather than custom go (build|vet|test) invocations.
  • The third commit updates release.yml to match only the exact set of patterns we want for releases (the previous pattern would allow tags like v1a.2b.3c-d.4ef).

git-bundle-server version

  • The fourth commit introduces the git-bundle-server version command, which prints a (currently unset) globally-accessible version string compiled into the program.
  • The fifth commit updates the Makefile to determine the VERSION if it is not set by a user, then compiles that value into git-bundle-server using -ldflags.

CC: @jeffhostetler (since this is based on your recommendation in an earlier PR)

vdye added 2 commits April 20, 2023 14:35
Add a target that runs 'go vet', to be used in the CI workflow to replace
direct invocations of 'go'.

Signed-off-by: Victoria Dye <[email protected]>
Rather than invoke 'go' directly, call the appropriate Makefile targets for
the given operations in 'main.yml'. This more accurately reflects the build
process for users and CD and avoids having multiple "sources of truth" on
how to build the project.

Signed-off-by: Victoria Dye <[email protected]>
@vdye vdye added this to the v1.0 milestone Apr 20, 2023
@vdye vdye self-assigned this Apr 20, 2023
Copy link

@jeffhostetler jeffhostetler left a comment

Choose a reason for hiding this comment

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

nicely done!

vdye added 3 commits April 21, 2023 09:00
Improve the tag pattern matching to only match the exact tag patterns we
want to release. Previously, the glob-style pattern would match a tag like
"v1a.2bc-d.3ef.4" due to the use of the '*' wildcard. However, GitHub
Actions has the regex-like '+' available to match one or more of the
preceding character set [1], so we can more restrictively match
'v<number>.<number>.<number>' with '[0-9]+' representing '<number>'.

To make the tag match slightly more flexible, add a pattern for
'v<number>.<number>.<number>-<string>' (e.g. for "-rc" versions).

[1] https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet

Signed-off-by: Victoria Dye <[email protected]>
Add a command to report the version of the compiled bundle server
executables. The version string is set using the '-ldflags' build flag in
'go build' (specifically, setting the 'Version' string in
'cmd/utils/version.go').

In a later patch, the version will be automatically during the build process
(using 'make') with 'git describe'.

Signed-off-by: Victoria Dye <[email protected]>
Add a 'VERSION-FILE' target that generates a value for the Makefile
'VERSION' using 'git describe'.

The process for generating this file is based off of the 'GIT-VERSION-FILE'
target in the Git project's Makefile, with some minor changes for the sake
of efficiency.

If the 'VERSION' is set by the caller (e.g. with 'make VERSION=1.0.0'), the
'VERSION-FILE' target is a .PHONY (i.e., non-file, always run) target.

Conversely, if 'VERSION' is not set, 'VERSION-FILE' is instead a real file
target and is loaded into the Makefile with '-include VERSION-FILE'. Its
recipe runs the script 'generate-version.sh' to determine a version and
write 'VERSION := <string>' to 'VERSION-FILE' *if and only if* its contents
change. Finally, the 'VERSION-FILE' target depends on a .PHONY 'FORCE'
target, ensuring it is always re-run.

If the contents of 'VERSION-FILE' change as a result of
'generate-version.sh', the full 'Makefile' is re-evaluated. This ensures
that 'VERSION' is up-to-date with the contents of 'VERSION-FILE'.

Finally, compile the 'VERSION' into 'git-bundle-server' by setting the appropriate '-ldflags'.

Signed-off-by: Victoria Dye <[email protected]>
@vdye vdye force-pushed the vdye/version-cmd branch from 2d64992 to e55fd2d Compare April 21, 2023 16:12
Copy link
Collaborator

@ldennington ldennington left a comment

Choose a reason for hiding this comment

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

Overall, looks really good! The one thing I'm having trouble with is getting the new command to work locally (although I recognize this is probabaly just me holding it wrong). Here's what I'm seeing:

make output

ldennington@Lessleys-MBP:~/repos/git-bundle-server(vdye/version-cmd○) » make
rm -f -r /Users/ldennington/repos/git-bundle-server/bin
GOOS="darwin" GOARCH="amd64" go build -o /Users/ldennington/repos/git-bundle-server/bin -ldflags "-X 'github.com/github/git-bundle-server/cmd/utils.Version='" ./...

git-bundle-server version output

ldennington@Lessleys-MBP:~/repos/git-bundle-server(vdye/version-cmd○) » ./bin/git-bundle-server version
git-bundle-server version <no version>

git tag --list output

ldennington@Lessleys-MBP:~/repos/git-bundle-server(vdye/version-cmd○) » git tag --list
v0.0.1
v0.1.0
v0.1.1
v0.1.2
v0.2.0

.PHONY: clean
clean:
go clean ./...
$(RM) -r VERSION-FILE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Is the -r needed, given this is a file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a -f instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might seem silly, but I went with -r in case someone really messes up their local build environment and creates a VERSION-FILE directory.

The $(RM) built-in variable already has the -f flag included, though.

@vdye
Copy link
Collaborator Author

vdye commented Apr 21, 2023

Overall, looks really good! The one thing I'm having trouble with is getting the new command to work locally (although I recognize this is probabaly just me holding it wrong). Here's what I'm seeing:

make output

ldennington@Lessleys-MBP:~/repos/git-bundle-server(vdye/version-cmd○) » make
rm -f -r /Users/ldennington/repos/git-bundle-server/bin
GOOS="darwin" GOARCH="amd64" go build -o /Users/ldennington/repos/git-bundle-server/bin -ldflags "-X 'github.com/github/git-bundle-server/cmd/utils.Version='" ./...

git-bundle-server version output

ldennington@Lessleys-MBP:~/repos/git-bundle-server(vdye/version-cmd○) » ./bin/git-bundle-server version
git-bundle-server version <no version>

git tag --list output

ldennington@Lessleys-MBP:~/repos/git-bundle-server(vdye/version-cmd○) » git tag --list
v0.0.1
v0.1.0
v0.1.1
v0.1.2
v0.2.0

@ldennington the issue is that none of those tags are on the main branch, so they're not in the ancestry path searched by git describe, so no version is found. If you locally tag the main branch with v<something>, does that work?

@ldennington
Copy link
Collaborator

@ldennington the issue is that none of those tags are on the main branch, so they're not in the ancestry path searched by git describe, so no version is found. If you locally tag the main branch with v<something>, does that work?

That worked! Thanks for clarifying.

@vdye vdye merged commit f35cf24 into main Apr 21, 2023
@vdye vdye deleted the vdye/version-cmd branch April 21, 2023 22:00
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.

Add a version subcommand or option to executables
4 participants