This repository has been archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease-to-github.sh
executable file
·93 lines (79 loc) · 2.05 KB
/
release-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
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
#!/usr/bin/env bash
set -ex
usage() {
echo "$(basename "$0") <version> <gh-username> <gh-token>"
exit 1
}
if [ $# -lt 3 ]; then
usage
fi
if ! which jq; then
echo 'you need jq -- brew install jq or http://stedolan.github.io/jq/'
exit 1
fi
VERSION="$1"
shift
GITHUB_USERNAME="$1"
shift
GITHUB_TOKEN="$1"
DIR="tmp/batterybar-$VERSION"
TAR="batterybar-$VERSION.tar.gz"
cleanup () {
rm -rf "$DIR"
rm "$(dirname "$DIR")/$TAR"
}
trap cleanup ERR EXIT
BIN="$( ./build.sh | tail -n1 )"
PLIST=com.github.blandinw.batterybar.plist
(
# prepare tmp dir for .tar.gz
mkdir -p "$DIR"
cp "$BIN" "$DIR"
cp "$PLIST" "$DIR"
# prepare install command
cp install.sh "$DIR/.install-helper.sh"
cat > "$DIR/install-batterybar.command" <<EOF
#!/usr/bin/env bash
set -ex
PLIST="$PLIST"
EOF
cat >> "$DIR/install-batterybar.command" <<'EOF'
cd "$(dirname $0)"
./.install-helper.sh batterybar "$PLIST"
echo "Installation successful!"
EOF
chmod +x "$DIR/install-batterybar.command"
# prepare uninstall command
cp uninstall.sh "$DIR/.uninstall-helper.sh"
cat > "$DIR/uninstall-batterybar.command" <<EOF
#!/usr/bin/env bash
set -ex
PLIST="$PLIST"
EOF
cat >> "$DIR/uninstall-batterybar.command" <<'EOF'
cd "$(dirname $0)"
./.uninstall-helper.sh batterybar "$PLIST"
echo "Uninstallation successful!"
EOF
chmod +x "$DIR/uninstall-batterybar.command"
# zip it
cd "$(dirname "$DIR")"
tar czvf "$TAR" "$(basename "$DIR")"
# create release
CURL_OUT="$(
curl https://api.github.com/repos/blandinw/batterybar/releases \
-XPOST \
-s -u "$GITHUB_USERNAME:$GITHUB_TOKEN" \
-d '{
"tag_name": "'"$VERSION"'",
"name": "'"$VERSION"'"
}'
)"
RELEASE_ID="$(echo "$CURL_OUT" | jq --raw-output '.id')"
# upload archive
curl "https://uploads.github.com/repos/blandinw/batterybar/releases/$RELEASE_ID/assets?name=$TAR" \
-XPOST \
-s -u "$GITHUB_USERNAME:$GITHUB_TOKEN" \
-H 'Content-Type: application/gzip' \
--data-binary "@$TAR"
)