-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e39526
commit 028cb11
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,31 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Get the most recent tag | ||
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null) | ||
|
||
if [ -z "$latest_tag" ]; then | ||
echo "No tags found" | ||
exit 1 | ||
fi | ||
|
||
# Get the full description of current commit relative to last tag | ||
# --long ensures we always get the commit count and hash | ||
# --always returns hash even if no tags exist | ||
describe=$(git describe --tags --long --always) | ||
|
||
# If we're exactly on a tag, just output the tag | ||
if git describe --tags --exact-match 2>/dev/null >/dev/null; then | ||
echo "$latest_tag" | ||
else | ||
# Parse the describe output | ||
# Format is like: 1.2.3-5-g36e65 | ||
# We want to transform it to: 1.2.3-build.5+g36e65 | ||
|
||
# Extract components using sed | ||
version=$(echo "$describe" | sed -E 's/^(.*)-([0-9]+)-g([0-9a-f]+)$/\1/') | ||
commits=$(echo "$describe" | sed -E 's/^(.*)-([0-9]+)-g([0-9a-f]+)$/\2/') | ||
hash=$(echo "$describe" | sed -E 's/^(.*)-([0-9]+)-g([0-9a-f]+)$/\3/') | ||
|
||
echo "$version-build.$commits+g$hash" | ||
fi |
This file contains 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 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,3 @@ | ||
package hversion | ||
|
||
const Version = "dev" |