-
Notifications
You must be signed in to change notification settings - Fork 13
/
upload_release.command
executable file
·93 lines (76 loc) · 2.93 KB
/
upload_release.command
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
OWNER="uliwitness"
REPO="Stacksmith"
TOKEN=`security 2>&1 >/dev/null find-generic-password -ga GithubStacksmithUploadToken | cut -f2 -d'"'`
cd `dirname $0`
REPO_DIR=`pwd`
cd ${REPO_DIR}/../
BUILD_DEST_PATH=`pwd`/Output/
ARCHIVE_PATH="$BUILD_DEST_PATH/Stacksmith.tgz"
RSS_PATH="${REPO_DIR}/docs/nightlies/stacksmith_nightlies.rss"
INFO_PLIST_PATH="${BUILD_DEST_PATH}/Stacksmith.app/Contents/Info.plist"
VERSION=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$INFO_PLIST_PATH")
VERSION_TAG="${VERSION// /_}"
VERSION_TAG="${VERSION_TAG//(/_}"
VERSION_TAG="${VERSION_TAG//)/_}"
VERSION_TAG="${VERSION_TAG//__/_}"
VERSION_TAG=$"$(echo -e "${VERSION_TAG}" | sed -e 's/[[_]]*$//')"
if [[ $VERSION_TAG == *"a"* || $VERSION_TAG == *"b"* ]]; then
IS_PRERELEASE="true"
else
IS_PRERELEASE="false"
fi
DESCRIPTION=$(xmllint --xpath '//channel/item/description/text()' "$RSS_PATH" | textutil -format html -convert txt -stdin -stdout)
DESCRIPTION="${DESCRIPTION//<h3>/### }"
DESCRIPTION="${DESCRIPTION//<\/h3>/<br/>}"
DESCRIPTION=$(echo "$DESCRIPTION" | textutil -format html -convert txt -stdin -stdout)
DESCRIPTION="${DESCRIPTION//•/-}"
DESCRIPTION="${DESCRIPTION// / }"
DESCRIPTION="${DESCRIPTION//\"/\\\"}"
DESCRIPTION=$(echo -e "$DESCRIPTION" | sed -e :a -e '$!N;s/\n/\\n/;ta')
## Make a draft release json with a markdown body
release='"tag_name": "v'"$VERSION_TAG"'", "target_commitish": "master", "name": "Stacksmith '"$VERSION"'", '
body=\"$DESCRIPTION\"
body='"body": '$body', '
release=$release$body
release=$release'"draft": false, "prerelease": '"$IS_PRERELEASE"
release='{'$release'}'
url="https://api.github.com/repos/$OWNER/$REPO/releases"
echo "$release"
succ=$(curl -H "Authorization: token $TOKEN" --data "$release" "$url")
## In case of success, we upload a file
upload=$(echo $succ | grep upload_url)
if [[ $? -eq 0 ]]; then
echo Release created.
else
echo "$succ"
echo Error creating release!
exit 1
fi
echo "$(tput setaf 6)$(tput bold)===== Uploading Binary =====$(tput sgr0)"
cd "`dirname ${ARCHIVE_PATH}`"
ARCHIVE_NAME="`basename ${ARCHIVE_PATH}`"
# $upload is like:
# "upload_url": "https://uploads.github.com/repos/:owner/:repo/releases/:ID/assets{?name,label}",
upload=$(echo "$upload" | egrep -o "\"upload_url\":[ \t]*\"(.+?)\"," | head -n 1)
upload=$(echo $upload | cut -d "\"" -f4 | cut -d "{" -f1)
upload="$upload?name=${ARCHIVE_NAME}"
echo "Uploading to: $upload"
succ=$(curl -L --post301 --post302 --post303 \
-H "Authorization: token $TOKEN" \
-H "Content-Type: $(file -b --mime-type $ARCHIVE_NAME)" \
-H "Accept: application/vnd.github.v3+json" \
--data-binary @${ARCHIVE_NAME} $upload)
echo "$succ"
download=$(echo $succ | egrep -o "\"url\":[ \t]*\"(.+?)\"," | head -n 1)
if [[ $? -eq 0 ]]; then
releaseurl="https://github.com/${OWNER}/${REPO}/releases/tag/v${VERSION_TAG}"
echo "New release at: $releaseurl"
open -a "Safari" "$releaseurl"
echo -ne '\007'
else
echo Upload error!
echo "$download"
echo -ne '\007'
exit 2
fi