2019-03-20 15:56:39 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Uploads one or more files to a github release
|
|
|
|
#
|
|
|
|
# Prerequisites
|
|
|
|
# 1) GITHUB_TOKEN defined in the environment
|
|
|
|
# 2) TAG defined in the environment
|
|
|
|
#
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ -z $1 ]]; then
|
|
|
|
echo No files specified
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $GITHUB_TOKEN ]]; then
|
|
|
|
echo Error: GITHUB_TOKEN not defined
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-06-06 12:20:47 -07:00
|
|
|
if [[ -z $CI_TAG ]]; then
|
|
|
|
echo Error: CI_TAG not defined
|
2019-03-20 15:56:39 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-06-11 13:13:54 -07:00
|
|
|
# Force CI_REPO_SLUG since sometimes
|
|
|
|
# BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG is not set correctly, causing the
|
|
|
|
# artifact upload to fail
|
|
|
|
CI_REPO_SLUG=solana-labs/solana
|
|
|
|
#if [[ -z $CI_REPO_SLUG ]]; then
|
|
|
|
# echo Error: CI_REPO_SLUG not defined
|
|
|
|
# exit 1
|
|
|
|
#fi
|
2019-06-17 20:42:09 -07:00
|
|
|
|
2019-03-20 15:56:39 -07:00
|
|
|
releaseId=$( \
|
2019-06-17 20:42:09 -07:00
|
|
|
curl -s "https://api.github.com/repos/$CI_REPO_SLUG/releases/tags/$CI_TAG" \
|
2019-03-20 15:56:39 -07:00
|
|
|
| grep -m 1 \"id\": \
|
|
|
|
| sed -ne 's/^[^0-9]*\([0-9]*\),$/\1/p' \
|
|
|
|
)
|
2019-06-06 12:20:47 -07:00
|
|
|
echo "Github release id for $CI_TAG is $releaseId"
|
2019-03-20 15:56:39 -07:00
|
|
|
|
|
|
|
for file in "$@"; do
|
2019-06-17 20:42:09 -07:00
|
|
|
echo "--- Uploading $file to tag $CI_TAG of $CI_REPO_SLUG"
|
2019-03-20 15:56:39 -07:00
|
|
|
curl \
|
2020-06-23 17:27:55 -07:00
|
|
|
--verbose \
|
2019-03-20 15:56:39 -07:00
|
|
|
--data-binary @"$file" \
|
|
|
|
-H "Authorization: token $GITHUB_TOKEN" \
|
|
|
|
-H "Content-Type: application/octet-stream" \
|
2019-06-17 20:42:09 -07:00
|
|
|
"https://uploads.github.com/repos/$CI_REPO_SLUG/releases/$releaseId/assets?name=$(basename "$file")"
|
2019-03-20 15:56:39 -07:00
|
|
|
echo
|
|
|
|
done
|
|
|
|
|