2018-09-24 21:42:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
2018-09-24 22:47:40 +02:00
|
|
|
if [[ ! -z "$TOKEN" ]]; then
|
|
|
|
GITHUB_TOKEN=$TOKEN
|
|
|
|
fi
|
2018-09-24 22:33:52 +02:00
|
|
|
|
|
|
|
if [[ -z "$GITHUB_TOKEN" ]]; then
|
|
|
|
echo "Set the GITHUB_TOKEN env variable."
|
2018-09-24 21:46:18 +02:00
|
|
|
exit 1
|
2018-09-24 21:42:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$GITHUB_REPOSITORY" ]]; then
|
2018-09-24 21:46:18 +02:00
|
|
|
echo "Set the GITHUB_REPOSITORY env variable."
|
|
|
|
exit 1
|
2018-09-24 21:42:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
URI=https://api.github.com
|
|
|
|
API_VERSION=v3
|
|
|
|
API_HEADER="Accept: application/vnd.github.${API_VERSION}+json"
|
2018-09-24 22:33:52 +02:00
|
|
|
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
|
2018-09-24 21:42:16 +02:00
|
|
|
|
2018-09-24 21:46:18 +02:00
|
|
|
main(){
|
|
|
|
local files
|
2018-09-24 21:42:16 +02:00
|
|
|
|
2018-09-24 21:46:18 +02:00
|
|
|
if [ "$#" -eq 0 ]; then
|
|
|
|
echo "Must pass files to be uploaded..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
files=( "$@" )
|
2018-09-24 21:42:16 +02:00
|
|
|
|
2018-09-24 21:46:18 +02:00
|
|
|
# Validate the GitHub token.
|
|
|
|
curl -o /dev/null -sSL -H "${AUTH_HEADER}" -H "${API_HEADER}" "${URI}/repos/${GITHUB_REPOSITORY}" || { echo "Error: Invalid repo, token or network issue!"; exit 1; }
|
2018-09-24 21:42:16 +02:00
|
|
|
|
2018-09-24 21:46:18 +02:00
|
|
|
tag_response=$(curl -sSL -H "${AUTH_HEADER}" -H "${API_HEADER}" "${URI}/repos/${GITHUB_REPOSITORY}/releases/latest")
|
|
|
|
|
|
|
|
tag_name=$(echo $tag_response | jq -e --raw-output .tag_name)
|
|
|
|
tag_id=$(echo $tag_response | jq -e --raw-output .id)
|
|
|
|
|
|
|
|
echo "Uploading files: ${files[@]}"
|
|
|
|
echo "For tag name: ${tag_name} tag id: ${tag_id}"
|
2018-09-24 21:50:03 +02:00
|
|
|
|
|
|
|
for file in ${files[@]}; do
|
|
|
|
filename=$(basename "$file")
|
|
|
|
curl -sSL -H "${AUTH_HEADER}" -H "${API_HEADER}" \
|
|
|
|
--data-binary @"$file" \
|
|
|
|
-H "Content-Type: application/octet-stream" \
|
2018-09-24 21:50:52 +02:00
|
|
|
"https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${tag_id}/assets?name=${filename}"
|
2018-09-24 21:50:03 +02:00
|
|
|
|
|
|
|
echo "Successfully uploaded: ${file}!"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Uploading assets to ${tag_name} complete!"
|
2018-09-24 21:46:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main $@
|