-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsvn-push
executable file
·266 lines (215 loc) · 6.78 KB
/
svn-push
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
#!/usr/bin/env bash
# By Luiz Bills based on work by Barry Kooij and Mike Jolley
# License: GPL v3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# ----- START EDITING HERE -----
# The slug of your WordPress.org plugin
# You need publish your plugin first: https://wordpress.org/plugins/developers/add/
WP_PLUGIN_SLUG="your_wp_plugin_slug"
# The GITHUB repository
# format: username/repository (example: luizbills/wp-tweaks)
GITHUB_REPO_SLUG="your_gh_username/your_gh_repo"
# The main Github repository branch
MAIN_BRANCH="main"
# directory with plugin icon, banner and screenshots used in https://wordpress.org
PLUGIN_ASSETS_DIR=".wordpress-org"
# ----- STOP EDITING HERE -----
# Parse cli arguments
ONLY_TRUNK="no"
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
--only-trunk)
ONLY_TRUNK="yes"
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
set -e
clear >$( tty ) # clear the terminal
echo "--------------------------------------------"
echo " Github to WordPress.org RELEASER "
echo "--------------------------------------------"
if [ "$ONLY_TRUNK" == "yes" ];
then
read -p "PRESS [ENTER] TO BEGIN UPDATING THE \"trunk\""
else
REMOTE_README_TXT="https://raw.githubusercontent.com/${GITHUB_REPO_SLUG}/${MAIN_BRANCH}/readme.txt"
STABLE_TAG=$( curl -m 3 -s $REMOTE_README_TXT | sed -n 's/Stable tag: \([0-9]\.[0-9]\.[0-9]*\).*/\1/p' )
trim_spaces() {
# Usage: trim_spaces " example string "
: "${1#"${1%%[![:space:]]*}"}"
: "${_%"${_##*[![:space:]]}"}"
printf '%s\n' "$_"
}
STABLE_TAG=$( trim_spaces $STABLE_TAG )
# ASK INFO
read -p "RELEASE VERSION$( [ $STABLE_TAG ] && echo " [$STABLE_TAG]" || echo "" ): " VERSION
VERSION=${VERSION:-$STABLE_TAG}
echo "--------------------------------------------"
echo ""
echo "Before continuing, confirm that you have done the following:"
echo ""
read -p " - Added a changelog for "${VERSION}"?"
read -p " - Set version in the main file to "${VERSION}"?"
read -p " - Set stable tag in the readme.txt file to "${VERSION}"?"
read -p " - Updated the POT file?"
read -p " - Committed all changes up to GITHUB?"
echo ""
read -p "PRESS [ENTER] TO BEGIN RELEASING "${VERSION}
clear >$( tty ) # clear the terminal
fi
SVN_REPO="http://plugins.svn.wordpress.org/${WP_PLUGIN_SLUG}/"
GIT_REPO="https://github.com/${GITHUB_REPO_SLUG}.git"
CURRENT_DIR="."
DIR="$( realpath ${CURRENT_DIR} )"
TEMP_GITHUB_REPO="/tmp/${WP_PLUGIN_SLUG}-git"
TEMP_SVN_REPO="/tmp/${WP_PLUGIN_SLUG}-svn"
# DELETE OLD TEMP DIRS
rm -Rf $TEMP_GITHUB_REPO
rm -rf $TEMP_SVN_REPO
# CLONE GIT DIR
echo "Cloning GIT repository from GITHUB"
git clone --progress --recurse-submodules $GIT_REPO $TEMP_GITHUB_REPO || { echo "Unable to clone repo."; exit 1; }
# MOVE INTO GIT DIR
cd "$TEMP_GITHUB_REPO"
clear >$( tty ) # clear the terminal
# LIST BRANCHES
git fetch origin
echo "WHICH BRANCH DO YOU WISH TO DEPLOY?"
git branch -r || { echo "Unable to list branches."; exit 1; }
echo ""
read -p "origin/" BRANCH
# Switch Branch
echo "Switching to branch"
git checkout ${BRANCH} || { echo "Unable to checkout branch."; exit 1; }
if [[ -f "composer.json" ]];
then
echo "Installing composer packages..."
composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader || { echo "Unable to install composer packages."; exit 1; }
fi
if [[ -f "package.json" ]];
then
echo "Installing NPM packages..."
npm ci --no-progress || { echo "Unable to install npm packages."; exit 1; }
fi
echo "Looking for PHP syntax errors"
find . -type f -name '*.php' ! -path './vendor/*' -print0 | while read -d $'\0' file
do
output=$(php -l "$file")
if [ ! $? -eq 0 ];
then
echo -e "\e[31mPHP Syntax Error!\e[0m"
exit 1
fi
done
echo "No syntax errors found"
# REMOVE UNWANTED FILES & FOLDERS
echo "Removing unwanted files"
rm -rf .git
rm -rf .github
rm -rf tests
rm -rf docs
rm -rf scripts
rm -rf logs
rm -rf node_modules
rm -rf wp-build
rm -f .gitattributes
rm -f .gitignore
rm -f .gitmodules
rm -f .editorconfig
rm -f .prettierrc.json
rm -f package-lock.json
rm -f pnpm-lock.yaml
rm -f composer.lock
rm -f phpunit.xml
rm -f phpunit.xml.dist
rm -f README.md
rm -f CONTRIBUTING.md
echo ""
read -p "PRESS [ENTER] TO DEPLOY BRANCH "${BRANCH}
clear >$( tty ) # clear the terminal
# CHECKOUT SVN DIR IF NOT EXISTS
echo "Checking out WordPress.org plugin SVN repository"
svn checkout $SVN_REPO $TEMP_SVN_REPO || { echo "Unable to checkout repo."; exit 1; }
# MOVE INTO SVN DIR
cd "$TEMP_SVN_REPO"
# UPDATE SVN
echo "Updating SVN"
svn update || { echo "Unable to update SVN."; exit 1; }
# DELETE TRUNK
echo "Replacing trunk"
rm -Rf trunk/
# COPY GIT DIR TO TRUNK
cp -a "${TEMP_GITHUB_REPO}/." trunk/
if [[ -d "trunk/${PLUGIN_ASSETS_DIR}" ]];
then
echo "Checking Plugin icon, banner and screenshots..."
rm -Rf assets/
mv trunk/$PLUGIN_ASSETS_DIR assets
fi
if [ "$ONLY_TRUNK" == "no" ];
then
# DELETE VERSION TAG
rm -Rf tags/${VERSION}
# COPY TRUNK TO TAGS/$VERSION
echo "Copying trunk to new tag"
cp -a trunk/ tags/${VERSION}
fi
# 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
clear >$( tty ) # clear the terminal
# DO SVN COMMIT
echo "Showing SVN status"
svn status
# PROMPT USER
echo ""
if [ "$ONLY_TRUNK" == "no" ];
then
read -p "PRESS [ENTER] TO COMMIT RELEASE "${VERSION}" TO WORDPRESS.ORG"
else
read -p "PRESS [ENTER] TO UPDATE THE \"trunk\" ON WORDPRESS.ORG"
fi
echo ""
clear >$( tty ) # clear the terminal
# DEPLOY
echo ""
echo "Committing to WordPress.org...this may take a while..."
if [ "$ONLY_TRUNK" == "no" ];
then
COMMIT_MESSAGE="Release "${VERSION}", see readme.txt for the changelog."
else
COMMIT_MESSAGE="Update trunk."
fi
svn commit -m "$COMMIT_MESSAGE" || { echo "Unable to commit."; exit 1; }
# REMOVE THE TEMP DIRS
echo "CLEANING UP..."
rm -Rf "$TEMP_GITHUB_REPO"
rm -Rf "$TEMP_SVN_REPO"
# DONE, BYE
echo "RELEASER DONE!"