-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_to_wordpress
More file actions
executable file
·222 lines (192 loc) · 5.32 KB
/
deploy_to_wordpress
File metadata and controls
executable file
·222 lines (192 loc) · 5.32 KB
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
#!/bin/bash
source .env
RELEASE="1"
MAJOR="0"
MINOR="0"
MICRO="0"
DOPOT="0"
DOTEST="0"
while [ $# -gt 0 ]
do
arg=$1
shift
if [[ "x$arg" = "x-v" ]]
then
RELEASE="1"
MINOR="1"
fi
if [[ "x$arg" = "x-r" ]]
then
RELEASE="1"
MAJOR="1"
fi
if [[ "x$arg" = "x-p" ]]
then
DOPOT="1"
RELEASE="0"
fi
if [[ "x$arg" = "x-t" ]]
then
DOTEST="1"
RELEASE="0"
fi
if [[ "x$arg" = "x-h" ]]
then
echo "Deploy to Wordpress script"
echo "Copyright (C) 2020-2023 muis IT https://www.muisit.nl"
echo ""
echo "deploy_to_wordpress [options]"
echo ""
echo "-h print this help text"
echo "-p search strings and regenerate the POT file"
echo "-r release a major release (tag with major value upgraded)"
echo "-t run extended tests"
echo "-v release a minor release (tag with minor value upgraded)"
echo ""
echo "Add the WPDIR directory location of the destination SVN repository in the"
echo ".env file next to this script. Set the PROJECT variable to the name of"
echo "the project/plugin name/file containing the version number. Set the WPCLI"
echo "variable to the wordpress CLI executable for purposes of I18N"
exit
fi
done
if [[ "x$DOPOT" = "x1" ]]
then
echo "Creating POT file"
$WPCLI i18n make-pot . languages/$PROJECT.pot --exclude="vue" --include="lib,models,controllers,assets,dist,$PROJECT.php"
echo "Update PO files"
$WPCLI i18n update-po languages/$PROJECT.pot
fi
if [[ -d languages ]]
then
# always just update the language files
echo "Updating I18N output files"
rm -f languages/*.mo languages/*.json
$WPCLI i18n make-mo languages
# do not purge the original translations
$WPCLI i18n make-json languages --pretty-print --no-purge
fi
# not releasing, just quit
if [[ "x$DOPOT" = "x1" ]]
then
exit 0
fi
pushd vue > /dev/null
npm run type-check > /dev/null 2>&1
if [[ "x$?" = "x0" ]]
then
echo "TypeScript type-check passes"
else
echo "TypeScript type-check fails"
exit 1
fi
npm run lint > /dev/null 2>&1
if [[ "x$?" = "x0" ]]
then
echo "Lint test passes"
else
echo "Lint fails"
exit 1
fi
popd > /dev/null
#echo "Running JS tests"
#npm run --silent test -- --silent >/dev/null 2>&1
#if [[ ! "x$?" = "x0" ]]
#then
# echo "Javascript tests fail, please run tests yourself"
# echo "npm run --silent test"
# exit 1
#else
# echo "Javascript tests succeed"
#fi
#phpunit --bootstrap tests/preload.php --testdox --colors=always tests
#phpunit --bootstrap tests/preload.php --stderr tests 2>/dev/null
#if [[ ! "x$?" = "x0" ]]
#then
# echo "PHPUnit tests fail, please run tests yourself"
# echo "phpunit --bootstrap tests/preload.php --testdox --colors=always tests"
# exit 1
#else
# echo "PHPUnit tests succeed"
#fi
# not releasing, just quit
if [[ "x$DOTEST" = "x1" ]]
then
exit 0
fi
if [[ "x$MAJOR" = "x1" && "x$MINOR" = "x1" ]]
then
echo "Major release requires a minor version of 0, ignoring -v"
MINOR="0"
fi
VERSION=`grep "* Version" "$PROJECT.php" | sed 's/[^0-9]*\([0-9\.]*\).*/\1/'`
MAJ=`echo $VERSION | sed 's/\([0-9]*\).*/\1/'`
MIN=`echo $VERSION | sed 's/[0-9]*\.\([0-9]*\).*/\1/'`
MICR=`echo $VERSION | sed 's/[0-9]*\.[0-9]*\.\([0-9]*\)/\1/'`
if [[ "x1" = "x$MAJOR" ]]
then
echo "Performing major release"
let "MAJ=$MAJ+1"
MIN="0"
MICR="0"
else
if [[ "x1" = "x$MINOR" ]]
then
echo "Performing minor release"
let "MIN=$MIN+1"
MICR="0"
else
if [[ "x$RELEASE" = "x1" ]]
then
echo "Performing micro release"
let "MICR=$MICR+1"
fi
fi
fi
echo "Version ${MAJ}.${MIN}.${MICR}"
cat "$PROJECT.php" | sed "s/\(.*Version[ \t:]*\).*/\1${MAJ}.${MIN}.${MICR}/" > tmp.$$
mv tmp.$$ "$PROJECT.php"
cat "$PROJECT.php" | sed "s/\(define.*VERSION[^\"]*\"\)[^\"]*\(\".*\)/\1${MAJ}.${MIN}.${MICR}\2/" > tmp.$$
mv tmp.$$ "$PROJECT.php"
pushd vue > /dev/null
cat "package.json" | sed "s/\(.*\"version\"[ \t:]*\"\).*/\1${MAJ}.${MIN}.${MICR}\",/" > tmp.$$
mv tmp.$$ "package.json"
popd > /dev/null
# perform a production build before we deploy
pushd vue > /dev/null
npm run build
STAT=$?
popd > /dev/null
if [ ! "x$STAT" = "x0" ]
then
exit 1
fi
mkdir -p $WPDIR/trunk
cp -r -v *.php LICENSE readme.txt controllers lib models vendor dist $WPDIR/trunk
if [[ -d languages ]]
then
mkdir -p $WPDIR/trunk/languages
cp -v languages/*.po $WPDIR/trunk/languages
# purge the language files and output them small
# first make-json, so we purge the .po files.
# then make .mo from the purged .po files
pushd $WPDIR/trunk > /dev/null
rm -f languages/*.mo languages/*.json
$WPCLI i18n make-json languages
$WPCLI i18n make-mo languages
rm -rf languages/*.po
popd > /dev/null
fi
# unset all debug flags
pushd $WPDIR/trunk > /dev/null
cat $PROJECT.php | sed "s/\(define.*DEBUG.*\).*true/\1false/i" > tmp.php
mv tmp.php $PROJECT.php
popd > /dev/null
pushd /tmp > /dev/null
cp -darpv $WPDIR/trunk /tmp/$PROJECT
zip -r $PROJECT $PROJECT
# move it one folder up, out of the SVN
mv $PROJECT.zip $WPDIR/..
rm -rf /tmp/$PROJECT
popd > /dev/null
mg create tag "${MAJ}.${MIN}.${MICR}" -m "auto tagged commit"