forked from SteffeyDev/atemOSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-release.sh
executable file
·184 lines (158 loc) · 4.44 KB
/
generate-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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
GENERATE_POST_BODY() {
cat <<EOF
{
"tag_name": "v$NEXT_RELEASE",
"target_commitish": "master",
"name": "v${NEXT_RELEASE}",
"body": "* List changes in this version here",
"draft": true,
"prerelease": false
}
EOF
}
RED_COLOR="\033[0;31m"
GREY_COLOR="\033[0;37m"
NO_COLOR="\033[0m"
#
# Check arguments
#
if [[ -z $1 ]] ; then
echo -e "Pass in the path to the notarized atemOSC.app file as the first argument"
exit 1
fi
#
# Check if Github auth token exists
#
if [[ -z "${AUTOMATIC_RELEASE_GITHUB_TOKEN}" ]] ; then
echo -e "${RED_COLOR}You must specify your Github auth token.${NO_COLOR}"
echo -e "Visit https://github.com/settings/tokens and generate a new Personal Access Token with \"public_repo\" access only."
echo -e "Then EXPORT the generated token to an environment variable, for example:"
echo -e "\techo 'export AUTOMATIC_RELEASE_GITHUB_TOKEN=\"<your_generated_token>\"' >> ~/.bashrc"
exit 1
fi
#
# Check if Homebrew is installed
#
echo "Checking for Homebrew"
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
echo "Please install Homebrew: https://brew.sh/"
exit 1
else
brew update
fi
#
# Check if Git is installed
#
echo "Checking for git"
which -s git
if [[ $? != 0 ]] ; then
echo "Installing git"
brew install git
fi
git --version
#
# Check if Node is installed
#
echo "Checking for Node"
which -s node
if [[ $? != 0 ]] ; then
echo "Installing Node"
brew install node
fi
echo "node $(node --version)"
#
# Check if Node Package Manager is installed
#
echo "Checking for NPM"
which -s npm
if [[ $? != 0 ]] ; then
echo "Installing npm"
brew install npm
fi
echo "npm v$(npm --version)"
#
# Check if create-dmg is installed
#
echo "Checking for create-dmg"
which -s create-dmg
if [[ $? != 0 ]] ; then
echo "Installing create-dmg"
npm install --global create-dmg
fi
echo "create-dmg v$(create-dmg --version)"
#
# Ensure correct repository status
#
echo "Checking git repository status"
if ! [ $(git rev-parse --abbrev-ref HEAD) == "master" ] ; then
echo -e "${RED_COLOR}You must generate a release from \"master\", currently on branch: \"$(git rev-parse --abbrev-ref HEAD)\".${NO_COLOR}"
echo -e "\tgit checkout master"
exit 1
fi
# if origin isn't set
if [[ ! $(git config --get remote.origin.url) ]]
then
echo -e "Remote ${GREY_COLOR}origin${NO_COLOR} missing"
echo -e "You need to specify the remote repository manually"
echo "e.g. ${GREY_COLOR}git remote add origin https://github.com/SteffeyDev/atemOSC${NO_COLOR}"
exit 1
fi
# Obtained valid 'origin' remote, set REPOSITORY now
REPOSITORY=$(git config --get remote.origin.url | sed -E 's/(https?:\/\/(www.)?github.com\/|[email protected]:)([A-Za-z]+\/[A-Za-z]+).*/\3/')
git pull origin master
if [[ $? != 0 ]] ; then
echo -e "${RED_COLOR}Could not pull from origin master. Please resolve manually (perhaps you have local changes).${NO_COLOR}"
exit 1
fi
#
# Creating directory to work in
#
rm -rf temp_output
mkdir -p temp_output
cd temp_output
cp -R "$1" .
#
# Generating DMG
#
echo "Generating DMG"
create-dmg 'atemOSC.app' || true
if [[ $? != 0 ]] ; then
echo -e "${RED_COLOR}Could not generate DMG.${NO_COLOR}"
exit 1
fi
FILENAME=$(find "atemOSC "*.dmg)
mv "$FILENAME" "${FILENAME// /_}"
FILENAME=$(find atemOSC_*.dmg)
NEXT_RELEASE=$(echo $FILENAME | sed -E 's/atemOSC_(.*).dmg/\1/')
echo -e "Generated: ${GREY_COLOR}${FILENAME}${NO_COLOR}"
#
# Create tag if needed
#
if [ $(git tag -l "v$NEXT_RELEASE" | wc -l | xargs) -eq 0 ]; then
git tag -a "v$NEXT_RELEASE" -m "v$NEXT_RELEASE"
git push --tags
fi
#
# Notarize installer
#
./../notarize-dmg.sh $FILENAME
if [[ $? != 0 ]] ; then
echo -e "${RED_COLOR}Notarization Failed.${NO_COLOR}"
exit 1
fi
#
# GitHub Release
#
echo "Generating v${NEXT_RELEASE}"
RELEASE=$(curl --silent -H "Content-Type: application/json" -H "Authorization: token $AUTOMATIC_RELEASE_GITHUB_TOKEN" -X POST --data "$(GENERATE_POST_BODY)" "https://api.github.com/repos/${REPOSITORY}/releases")
EDIT_URL="$(node -p -e 'JSON.parse(process.argv[1]).html_url.replace('/\\/tag\\//', '/edit/')' "${RELEASE}")"
ASSET_URL="$(node -p -e 'JSON.parse(process.argv[1]).upload_url.replace('/\\{\\?name\,label\}/', '\"?name=${FILENAME}\"')' "${RELEASE}")"
echo "Uploading DMG file"
ASSET=$(curl --silent --data-binary @"$FILENAME" -H "Authorization: token $AUTOMATIC_RELEASE_GITHUB_TOKEN" -H "Content-Type: application/octet-stream" $ASSET_URL)
# Cleaning up
cd -
rm -rf temp_output
echo "✅ Release draft generated. Visit ${EDIT_URL}"