Skip to content

Commit 7299f53

Browse files
committed
Check GitHub releases before tags
1 parent 83b3425 commit 7299f53

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

scripts/get-latest-github-release-tag.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,27 @@ if [ -n "$GITHUB_TOKEN" ]; then
2020
GITHUB_AUTHORIZATION_HEADER="Authorization: Bearer $GITHUB_TOKEN"
2121
fi
2222

23-
# get the tags JSON from the GitHub API and parse it manually,
24-
# or output it to stderr if the server returns an error
23+
# try releases first (preferred), then fall back to tags
2524
# per_page=100 is required for some repositories with a lot of beta tags
25+
github_releases=`curl \
26+
--silent --show-error --fail-with-body \
27+
--header "$GITHUB_AUTHORIZATION_HEADER" \
28+
https://api.github.com/repos/$GITHUB_REPO/releases?per_page=100`
29+
30+
if [ $? -eq 0 ]; then
31+
latest_release=`echo "$github_releases" \
32+
| grep '"tag_name":' \
33+
| sed -E 's/.*"([^"]+)".*/\1/' \
34+
| egrep "^${TAG_PREFIX}[0-9]+[\\._-][0-9]+([\\._-][0-9]+)?\$" \
35+
| head -n 1`
36+
if [ -n "$latest_release" ]; then
37+
echo "$latest_release"
38+
exit 0
39+
fi
40+
else
41+
echo "$github_releases" >&2
42+
fi
43+
2644
github_tags=`curl \
2745
--silent --show-error --fail-with-body \
2846
--header "$GITHUB_AUTHORIZATION_HEADER" \

0 commit comments

Comments
 (0)