mirror of
https://github.com/jessfraz/dockerfiles.git
synced 2024-11-23 11:31:49 +01:00
18dcbce78b
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
54 lines
1.4 KiB
Bash
Executable File
54 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
set -o pipefail
|
|
|
|
if [[ -z "$GITHUB_TOKEN" ]]; then
|
|
echo "Set the GITHUB_TOKEN env variable."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "$GITHUB_REPOSITORY" ]]; then
|
|
echo "Set the GITHUB_REPOSITORY env variable."
|
|
exit 1
|
|
fi
|
|
|
|
URI=https://api.github.com
|
|
API_VERSION=v3
|
|
API_HEADER="Accept: application/vnd.github.${API_VERSION}+json"
|
|
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
|
|
|
|
main(){
|
|
local files
|
|
|
|
if [ "$#" -eq 0 ]; then
|
|
echo "Must pass files to be uploaded..."
|
|
exit 1
|
|
fi
|
|
files=( "$@" )
|
|
|
|
# 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; }
|
|
|
|
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}"
|
|
|
|
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" \
|
|
"${URI}/repos/${GITHUB_REPOSITORY}/releases/${tag_id}/assets?name=${filename}"
|
|
|
|
echo "Successfully uploaded: ${file}!"
|
|
done
|
|
|
|
echo "Uploading assets to ${tag_name} complete!"
|
|
}
|
|
|
|
main $@
|