-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ec543e7
Makefile: add 'vet' target
vdye 4a46973
ci: run Makefile targets
vdye 0a8b690
release.yml: improve tag pattern matching
vdye c7f5edd
git-bundle-server: add 'version' command
vdye e55fd2d
Makefile: automatically determine the bundle server version
vdye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/git-bundle-server | ||
/git-bundle-web-server | ||
/VERSION-FILE | ||
/bin/ | ||
/_dist/ | ||
/_docs/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/github/git-bundle-server/cmd/utils" | ||
"github.com/github/git-bundle-server/internal/argparse" | ||
"github.com/github/git-bundle-server/internal/log" | ||
) | ||
|
||
type versionCmd struct { | ||
logger log.TraceLogger | ||
container *utils.DependencyContainer | ||
} | ||
|
||
func NewVersionCommand(logger log.TraceLogger, container *utils.DependencyContainer) argparse.Subcommand { | ||
return &versionCmd{ | ||
logger: logger, | ||
container: container, | ||
} | ||
} | ||
|
||
func (versionCmd) Name() string { | ||
return "version" | ||
} | ||
|
||
func (versionCmd) Description() string { | ||
return ` | ||
Display the version information for the bundle server CLI.` | ||
} | ||
|
||
func (v *versionCmd) Run(ctx context.Context, args []string) error { | ||
parser := argparse.NewArgParser(v.logger, "git-bundle-server version") | ||
parser.Parse(ctx, args) | ||
|
||
versionStr := utils.Version | ||
if versionStr == "" { | ||
versionStr = "<no version>" | ||
} | ||
|
||
fmt.Printf("git-bundle-server version %s\n", versionStr) | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package utils | ||
|
||
// The purpose of this file is to contain globally-accessible variables that | ||
// specify version information for the bundle server. The values of these | ||
// variables are set during the build process when using 'make'. | ||
|
||
// The executable's version string with no leading 'v' (e.g. "1.0.0" or | ||
// "1.0.1-g1a2b3c4d"). | ||
var Version string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
die () { | ||
echo "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
write_version () { | ||
if [ -n "$1" ]; then | ||
echo "Setting VERSION to $1" | ||
else | ||
echo "No version found!" | ||
fi | ||
echo "VERSION := $1" >"$2" | ||
} | ||
|
||
# Parse script arguments | ||
for i in "$@" | ||
do | ||
case "$i" in | ||
--version-file=*) | ||
VERSION_FILE="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
*) | ||
die "unknown option '$i'" | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "$VERSION_FILE" ]; then | ||
die "error: missing version file path" | ||
fi | ||
|
||
set -e | ||
|
||
# The pattern match used below is *less* restrictive than it should be (i.e. | ||
# "v<number>.<number>.<number>[-<optional string>]"), but we're limited by the | ||
# glob patterns used in 'git describe'. | ||
# | ||
# That said, we're explicitly specifying 'VERSION' for formal releases(based on | ||
# the more precise pattern match in 'release.yml', so it's not super important | ||
# to be strict here. | ||
VERSION_RAW="$(git describe --tags --match "v[0-9]*.[0-9]*.[0-9]*" 2>/dev/null || echo "")" | ||
VERSION="${VERSION_RAW:1}" | ||
derrickstolee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if [ -r "$VERSION_FILE" ] | ||
then | ||
CACHE_VERSION=$(sed -e 's/^VERSION := //' <"$VERSION_FILE") | ||
if [ "$VERSION" != "$CACHE_VERSION" ]; then | ||
write_version "$VERSION" "$VERSION_FILE" | ||
fi | ||
else | ||
# If the file doesn't exist, write unconditionally | ||
write_version "$VERSION" "$VERSION_FILE" | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aVERSION-FILE
directory.The
$(RM)
built-in variable already has the-f
flag included, though.