forked from duniter/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.sh
executable file
·80 lines (66 loc) · 2.87 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
### Control that the script is run on `dev` branch
branch=`git rev-parse --abbrev-ref HEAD`
if [[ ! "$branch" = "master" ]];
then
echo ">> This script must be run under \`master\` branch"
exit
fi
### Releasing
current=`grep -P "version\": \"\d+.\d+.\d+(\w*)" package.json | grep -oP "\d+.\d+.\d+(\w*)"`
echo "Current version: $current"
case "$1" in
del)
if [[ $2 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ ]]; then
result=`curl -i 'https://api.github.com/repos/duniter/cesium/releases/tags/v'"$current"''`
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://api.github.com/repos/duniter/cesium/releases/\d+"`
if [[ $release_url != "" ]]; then
echo "Deleting existing release..."
curl -XDELETE $release_url -u $2
fi
else
echo "Wrong argument"
echo "Usage:"
echo " > ./github.sh del user:password"
exit
fi
;;
pre|rel)
if [[ $2 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ && $3 != "" ]]; then
if [[ $1 = "pre" ]]; then
prerelease="true"
else
prerelease="false"
fi
result=`curl -i 'https://api.github.com/repos/duniter/cesium/releases/tags/v'"$current"''`
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://api.github.com/repos/duniter/cesium/releases/\d+"`
if [[ $release_url != "" ]]; then
echo "Deleting existing release..."
curl -XDELETE $release_url -u $2
fi
echo "Creating new release..."
result=`curl -i https://api.github.com/repos/duniter/cesium/releases -u $2 -d '{"tag_name": "v'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$3"'","draft": false,"prerelease": '"$prerelease"'}'`
upload_url=`echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[a-z0-9/.]+"`
### Sending files
echo "Uploading files to GitHub..."
dirname=`pwd`
curl -i -u $2 -H 'Content-Type: application/zip' -T $dirname/platforms/web/build/cesium-web-$current.zip $upload_url?name=cesium-v$current-web.zip
curl -i -u $2 -H 'Content-Type: application/zip' -T $dirname/platforms/firefoxos/build/package.zip $upload_url?name=cesium-v$current-firefoxos.zip
curl -i -u $2 -H 'Content-Type: application/vnd.android.package-archive' -T $dirname/platforms/android/build/outputs/apk/android-release.apk $upload_url?name=cesium-v$current-android.apk
echo "Successfully uploading files"
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://api.github.com/repos/[a-z0-9/.]+"`
echo " -> Release url: $release_url"
else
echo "Wrong arguments"
echo "Usage:"
echo " > ./github.sh pre|rel user:password <release_description>"
echo "With:"
echo " - pre: use for pre-release"
echo " - rel: for full release"
exit
fi
;;
*)
echo "No task given"
;;
esac