This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·175 lines (141 loc) · 4.69 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
#!/bin/bash
set -e
exec 2>deploy.log
set -x
# main config
PLUGINSLUG="shipcloud-for-woocommerce"
CURRENTDIR=`pwd`
MAINFILE="woocommerce-shipcloud.php" # This should be the name of your main php file in the WordPress plugin
DEFAULT_EDITOR="/usr/bin/vi"
# git config
GITPATH="$CURRENTDIR/src/plugins/$PLUGINSLUG/" # this file should be in the base of your git repository
ASSETSFOLDER="assets"
ASSETSPATH="$GITPATH/$ASSETSFOLDER/" # this file should be in the base of your git repository
# svn config
SVNPATH="/tmp/$PLUGINSLUG" # Path to a temp SVN repo. No trailing slash required.
SVNURL="https://plugins.svn.wordpress.org/$PLUGINSLUG/" # Remote SVN repo on wordpress.org
SVNUSER=$1
SVNPASS=$2
if [ "$SVNUSER" == "" ] || [ "$SVNPASS" == "" ]
then echo "Please enter a SVN username and password (e.g. deploy USERNAME PASSWORD)"
exit 1
fi
[[ -d $SVNPATH ]] && rm -rf $SVNPATH
# Let's begin...
echo
echo "Deploy WordPress plugin"
echo "======================="
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
NEWVERSION1=`grep "^Stable tag:" "$GITPATH/readme.txt" | awk -F' ' '{print $NF}'`
echo "readme.txt version: $NEWVERSION1"
NEWVERSION2=`grep "Version: " "$GITPATH/$MAINFILE" | awk -F' ' '{print $NF}'`
echo "$MAINFILE version: $NEWVERSION2"
if [ "$NEWVERSION1" != "$NEWVERSION2" ]
then echo "Version in readme.txt & $MAINFILE don't match. Exiting."
exit 1
fi
echo "Versions match in readme.txt and $MAINFILE. Let's proceed..."
if git show-ref --quiet --tags --verify -- "refs/tags/$NEWVERSION1"
then
echo "Version $NEWVERSION1 already exists as git tag. Skipping."
else
printf "Tagging new Git version..."
git tag -a "$NEWVERSION1" -m "tagged version $NEWVERSION1"
echo "Done."
printf "Pushing new Git tag..."
git push --quiet --tags
echo "Done."
fi
cd $GITPATH
printf "Creating local copy of SVN repo..."
svn checkout --quiet $SVNURL/trunk $SVNPATH/trunk
echo "Done."
printf "Exporting the HEAD of master from Git to the trunk of SVN..."
git checkout-index --quiet --all --force --prefix=$SVNPATH/trunk/
echo "Done."
printf "Preparing commit message..."
echo "updated version to $NEWVERSION1" > /tmp/wppdcommitmsg.tmp
echo "Done."
echo "Preparing assets-wp-repo..."
if [ -d $ASSETSPATH ]
then
svn checkout --quiet $SVNURL/assets $SVNPATH/assets > /dev/null
[[ -d $SVNPATH/assets/ ]] || mkdir $SVNPATH/assets/ > /dev/null # Create assets directory if it doesn't exists
cp -a $SVNPATH/trunk/$ASSETSFOLDER/wordpress_com/* $SVNPATH/assets/ # Copy assets for wordpress.com website
echo " SVN: Remove wordpress_com from plugin asset folder..."
rm -rf $SVNPATH/trunk/$ASSETSFOLDER/wordpress_com
cd $SVNPATH/assets/ # Switch to assets directory
if svn stat | grep "^?\|^M"
then
svn stat | grep "^?" | awk '{print $2}' | xargs svn add --quiet # Add new assets
echo -en "Committing new assets..."
svn commit --quiet -m "updated assets"
echo "Done."
else
echo "Unchanged."
fi
else
echo "No assets exists."
fi
cd $SVNPATH/trunk/
printf "Installing Composer dependencies..."
if [ -f composer.lock ]
then rm composer.lock
fi
[[ -f composer.json ]] && composer install --prefer-dist --no-dev --quiet
echo "Done."
printf "Ignoring GitHub specific files and deployment script..."
svn propset --quiet svn:ignore ".bowerrc
.codeclimate.yml
.git
.gitignore
.travis.yml
bower.json
composer.json
composer.lock
CONTRIBUTING.md
deploy.sh
gulpfile.js
Gruntfile.js
package.json
phpunit.xml
README.md
tests" .
echo "Done."
if svn stat | grep "^?"; then
printf "Adding new files..."
svn stat | grep "^?" | awk '{print $2}' | xargs svn add --quiet
echo "Done."
fi
if svn stat | grep "^\!"; then
printf "Removing old files..."
svn stat | grep "^\!" | awk '{print $2}' | xargs svn remove --quiet
echo "Done."
fi
printf "Enter a commit message for this new SVN version..."
$DEFAULT_EDITOR /tmp/wppdcommitmsg.tmp
COMMITMSG=`cat /tmp/wppdcommitmsg.tmp`
rm /tmp/wppdcommitmsg.tmp
echo "Done."
printf "Committing new SVN version..."
svn commit --username "$SVNUSER" --password "$SVNPASS" --quiet -m "$COMMITMSG"
echo "Done."
printf "Tagging and committing new SVN tag..."
echo "Deleting: $SVNURL/tags/$NEWVERSION1"
if ! svn delete $SVNURL/tags/$NEWVERSION1 -m "Renewing Tag"; then
echo "First time this version will be pushed."
fi
CP_FROM="$SVNURL/trunk"
CP_TO="$SVNURL/tags/$NEWVERSION1"
echo "Copy from: $CP_FROM"
echo "Copy to: $CP_TO"
svn cp $CP_FROM $CP_TO -m "tagged version $NEWVERSION1"
echo "Done."
printf "Removing temporary directory %s..." "$SVNPATH"
rm -rf $SVNPATH/
echo "Done."
echo
echo "Plugin $PLUGINSLUG version $NEWVERSION1 has been successfully deployed."
echo