-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathrelease.sh
executable file
·165 lines (138 loc) · 5.31 KB
/
release.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
#!/bin/bash
set -e
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/GaryJones/wordpress-plugin-git-flow-svn-deploy
# The difference is that this script lives in the plugin's git repo, auto sets parameters and checks for a readme.md in addition to readme.txt
# config
PLUGINDIR=$(pwd)
MAINFILE="wp-mpdf.php"
SVNURL="https://plugins.svn.wordpress.org/wp-mpdf/"
SVNUSER="fkrauthan"
SVNPATH="$PLUGINDIR/svn"
# git config
GITPATH="$PLUGINDIR/" # this file should be in the base of your git repository
# Let's begin...
echo "............................................."
echo
echo "Preparing to deploy wp-mpdf WordPress plugin"
echo
echo "............................................."
echo
# Check that git working directory is clean
if [ -n "$(git status --porcelain)" ]; then
echo "There are uncommitted git changes. Exiting...."
exit 1
fi
# Ensure composer exists
if [ ! -f "./composer.phar" ]; then
echo "Installing composer."
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
php composer-setup.php --quiet
rm composer-setup.php
fi
# Ensure dependencies are installed
echo "Installing dependencies for deployment"
php ./composer.phar install -q --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress
# 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 "Version:" $GITPATH/$MAINFILE | awk -F' ' '{print $NF}' | tr -d '\r')
echo "$MAINFILE version: $PLUGINVERSION"
READMEVERSION=$(grep "^Stable tag:" $GITPATH/readme.txt | awk -F' ' '{print $NF}' | tr -d '\r')
echo "readme.txt version: $READMEVERSION"
READMEMDVERSION=$(grep "^\*\*Stable tag:\*\*" $GITPATH/readme.md | awk -F' ' '{print $NF}' | tr -d '\r')
echo "readme.md version: $READMEMDVERSION"
if [ "$READMEVERSION" = "trunk" ]; then
echo "Version in readme.txt & $MAINFILE don't match, but Stable tag is trunk. Let's proceed..."
elif [ "$PLUGINVERSION" != "$READMEVERSION" ]; then
echo "Version in readme.txt & $MAINFILE don't match. Exiting...."
exit 1
elif [ "$PLUGINVERSION" != "$READMEMDVERSION" ]; then
echo "Version in readme.md & $MAINFILE don't match. Exiting...."
exit 1
elif [ "$PLUGINVERSION" = "$READMEVERSION" ] && [ "$PLUGINVERSION" = "$READMEMDVERSION" ]; then
echo "Versions match in readme.txt, readme.md and $MAINFILE. Let's proceed..."
fi
if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"; then
if [[ $GITHUB_ACTIONS ]]; then
echo "Version $PLUGINVERSION git tag found"
else
echo "Version $PLUGINVERSION already exists as git tag. Exiting...."
exit 1
fi
else
if [[ $GITHUB_ACTIONS ]]; then
echo "Git version does not exist. This is required to proceed. Exiting...."
exit 1
else
echo "Git version does not exist. Let's proceed..."
fi
fi
# Tag new version
if [[ $GITHUB_ACTIONS ]]; then
echo "Skip tagging for github actions deploy"
else
echo "Tagging new version in git"
git tag -a "$PLUGINVERSION" -m "Tagging version $PLUGINVERSION"
fi
# Push changes back up to master
#echo "Pushing git master to origin, with tags"
#git push origin master
#git push origin master --tags
# Checkout svn repo
echo
echo "Creating local copy of SVN repo trunk ..."
svn checkout $SVNURL $SVNPATH --depth immediates
svn update --quiet $SVNPATH/trunk --set-depth infinity
echo "Exporting the HEAD of master from git to the trunk of SVN"
rm -Rf $SVNPATH/trunk/
git checkout-index -a -f --prefix=$SVNPATH/trunk/
echo "Copying the vendor folder to trunk of SVN"
cp -R $PLUGINDIR/vendor $SVNPATH/trunk/vendor
echo "Remove security related files"
rm -Rf $SVNPATH/trunk/vendor/geshi/geshi/contrib
echo "Ignoring GitHub/IDEA and dev specific files"
svn propset svn:ignore "readme.md
changelog.md
Thumbs.db
.github
.idea
dev
composer.phar
.git
.gitattributes
release.sh
prepare.sh
.gitignore" "$SVNPATH/trunk/"
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 "^\!" | sed 's/! *//' | xargs -I% svn del --force %
# Add all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | sed 's/\? *//' | xargs svn add
if [[ $SVNPASSWORD ]]; then
svn commit --username=$SVNUSER --password="$SVNPASSWORD" --no-auth-cache --non-interactive -m "Preparing for $PLUGINVERSION release"
else
svn commit --username=$SVNUSER -m "Preparing for $PLUGINVERSION release"
fi
echo "Creating new SVN tag and committing it"
cd $SVNPATH
svn update --quiet $SVNPATH/tags/$PLUGINVERSION
svn copy --quiet trunk/ tags/$PLUGINVERSION/
# Commit new tag
cd $SVNPATH/tags/$PLUGINVERSION
if [[ $SVNPASSWORD ]]; then
svn commit --username=$SVNUSER --password="$SVNPASSWORD" --no-auth-cache --non-interactive -m "Tagging version $PLUGINVERSION"
else
svn commit --username=$SVNUSER -m "Tagging version $PLUGINVERSION"
fi
echo "Removing temporary directory $SVNPATH"
cd $SVNPATH
cd ..
rm -fr $SVNPATH/
echo "*** FIN ***"