Skip to content

Commit f758c64

Browse files
committed
Add msysGit's helper to upload to GitHub
This was taken from msysgit/msysgit@00039af4 (Rewrite upload-to-github.sh for current GitHub API). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2bace66 commit f758c64

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

upload-to-github.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
3+
die () {
4+
echo "$*" >&2
5+
exit 1
6+
}
7+
8+
test $# -ge 2 ||
9+
die "Usage: $0 <tag-name> <path>..."
10+
11+
tagname="$1"
12+
shift
13+
14+
url=https://api.github.com/repos/msysgit/msysgit/releases
15+
id="$(curl --netrc -s $url |
16+
grep -B1 "\"tag_name\": \"$tagname\"" |
17+
sed -n 's/.*"id": *\([0-9]*\).*/\1/p')"
18+
test -n "$id" || {
19+
out="$(curl --netrc -s -XPOST -d '{"tag_name":"'"$tagname"'"}' $url)" ||
20+
die "Error creating release: $out"
21+
id="$(echo "$out" |
22+
sed -n 's/.*"id": *\([0-9]*\).*/\1/p')"
23+
test -n "$id" ||
24+
die "Could not create release for tag $tagname"
25+
}
26+
27+
url=https://uploads.${url#https://api.}
28+
29+
for path
30+
do
31+
case "$path" in
32+
*.exe)
33+
contenttype=application/executable
34+
;;
35+
*.7z)
36+
contenttype=application/zip
37+
;;
38+
*)
39+
die "Unknown file type: $path"
40+
;;
41+
esac
42+
basename="$(basename "$path")"
43+
curl -i --netrc -XPOST -H "Content-Type: $contenttype" \
44+
--data-binary @"$path" "$url/$id/assets?name=$basename"
45+
done

0 commit comments

Comments
 (0)