-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.sh
288 lines (237 loc) · 9.01 KB
/
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/sh
SCRIPT_VERSION="2"
set -e
clear
# ASK INFO
echo "---------------------------------------------------------------------"
echo " GitHub to WordPress.org Deployment Script v${SCRIPT_VERSION} "
echo "---------------------------------------------------------------------"
read -p "Enter the ROOT PATH of the plugin you want to release: " ROOT_PATH
if [[ -d $ROOT_PATH ]]; then
echo "---------------------------------------------------------------------"
echo "New ROOT PATH has been set."
cd $ROOT_PATH
elif [[ -f $ROOT_PATH ]]; then
echo "---------------------------------------------------------------------"
read -p "$ROOT_PATH is a file. Please enter a ROOT PATH: " ROOT_PATH
fi
echo "---------------------------------------------------------------------"
read -p "Tag and Release Version: " VERSION
echo "---------------------------------------------------------------------"
echo ""
echo "Before continuing, confirm that you have done the following :"
echo ""
read -p " - Added a changelog for v"${VERSION}"?"
read -p " - Set version in the readme.txt and main file to v"${VERSION}"?"
read -p " - Set stable tag in the readme.txt file to v"${VERSION}"?"
read -p " - Updated the POT file?"
read -p " - Committed all changes up to GitHub?"
echo ""
read -p "Press [ENTER] to begin releasing v"${VERSION}
clear
echo "-------------------------------------------------------"
echo "Did you tag a pre-release last?"
read -p "Enter Y for Yes or N for No "${BETA}""
echo "-------------------------------------------------------"
clear
# Check if version is already released.
if ${BETA} = 'n' && $ROOT_PATH git show-ref --tags --exclude-existing | egrep -q "refs/tags/v${VERSION}"; then
echo "---------------------------------------------------------------------"
echo "Version already tagged and released.";
echo "---------------------------------------------------------------------"
echo "Run this script again and enter another version.";
echo "---------------------------------------------------------------------"
exit 1;
else
echo "---------------------------------------------------------------------"
echo "Yeah! v${VERSION} is not yet a release.";
echo "---------------------------------------------------------------------"
fi
read -p "Enter WordPress plugin slug: " SVN_REPO_SLUG
clear
echo "---------------------------------------------------------------------"
echo "Now processing..."
echo "---------------------------------------------------------------------"
SVN_REPO_URL="https://plugins.svn.wordpress.org"
# Set WordPress.org Plugin URL
SVN_REPO=$SVN_REPO_URL"/"$SVN_REPO_SLUG"/"
# Set temporary SVN folder for WordPress release.
TEMP_SVN_REPO=${SVN_REPO_SLUG}"-svn"
# Delete old SVN cache just incase it was not cleaned before after the last release.
rm -Rf $ROOT_PATH$TEMP_SVN_REPO
# CHECKOUT SVN DIR IF NOT EXISTS
if [[ ! -d $TEMP_SVN_REPO ]]; then
echo "Checking out WordPress.org plugin repository."
echo "---------------------------------------------------------------------"
svn checkout $SVN_REPO $TEMP_SVN_REPO || { echo "Unable to checkout repo."; exit 1; }
fi
clear
echo "---------------------------------------------------------------------"
read -p "Enter GitHub username: " GITHUB_USER
echo "---------------------------------------------------------------------"
read -p "Enter repository slug: " GITHUB_REPO_NAME
clear
# Set temporary folder for GitHub release.
TEMP_GITHUB_REPO="prepping-release"
# Delete old GitHub cache just incase it was not cleaned before after the last release.
rm -Rf $ROOT_PATH$TEMP_GITHUB_REPO
echo "---------------------------------------------------------------------"
echo "Is the line secure?"
echo "---------------------------------------------------------------------"
echo " - y for SSH"
echo " - n for HTTPS"
read -p "" SECURE_LINE
# Set GitHub Repository URL
if [[ ${SECURE_LINE} = "y" ]]; then
GIT_REPO="[email protected]:"${GITHUB_USER}"/"${GITHUB_REPO_NAME}".git"
else
GIT_REPO="https://github.com/"${GITHUB_USER}"/"${GITHUB_REPO_NAME}".git"
fi;
clear
# CLONE GIT DIR
echo "---------------------------------------------------------------------"
echo "Cloning GIT repository from GitHub"
echo "---------------------------------------------------------------------"
git clone --progress $GIT_REPO $TEMP_GITHUB_REPO || { echo "Unable to clone repo."; exit 1; }
# MOVE INTO GIT DIR
cd $ROOT_PATH$TEMP_GITHUB_REPO
clear
# Which Remote?
echo "---------------------------------------------------------------------"
read -p "Which remote are we fetching? Default is 'origin'" ORIGIN
echo "---------------------------------------------------------------------"
# IF REMOTE WAS LEFT EMPTY THEN FETCH ORIGIN BY DEFAULT
if [[ -z ${ORIGIN} ]]; then
git fetch origin
# Set ORIGIN as origin if left blank
ORIGIN=origin
else
git fetch ${ORIGIN}
fi;
clear
# List Branches
echo "---------------------------------------------------------------------"
git branch -r || { echo "Unable to list branches."; exit 1; }
echo "---------------------------------------------------------------------"
read -p "Which branch do you wish to release? /" BRANCH
# Switch Branch
echo "---------------------------------------------------------------------"
echo "Switching to branch "${BRANCH}
# IF BRANCH WAS LEFT EMPTY THEN FETCH "master" BY DEFAULT
if [[ -z ${BRANCH} ]]; then
BRANCH=master
else
git checkout ${BRANCH} || { echo "Unable to checkout branch."; exit 1; }
fi;
echo "---------------------------------------------------------------------"
read -p "Press [ENTER] to remove unwanted files before release."
# REMOVE UNWANTED FILES & FOLDERS
echo "---------------------------------------------------------------------"
echo "Removing unwanted files..."
echo "---------------------------------------------------------------------"
rm -Rf .git
rm -Rf .github
rm -Rf .wordpress-org
rm -Rf tests
rm -Rf apigen
rm -Rf node_modules
rm -Rf src
rm -Rf sass
rm -Rf scss
rm -Rf assets/sass
rm -Rf assets/scss
rm -Rf .idea/*
rm -f .babelrc
rm -f .editorconfig
rm -f .eslintignore
rm -f .eslintrc.json
rm -f .gitattributes
rm -f .gitignore
rm -f .gitmodules
rm -f gulpfile.js
rm -f .idea
rm -f *.md
rm -f *.rb
rm -f *.sh
rm -f *.lock
rm -f .coveralls.yml
rm -f .scrutinizer.yml
rm -f .travis.yml
rm -f *.yml
rm -f Gruntfile.js
rm -f composer.json
rm -f package.json
rm -f package-lock.json
rm -f .jscrsrc
rm -f .jshintrc
rm -f phpunit.xml
rm -f phpunit.xml.dist
rm -f *.xml
rm -f .editorconfig
rm -f apigen.neon
rm -f screenshot-*.jpg
rm -f screenshot-*.png
clear
echo "---------------------------------------------------------------------"
read -p "READY! Press [ENTER] to deploy branch "${BRANCH}
# MOVE INTO SVN DIR
cd "../"$TEMP_SVN_REPO
# UPDATE SVN
echo "---------------------------------------------------------------------"
echo "Updating SVN"
svn update || { echo "Unable to update SVN."; exit 1; }
# DELETE TRUNK
echo "---------------------------------------------------------------------"
echo "Replacing TRUNK folder."
rm -Rf trunk/
# COPY GIT DIR TO TRUNK
cp -R "../"$TEMP_GITHUB_REPO trunk/
# DO THE ADD ALL NOT KNOWN FILES UNIX COMMAND
svn add --force * --auto-props --parents --depth infinity -q
# DO THE REMOVE ALL DELETED FILES UNIX COMMAND
MISSING_PATHS=$( svn status | sed -e '/^!/!d' -e 's/^!//' )
# iterate over filepaths
for MISSING_PATH in $MISSING_PATHS; do
svn rm --force "$MISSING_PATH"
done
# COPY TRUNK TO TAGS/$VERSION
echo "---------------------------------------------------------------------"
echo "Copying TRUNK to a new tag"
echo "---------------------------------------------------------------------"
svn copy trunk tags/${VERSION} || { echo "Unable to create tag."; exit 1; }
# DO SVN COMMIT
clear
echo "SVN Status"
svn status
# PROMPT USER
echo "---------------------------------------------------------------------"
read -p "Press [ENTER] to commit release "${VERSION}" to WordPress.org AND GitHub"
echo "---------------------------------------------------------------------"
# CREATE THE GITHUB RELEASE
echo "Creating release on GitHub repository."
cd "$GITPATH"
echo "---------------------------------------------------------------------"
echo "Tagging new version in git"
git tag -a "v${VERSION}" -m "Tagging version v${VERSION}"
echo "---------------------------------------------------------------------"
echo "Pushing latest commit to origin, with tags"
git push origin master
git push origin master --tags
# DEPLOY
echo "---------------------------------------------------------------------"
echo "Committing to WordPress.org... this may take a while..."
svn commit -m "Releasing "${VERSION}"" || { echo "Unable to commit."; exit 1; }
# REMOVE THE TEMP DIRS
echo "---------------------------------------------------------------------"
echo "Cleaning Up..."
echo "---------------------------------------------------------------------"
cd "../"
rm -Rf $ROOT_PATH$TEMP_GITHUB_REPO
rm -Rf $ROOT_PATH$TEMP_SVN_REPO
clear
# DONE
echo "---------------------------------------------------------------------"
echo "Release Done!"
echo "---------------------------------------------------------------------"
read -p "Press [ENTER] to exit program."
clear