-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a separate script to get the latest tag
- Loading branch information
Showing
2 changed files
with
31 additions
and
8 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,28 @@ | ||
#!/bin/env bash | ||
|
||
set -e | ||
|
||
function get_latest_tag() { | ||
git fetch --tags | ||
# This suppress an error occurred when the repository is a complete one. | ||
git fetch --prune || true | ||
|
||
latest_tag='' | ||
|
||
# Get a latest tag in the shape of semver. | ||
for ref in $(git for-each-ref --sort=-creatordate --format '%(refname)' refs/tags); do | ||
tag="${ref#refs/tags/}" | ||
if echo "${tag}" | grep -Eq '^v?([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$'; then | ||
latest_tag="${tag}" | ||
break | ||
fi | ||
done | ||
|
||
if [ "${latest_tag}" = '' ]; then | ||
latest_tag="${INPUT_INITIAL_VERSION}" | ||
fi | ||
|
||
echo "${latest_tag}" | ||
} | ||
|
||
get_latest_tag |