forked from client9/shlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_release.sh
30 lines (29 loc) · 905 Bytes
/
github_release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
# github_release: validates tag exists or returns latest tagged release
#
# If tag exists it is returned
# If tag is latest, the latest tag is returned
#
# Requires: http_download, is_command
#
# hack to extract version from output is based on
#
# https://github.com/golang/dep/blob/master/install.sh
#
# 1. tr -s '\n' ' ' --> make sure output is exactly one line
# 2. sed 's/.*"tag_name":"//' --> remove everything before
# 3. sed 's/".*//' --> remove everything after
#
# what remains is the version number
#
github_release() {
owner_repo=$1
version=$2
test -z "$version" && version="latest"
giturl="https://github.com/${owner_repo}/releases/${version}"
json=$(http_copy "$giturl" "Accept:application/json")
test -z "$json" && return 1
version=$(echo "$json" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//')
test -z "$version" && return 1
echo "$version"
}