Skip to content
This repository was archived by the owner on May 10, 2023. It is now read-only.

Commit c8011eb

Browse files
committed
Workflow changes
- Update name of this deploy script repo (it's no longer focused on using Git Flow). - Add summary of steps to top comments. - Bump to version 3.0.0. - Change question numbers. - Change from deprecated backticks to dollar parens format. - Remove notes on not have trailing slash, as this is already handled. - Re-order questions, so intermediate checks can be done, and if necessary, fail early. - Check local plugin (Git) directory exists. - Check main plugin file exists. - Remove `GITPATH` variable, as it was mostly unused. - Added empty lines between sections of output for readability. - Check git tag exists (must exactly match plugin version).
1 parent 544be04 commit c8011eb

File tree

1 file changed

+111
-73
lines changed

1 file changed

+111
-73
lines changed

deploy.sh

Lines changed: 111 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,122 @@
11
#! /bin/bash
2-
# See https://github.com/GaryJones/wordpress-plugin-git-flow-svn-deploy for instructions and credits.
3-
4-
echo
5-
echo "WordPress Plugin Git-Flow SVN Deploy v2.1.0"
6-
echo
7-
echo "Step 1. Let's collect some information first."
2+
# See https://github.com/GaryJones/wordpress-plugin-svn-deploy for instructions and credits.
3+
#
4+
# Steps to deploying:
5+
#
6+
# 1. Ask for plugin slug.
7+
# 2. Ask for local plugin directory.
8+
# 3. Check local plugin directory exists.
9+
# 4. Ask for main plugin file name.
10+
# 5. Check main plugin file exists.
11+
# 6. Check readme.txt version matches main plugin file version.
12+
# 7. Ask for temporary SVN path.
13+
# 8. Ask for remote SVN repo.
14+
# 9. Ask for SVN username.
15+
# 10. Ask if input is correct, and give chance to abort.
16+
# 11. Check if Git tag exists for version number (must match exactly).
17+
# 12. Checkout SVN repo.
18+
# 13. Set to SVN ignore some GitHub-related files.
19+
# 14. Export HEAD of master from git to the trunk of SVN.
20+
# 15. Initialise and update and git submodules.
21+
# 16. Move /trunk/assets up to /assets.
22+
# 17. Move into /trunk, and SVN commit.
23+
# 18. Move into /assets, and SVN commit.
24+
# 19. Copy /trunk into /tags/{version}, and SVN commit.
25+
# 20. Delete temporary local SVN checkout.
26+
27+
echo
28+
echo "WordPress Plugin SVN Deploy v3.0.0"
29+
echo
30+
echo "Let's collect some information first. There are six questions."
831
echo
932
echo "Default values are in brackets - just hit enter to accept them."
1033
echo
1134

1235
# Get some user input
1336
# Can't use the -i flag for read, since that doesn't work for bash 3
14-
printf "1a) WordPress Repo Plugin Slug e.g. my-awesome-plugin: "
37+
printf "Q1. WordPress Repo Plugin Slug e.g. my-awesome-plugin: "
1538
read -e PLUGINSLUG
1639
echo
1740

1841
# Set up some default values. Feel free to change these in your own script
19-
CURRENTDIR=`pwd`
42+
CURRENTDIR=$(pwd)
2043
default_svnpath="/tmp/$PLUGINSLUG"
2144
default_svnurl="https://plugins.svn.wordpress.org/$PLUGINSLUG"
2245
default_svnuser="GaryJ"
2346
default_plugindir="$CURRENTDIR/$PLUGINSLUG"
2447
default_mainfile="$PLUGINSLUG.php"
2548

26-
echo "1b) Path to a local directory where a temporary SVN checkout can be made."
27-
printf "No trailing slash and don't add trunk ($default_svnpath): "
28-
read -e input
49+
echo "Q2. Your local plugin root directory (the Git repo)."
50+
printf "($default_plugindir): "
51+
read -e input
2952
input="${input%/}" # Strip trailing slash
30-
SVNPATH="${input:-$default_svnpath}" # Populate with default if empty
53+
PLUGINDIR="${input:-$default_plugindir}" # Populate with default if empty
3154
echo
3255

33-
echo "1c) Remote SVN repo on WordPress.org. No trailing slash."
34-
printf "($default_svnurl): "
56+
# Check directory exists.
57+
if [ ! -d "$PLUGINDIR" ]; then
58+
echo "Directory $PLUGINDIR not found. Aborting."
59+
exit 1;
60+
fi
61+
62+
printf "Q3. Name of the main plugin file ($default_mainfile): "
3563
read -e input
36-
input="${input%/}" # Strip trailing slash
37-
SVNURL="${input:-$default_svnurl}" # Populate with default if empty
64+
MAINFILE="${input:-$default_mainfile}" # Populate with default if empty
65+
echo
66+
67+
# Check main plugin file exists.
68+
if [ ! -f "$PLUGINDIR/$MAINFILE" ]; then
69+
echo "Plugin file $PLUGINDIR/$MAINFILE not found. Aborting."
70+
exit 1;
71+
fi
72+
73+
echo "Checking version in main plugin file matches version in readme.txt file..."
3874
echo
3975

40-
printf "1d) Your WordPress repo SVN username ($default_svnuser): "
76+
# 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
77+
PLUGINVERSION=$(grep -i "Version:" $PLUGINDIR/$MAINFILE | awk -F' ' '{print $NF}' | tr -d '\r')
78+
echo "$MAINFILE version: $PLUGINVERSION"
79+
READMEVERSION=$(grep -i "Stable tag:" $PLUGINDIR/readme.txt | awk -F' ' '{print $NF}' | tr -d '\r')
80+
echo "readme.txt version: $READMEVERSION"
81+
82+
if [ "$READMEVERSION" = "trunk" ]; then
83+
echo "Version in readme.txt & $MAINFILE don't match, but Stable tag is trunk. Let's continue..."
84+
elif [ "$PLUGINVERSION" != "$READMEVERSION" ]; then
85+
echo "Version in readme.txt & $MAINFILE don't match. Exiting...."
86+
exit 1;
87+
elif [ "$PLUGINVERSION" = "$READMEVERSION" ]; then
88+
echo "Versions match in readme.txt and $MAINFILE. Let's continue..."
89+
fi
90+
91+
echo
92+
93+
echo "Q4. Path to a local directory where a temporary SVN checkout can be made."
94+
printf "Don't add trunk ($default_svnpath): "
4195
read -e input
42-
SVNUSER="${input:-$default_svnuser}" # Populate with default if empty
96+
input="${input%/}" # Strip trailing slash
97+
SVNPATH="${input:-$default_svnpath}" # Populate with default if empty
4398
echo
4499

45-
echo "1e) Your local plugin root directory, the Git repo. No trailing slash."
46-
printf "($default_plugindir): "
47-
read -e input
100+
echo "Q5. Remote SVN repo on WordPress.org."
101+
printf "($default_svnurl): "
102+
read -e input
48103
input="${input%/}" # Strip trailing slash
49-
PLUGINDIR="${input:-$default_plugindir}" # Populate with default if empty
104+
SVNURL="${input:-$default_svnurl}" # Populate with default if empty
50105
echo
51106

52-
printf "1f) Name of the main plugin file ($default_mainfile): "
107+
printf "Q6. Your WordPress repo SVN username ($default_svnuser): "
53108
read -e input
54-
MAINFILE="${input:-$default_mainfile}" # Populate with default if empty
109+
SVNUSER="${input:-$default_svnuser}" # Populate with default if empty
55110
echo
56111

57112
echo "That's all of the data collected."
58113
echo
59114
echo "Slug: $PLUGINSLUG"
115+
echo "Plugin directory: $PLUGINDIR"
116+
echo "Main file: $MAINFILE"
60117
echo "Temp checkout path: $SVNPATH"
61118
echo "Remote SVN repo: $SVNURL"
62119
echo "SVN username: $SVNUSER"
63-
echo "Plugin directory: $PLUGINDIR"
64-
echo "Main file: $MAINFILE"
65120
echo
66121

67122
printf "OK to proceed (Y|n)? "
@@ -72,9 +127,6 @@ echo
72127
# Allow user cancellation
73128
if [ $(echo "$PROCEED" |tr [:upper:] [:lower:]) != "y" ]; then echo "Aborting..."; exit 1; fi
74129

75-
# git config
76-
GITPATH="$PLUGINDIR/" # this file should be in the base of your git repository
77-
78130
# Let's begin...
79131
echo ".........................................."
80132
echo
@@ -83,48 +135,24 @@ echo
83135
echo ".........................................."
84136
echo
85137

86-
# 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
87-
PLUGINVERSION=`grep -i "Version:" $GITPATH/$MAINFILE | awk -F' ' '{print $NF}' | tr -d '\r'`
88-
echo "$MAINFILE version: $PLUGINVERSION"
89-
READMEVERSION=`grep -i "Stable tag:" $GITPATH/readme.txt | awk -F' ' '{print $NF}' | tr -d '\r'`
90-
echo "readme.txt version: $READMEVERSION"
138+
echo
91139

92-
if [ "$READMEVERSION" = "trunk" ]; then
93-
echo "Version in readme.txt & $MAINFILE don't match, but Stable tag is trunk. Let's proceed..."
94-
elif [ "$PLUGINVERSION" != "$READMEVERSION" ]; then
95-
echo "Version in readme.txt & $MAINFILE don't match. Exiting...."
96-
exit 1;
97-
elif [ "$PLUGINVERSION" = "$READMEVERSION" ]; then
98-
echo "Versions match in readme.txt and $MAINFILE. Let's proceed..."
140+
echo "Changing to $PLUGINDIR"
141+
cd $PLUGINDIR
142+
143+
# Check for git tag (may need to allow for leading "v"?)
144+
# if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"
145+
if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"
146+
then
147+
echo "Git tag $PLUGINVERSION does exist. Let's continue..."
148+
else
149+
echo "$PLUGINVERSION does not exist as a git tag. Aborting.";
150+
exit 1;
99151
fi
100152

101-
# GaryJ: Ignore check for git tag, as git flow release finish creates this.
102-
#if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"
103-
# then
104-
# echo "Version $PLUGINVERSION already exists as git tag. Exiting....";
105-
# exit 1;
106-
# else
107-
# echo "Git version does not exist. Let's proceed..."
108-
#fi
109-
110-
echo "Changing to $GITPATH"
111-
cd $GITPATH
112-
# GaryJ: Commit message variable not needed . Hard coded for SVN trunk commit for consistency.
113-
#echo -e "Enter a commit message for this new version: \c"
114-
#read COMMITMSG
115-
# GaryJ: git flow release finish already covers this commit.
116-
#git commit -am "$COMMITMSG"
117-
118-
# GaryJ: git flow release finish already covers this tag creation.
119-
#echo "Tagging new version in git"
120-
#git tag -a "$PLUGINVERSION" -m "Tagging version $PLUGINVERSION"
121-
122-
echo "Pushing git master to origin, with tags"
123-
git push origin master
124-
git push origin master --tags
125-
126-
echo
127-
echo "Creating local copy of SVN repo trunk ..."
153+
echo
154+
155+
echo "Creating local copy of SVN repo trunk..."
128156
svn checkout $SVNURL $SVNPATH --depth immediates
129157
svn update --quiet $SVNPATH/trunk --set-depth infinity
130158

@@ -158,23 +186,29 @@ if [ -f ".gitmodules" ]
158186
done
159187
fi
160188

189+
echo
190+
161191
# Support for the /assets folder on the .org repo.
162-
echo "Moving assets"
192+
echo "Moving assets."
163193
# Make the directory if it doesn't already exist
164194
mkdir -p $SVNPATH/assets/
165195
mv $SVNPATH/trunk/assets/* $SVNPATH/assets/
166196
svn add --force $SVNPATH/assets/
167197
svn delete --force $SVNPATH/trunk/assets
168198

169-
echo "Changing directory to SVN and committing to trunk"
199+
echo
200+
201+
echo "Changing directory to SVN and committing to trunk."
170202
cd $SVNPATH/trunk/
171203
# Delete all files that should not now be added.
172204
svn status | grep -v "^.[ \t]*\..*" | grep "^\!" | awk '{print $2"@"}' | xargs svn del
173205
# Add all new files that are not set to be ignored
174206
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2"@"}' | xargs svn add
175207
svn commit --username=$SVNUSER -m "Preparing for $PLUGINVERSION release"
176208

177-
echo "Updating WordPress plugin repo assets and committing"
209+
echo
210+
211+
echo "Updating WordPress plugin repo assets and committing."
178212
cd $SVNPATH/assets/
179213
# Delete all new files that are not set to be ignored
180214
svn status | grep -v "^.[ \t]*\..*" | grep "^\!" | awk '{print $2"@"}' | xargs svn del
@@ -183,7 +217,9 @@ svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2"@"}' | xargs sv
183217
svn update --quiet --accept working $SVNPATH/assets/*
184218
svn commit --username=$SVNUSER -m "Updating assets"
185219

186-
echo "Creating new SVN tag and committing it"
220+
echo
221+
222+
echo "Creating new SVN tag and committing it."
187223
cd $SVNPATH
188224
svn copy --quiet trunk/ tags/$PLUGINVERSION/
189225
# Remove assets and trunk directories from tag directory
@@ -193,7 +229,9 @@ svn update --quiet --accept working $SVNPATH/tags/$PLUGINVERSION
193229
cd $SVNPATH/tags/$PLUGINVERSION
194230
svn commit --username=$SVNUSER -m "Tagging version $PLUGINVERSION"
195231

196-
echo "Removing temporary directory $SVNPATH"
232+
echo
233+
234+
echo "Removing temporary directory $SVNPATH."
197235
cd $SVNPATH
198236
cd ..
199237
rm -fr $SVNPATH/

0 commit comments

Comments
 (0)