forked from spinupwp/spinupwp-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·252 lines (213 loc) · 7.98 KB
/
deploy.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
#! /bin/bash
# See https://github.com/GaryJones/wordpress-plugin-svn-deploy for instructions and credits.
#
# Steps to deploying:
#
# 1. Ask for plugin slug.
# 2. Ask for local plugin directory.
# 3. Check local plugin directory exists.
# 4. Ask for main plugin file name.
# 5. Check main plugin file exists.
# 6. Check readme.txt version matches main plugin file version.
# 7. Ask for temporary SVN path.
# 8. Ask for remote SVN repo.
# 9. Ask for SVN username.
# 10. Ask if input is correct, and give chance to abort.
# 11. Check if Git tag exists for version number (must match exactly).
# 12. Checkout SVN repo.
# 13. Set to SVN ignore some GitHub-related files.
# 14. Export HEAD of master from git to the trunk of SVN.
# 15. Initialise and update and git submodules.
# 16. Move /trunk/assets up to /assets.
# 17. Move into /trunk, and SVN commit.
# 18. Move into /assets, and SVN commit.
# 19. Copy /trunk into /tags/{version}, and SVN commit.
# 20. Delete temporary local SVN checkout.
echo
echo "WordPress Plugin SVN Deploy v3.0.0"
echo
echo "Let's collect some information first. There are six questions."
echo
echo "Default values are in brackets - just hit enter to accept them."
echo
# Set up some default values. Feel free to change these in your own script
PLUGINSLUG="spinupwp"
CURRENTDIR=$(pwd)
default_svnpath="/tmp/$PLUGINSLUG"
default_svnurl="https://plugins.svn.wordpress.org/$PLUGINSLUG"
default_svnuser="spinupwp"
default_plugindir="$CURRENTDIR"
default_mainfile="$PLUGINSLUG.php"
echo "Q1. Your local plugin root directory (the Git repo)."
printf "($default_plugindir): "
read -e input
input="${input%/}" # Strip trailing slash
PLUGINDIR="${input:-$default_plugindir}" # Populate with default if empty
echo
# Check directory exists.
if [ ! -d "$PLUGINDIR" ]; then
echo "Directory $PLUGINDIR not found. Aborting."
exit 1;
fi
printf "Q2. Name of the main plugin file ($default_mainfile): "
read -e input
MAINFILE="${input:-$default_mainfile}" # Populate with default if empty
echo
# Check main plugin file exists.
if [ ! -f "$PLUGINDIR/$MAINFILE" ]; then
echo "Plugin file $PLUGINDIR/$MAINFILE not found. Aborting."
exit 1;
fi
echo "Checking version in main plugin file matches version in readme.txt file..."
echo
# Check version in readme.txt is the same as plugin file after translating both to Unix line breaks to work around grep's failure to identify Mac line breaks
PLUGINVERSION=$(grep -i "Version:" "$PLUGINDIR/$MAINFILE" | awk -F' ' '{print $NF}' | tr -d '\r')
echo "$MAINFILE version: $PLUGINVERSION"
READMEVERSION=$(grep -i "Stable tag:" "$PLUGINDIR/readme.txt" | awk -F' ' '{print $NF}' | tr -d '\r')
echo "readme.txt version: $READMEVERSION"
if [ "$READMEVERSION" = "trunk" ]; then
echo "Version in readme.txt & $MAINFILE don't match, but Stable tag is trunk. Let's continue..."
elif [ "$PLUGINVERSION" != "$READMEVERSION" ]; then
echo "Version in readme.txt & $MAINFILE don't match. Exiting...."
exit 1;
elif [ "$PLUGINVERSION" = "$READMEVERSION" ]; then
echo "Versions match in readme.txt and $MAINFILE. Let's continue..."
fi
echo
echo "Q3. Path to a local directory where a temporary SVN checkout can be made."
printf "Don't add trunk ($default_svnpath): "
read -e input
input="${input%/}" # Strip trailing slash
SVNPATH="${input:-$default_svnpath}" # Populate with default if empty
echo
echo "Q4. Remote SVN repo on WordPress.org."
printf "($default_svnurl): "
read -e input
input="${input%/}" # Strip trailing slash
SVNURL="${input:-$default_svnurl}" # Populate with default if empty
echo
printf "Q5. Your WordPress repo SVN username ($default_svnuser): "
read -e input
SVNUSER="${input:-$default_svnuser}" # Populate with default if empty
echo
echo "That's all of the data collected."
echo
echo "Slug: $PLUGINSLUG"
echo "Plugin directory: $PLUGINDIR"
echo "Main file: $MAINFILE"
echo "Temp checkout path: $SVNPATH"
echo "Remote SVN repo: $SVNURL"
echo "SVN username: $SVNUSER"
echo
printf "OK to proceed (Y|n)? "
read -e input
PROCEED="${input:-y}"
echo
# Allow user cancellation
if [ $(echo "$PROCEED" |tr [:upper:] [:lower:]) != "y" ]; then echo "Aborting..."; exit 1; fi
# Let's begin...
echo ".........................................."
echo
echo "Preparing to deploy WordPress plugin"
echo
echo ".........................................."
echo
echo
composer -v > /dev/null 2>&1
COMPOSER_IS_INSTALLED=$?
if [[ $COMPOSER_IS_INSTALLED -ne 0 ]]; then
echo "Composer not installed. Aborting."
exit 1
fi
echo "Changing to $PLUGINDIR"
cd "$PLUGINDIR"
# Check for git tag (may need to allow for leading "v"?)
# if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"
if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"
then
echo "Git tag $PLUGINVERSION does exist. Let's continue..."
else
echo "$PLUGINVERSION does not exist as a git tag. Aborting.";
exit 1;
fi
echo
echo "Creating local copy of SVN repo trunk..."
svn checkout "$SVNURL" "$SVNPATH" --depth immediates
svn update --quiet "$SVNPATH/trunk" --set-depth infinity
echo "Ignoring GitHub specific files"
svn propset svn:ignore "README.md
deploy.sh
Thumbs.db
.github/*
.git
.gitattributes
.gitignore
composer.lock" "$SVNPATH/trunk/"
echo "Exporting the HEAD of master from git to the trunk of SVN"
git checkout-index -a -f --prefix="$SVNPATH/trunk/"
# If submodule exist, recursively check out their indexes
if [ -f ".gitmodules" ]
then
echo "Exporting the HEAD of each submodule from git to the trunk of SVN"
git submodule init
git submodule update
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
#url_key=$(echo $path_key | sed 's/\.path/.url/')
#url=$(git config -f .gitmodules --get "$url_key")
#git submodule add $url $path
echo "This is the submodule path: $path"
echo "The following line is the command to checkout the submodule."
echo "git submodule foreach --recursive 'git checkout-index -a -f --prefix=$SVNPATH/trunk/$path/'"
git submodule foreach --recursive 'git checkout-index -a -f --prefix=$SVNPATH/trunk/$path/'
done
fi
echo
echo "Running composer install..."
composer install --optimize-autoloader --no-dev -d "$SVNPATH/trunk/"
echo
# Support for the /assets folder on the .org repo.
echo "Moving WP assets."
# Make the directory if it doesn't already exist
mkdir -p "$SVNPATH/assets/"
mv "$SVNPATH"/trunk/wp-assets/* "$SVNPATH/assets/"
rm "$SVNPATH/assets/.gitkeep"
svn propset svn:mime-type image/png *.png
svn propset svn:mime-type image/jpeg *.jpg
svn add --force "$SVNPATH/assets/"
svn delete --force "$SVNPATH/trunk/wp-assets"
echo
echo "Changing directory to SVN and committing to trunk."
cd "$SVNPATH/trunk/"
# Delete all files that should not now be added.
svn status | grep -v "^.[ \t]*\..*" | grep "^\!" | awk '{print $2"@"}' | xargs svn del
# Add all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2"@"}' | xargs svn add
svn commit --username="$SVNUSER" -m "Preparing for $PLUGINVERSION release"
echo
echo "Updating WordPress plugin repo assets and committing."
cd "$SVNPATH/assets/"
# Delete all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^\!" | awk '{print $2"@"}' | xargs svn del
# Add all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2"@"}' | xargs svn add
svn update --quiet --accept working "$SVNPATH"/assets/*
svn resolve --accept working "$SVNPATH"/assets/*
svn commit --username="$SVNUSER" -m "Updating assets"
echo
echo "Creating new SVN tag and committing it."
cd "$SVNPATH"
svn copy --quiet trunk/ "tags/$PLUGINVERSION/"
# Remove trunk directory from tag directory
svn delete --force --quiet "$SVNPATH/tags/$PLUGINVERSION/trunk"
svn update --quiet --accept working "$SVNPATH/tags/$PLUGINVERSION"
#svn resolve --accept working "$SVNPATH/tags/$PLUGINVERSION"/*
cd "$SVNPATH/tags/$PLUGINVERSION"
svn commit --username="$SVNUSER" -m "Tagging version $PLUGINVERSION"
echo
echo "Removing temporary directory $SVNPATH."
cd "$SVNPATH"
cd ..
rm -fr "$SVNPATH/"
echo "*** FIN ***"