Merge pull request #1008 from PowerShell/andschwa/ci-upgrade
Refactor to get latest asset ID using API
This commit is contained in:
commit
93c01909f5
1 changed files with 20 additions and 14 deletions
34
download.sh
34
download.sh
|
@ -2,32 +2,38 @@
|
|||
|
||||
[[ -n $GITHUB_TOKEN ]] || { echo >&2 "GITHUB_TOKEN variable is undefined, please provide token"; exit 1; }
|
||||
|
||||
# Set OS specific asset ID and package name
|
||||
# Authorizes with read-only access to GitHub API
|
||||
curl_() {
|
||||
curl -s -i -H "Authorization: token $GITHUB_TOKEN" "$@"
|
||||
}
|
||||
|
||||
# Retrieves asset ID and package name of asset ending in argument
|
||||
# $info looks like: "id": 1698239, "name": "powershell_0.4.0-1_amd64.deb",
|
||||
get_info() {
|
||||
curl_ https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep -B 1 "name.*$1"
|
||||
}
|
||||
|
||||
# Get OS specific asset ID and package name
|
||||
case "$OSTYPE" in
|
||||
linux*)
|
||||
asset='1536045'
|
||||
package='powershell_0.3.0-1_amd64.deb'
|
||||
# Install curl and wget to download package
|
||||
sudo apt-get install -y curl wget
|
||||
info=$(get_info deb)
|
||||
;;
|
||||
darwin*)
|
||||
asset='1536063'
|
||||
package='powershell-0.3.0.pkg'
|
||||
info=$(get_info pkg)
|
||||
;;
|
||||
*)
|
||||
exit 2 >&2 "$OSTYPE not supported!"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Authorizes with read-only access to GitHub API
|
||||
# Retrieves URL of v0.3.0 release asset
|
||||
curl -s -i \
|
||||
-H "Authorization: token $GITHUB_TOKEN " \
|
||||
-H 'Accept: application/octet-stream' \
|
||||
"https://api.github.com/repos/PowerShell/PowerShell/releases/assets/$asset" |
|
||||
grep location |
|
||||
sed 's/location: //g' |
|
||||
wget -i - -O $package
|
||||
# Parses $info for asset ID and package name
|
||||
read asset package <<< $(echo $info | sed 's/[,"]//g' | awk '{ print $2; print $4 }')
|
||||
|
||||
# Downloads asset to file
|
||||
curl_ -H 'Accept: application/octet-stream' https://api.github.com/repos/PowerShell/PowerShell/releases/assets/$asset |
|
||||
grep location | sed 's/location: //g' | wget -i - -O $package
|
||||
|
||||
# Installs PowerShell package
|
||||
case "$OSTYPE" in
|
||||
|
|
Loading…
Reference in a new issue