2015-03-15 20:08:54 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
die () {
|
|
|
|
echo "$*" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test $# -ge 2 ||
|
2015-04-06 22:57:04 +03:00
|
|
|
die "Usage: $0 [--repo=<repo>] <tag-name> <path>..."
|
|
|
|
|
2015-05-12 17:30:08 +03:00
|
|
|
repo=git-for-windows/build-extra
|
2015-04-06 22:57:04 +03:00
|
|
|
case "$1" in
|
|
|
|
--repo=*)
|
|
|
|
repo=${1#--repo=}
|
2015-05-12 17:30:08 +03:00
|
|
|
test "a${repo}" != "a${repo#*/}" ||
|
|
|
|
repo=git-for-windows/$repo
|
2015-04-06 22:57:04 +03:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
2015-03-15 20:08:54 +03:00
|
|
|
|
|
|
|
tagname="$1"
|
|
|
|
shift
|
|
|
|
|
2015-05-12 17:30:08 +03:00
|
|
|
url=https://api.github.com/repos/$repo/releases
|
2015-03-15 20:08:54 +03:00
|
|
|
id="$(curl --netrc -s $url |
|
|
|
|
grep -B1 "\"tag_name\": \"$tagname\"" |
|
|
|
|
sed -n 's/.*"id": *\([0-9]*\).*/\1/p')"
|
|
|
|
test -n "$id" || {
|
2015-05-14 21:16:18 +03:00
|
|
|
out="$(curl --netrc -s -XPOST -d \
|
|
|
|
'{"tag_name":"'"$tagname"'","draft":true,"prerelease":true}' \
|
|
|
|
$url)" ||
|
2015-03-15 20:08:54 +03:00
|
|
|
die "Error creating release: $out"
|
|
|
|
id="$(echo "$out" |
|
2015-03-29 00:46:11 +03:00
|
|
|
sed -n 's/^ "id": *\([0-9]*\).*/\1/p')"
|
2015-03-15 20:08:54 +03:00
|
|
|
test -n "$id" ||
|
|
|
|
die "Could not create release for tag $tagname"
|
|
|
|
}
|
|
|
|
|
|
|
|
url=https://uploads.${url#https://api.}
|
|
|
|
|
2015-09-30 20:52:40 +03:00
|
|
|
release_url=
|
2015-03-15 20:08:54 +03:00
|
|
|
for path
|
|
|
|
do
|
|
|
|
case "$path" in
|
|
|
|
*.exe)
|
|
|
|
contenttype=application/executable
|
|
|
|
;;
|
|
|
|
*.7z)
|
|
|
|
contenttype=application/zip
|
|
|
|
;;
|
|
|
|
*)
|
2015-05-12 17:30:35 +03:00
|
|
|
contenttype="$(file --brief --mime-type "$path")" ||
|
2015-03-15 20:08:54 +03:00
|
|
|
die "Unknown file type: $path"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
basename="$(basename "$path")"
|
2015-09-30 20:52:40 +03:00
|
|
|
json="$(curl -i --netrc -XPOST -H "Content-Type: $contenttype" \
|
|
|
|
--data-binary @"$path" "$url/$id/assets?name=$basename")" ||
|
2015-09-30 20:50:53 +03:00
|
|
|
die "Could not upload $path (response: $json)"
|
2015-09-30 20:52:40 +03:00
|
|
|
|
|
|
|
url2="$(echo "${json##*\"browser_download_url\":\"}" | sed -n \
|
|
|
|
'1s|\([^"]*/\)download\(/[^"]*\).*|\1edit\2|'p)"
|
|
|
|
if test -z "$release_url"
|
|
|
|
then
|
|
|
|
release_url=$url2
|
|
|
|
else
|
|
|
|
test "a$url2" = "a$release_url" ||
|
|
|
|
echo "Warning: inconsistent URL: $url2 vs $release_url" >&2
|
|
|
|
fi
|
2015-03-15 20:08:54 +03:00
|
|
|
done
|
2015-09-30 20:52:40 +03:00
|
|
|
|
|
|
|
test -z "$release_url" ||
|
|
|
|
printf "\nNow direct your browser to:\n\n%s\n" "$release_url"
|