forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-to-github.sh
executable file
·53 lines (46 loc) · 1014 Bytes
/
upload-to-github.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
die () {
echo "$*" >&2
exit 1
}
test $# -ge 2 ||
die "Usage: $0 [--repo=<repo>] <tag-name> <path>..."
repo=build-extra
case "$1" in
--repo=*)
repo=${1#--repo=}
shift
;;
esac
tagname="$1"
shift
url=https://api.github.com/repos/git-for-windows/$repo/releases
id="$(curl --netrc -s $url |
grep -B1 "\"tag_name\": \"$tagname\"" |
sed -n 's/.*"id": *\([0-9]*\).*/\1/p')"
test -n "$id" || {
out="$(curl --netrc -s -XPOST -d '{"tag_name":"'"$tagname"'"}' $url)" ||
die "Error creating release: $out"
id="$(echo "$out" |
sed -n 's/^ "id": *\([0-9]*\).*/\1/p')"
test -n "$id" ||
die "Could not create release for tag $tagname"
}
url=https://uploads.${url#https://api.}
for path
do
case "$path" in
*.exe)
contenttype=application/executable
;;
*.7z)
contenttype=application/zip
;;
*)
die "Unknown file type: $path"
;;
esac
basename="$(basename "$path")"
curl -i --netrc -XPOST -H "Content-Type: $contenttype" \
--data-binary @"$path" "$url/$id/assets?name=$basename"
done