-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-release.sh
executable file
·61 lines (46 loc) · 1.41 KB
/
upload-release.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
#!/usr/bin/env bash
set -u
API_ENDPOINT="https://api.github.com"
UPLOAD_ENDPOINT="https://uploads.github.com"
TAG=$(git tag)
if [[ ! "$TAG" =~ v[0-9]+ ]]; then
echo -e "Tag '$TAG' incorrectly formatted"
exit 1
fi
echo "Tag: $TAG"
# TODO better file name handling
FILE_LOCATION="app/build/outputs/apk/release/app-release.apk"
if [[ ! -f "$FILE_LOCATION" ]]; then
echo "Please run ./gradlew :app:assembleRelease first"
exit 2
fi
SIZE_LIMIT=4000000
SIZE=$(stat --printf="%s" "$FILE_LOCATION")
if [[ "$SIZE" -gt "$SIZE_LIMIT" ]]; then
echo "File too large"
exit 4
fi
read -p "Github username: " USERNAME
read -s -p "Github password: " PASSWORD
echo
echo "Creating release..."
read -r -d '' CREATE_PAYLOAD <<HERE
{
"tag_name": "$TAG",
"name": "$TAG"
}
HERE
echo "$CREATE_PAYLOAD"
RESPONSE=$(curl -s -X POST -u "$USERNAME:$PASSWORD" "$API_ENDPOINT/repos/0queue/claw-for-lobsters/releases" -d "$CREATE_PAYLOAD")
ID=$(echo "$RESPONSE" | jq '.id')
if [[ "$ID" = "null" ]]; then
echo "Error while creating"
echo "$RESPONSE"
echo 3
fi
echo "Created release with ID $ID"
# TODO better file name handling
FILENAME="app-release-$TAG.apk"
echo "Creating release asset $FILENAME..."
RESPONSE2=$(curl -s -X POST -u "$USERNAME:$PASSWORD" "$UPLOAD_ENDPOINT/repos/0queue/claw-for-lobsters/releases/$ID/assets?name=$FILENAME" -H "Content-Type: application/zip" --data-binary "@$FILE_LOCATION")
echo "Done"