-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
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]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nicely done!
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]>
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a -f
instead?
There was a problem hiding this comment.
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.
@ldennington the issue is that none of those tags are on the |
That worked! Thanks for clarifying. |
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
main.yml
workflow to runMakefile
targets rather than customgo (build|vet|test)
invocations.release.yml
to match only the exact set of patterns we want for releases (the previous pattern would allow tags likev1a.2b.3c-d.4ef
).git-bundle-server version
git-bundle-server version
command, which prints a (currently unset) globally-accessible version string compiled into the program.Makefile
to determine theVERSION
if it is not set by a user, then compiles that value intogit-bundle-server
using-ldflags
.CC: @jeffhostetler (since this is based on your recommendation in an earlier PR)