-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathversion-release.sh
More file actions
201 lines (156 loc) · 5.2 KB
/
version-release.sh
File metadata and controls
201 lines (156 loc) · 5.2 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
#!/bin/bash
# Tag and release a new version of the plugin.
#
# This script takes a local git repo directory and syncs it to an SVN working directory for use as a
# new version per WordPress plugin development practices. In this set-up, use the local git directory normally for
# development: branch, tag, and commit however often you want. When you are ready to release a new version of the
# plugin, run this script. It will copy the contents of this folder to an SVN folder (defined by the SVNDIR variable).
# It will handle incrementing the version number, creating a tag (in both Git and SVN), and it will add or remove files
# from SVN to match the contents of this git directory.
#
#
# USAGE
# -------------
# bash to-svn.sh 1.2.3
#
# 1. "export" the current directory to a temp directory
# 2. merge the temp directory in with the managed SVN directory
# 3. commit the SVN code
#####################################################
# CONFIGURATION
#####################################################
# Temp dir -- will be deleted!
# Omit trailing slash.
# Don't use spaces or weird chars in the dir names.
TMPDIR="/tmp/cctm"
# Absolute path or path relative to this dir, omit trailing slash
# This dir should contain the SVN trunk.
SVNDIR="../../cctm.svn"
#####################################################
# END CONFIG
#####################################################
# Most bash variables are global, but not the arguments
# so we pass them to another variable.
VERSION=$1;
#####################################################
# SUBROUTINES
#####################################################
function verify_version {
if [[ -z $VERSION ]]; then
echo 'Missing required VERSION parameter.';
exit 1;
fi
if [[ ! $VERSION =~ [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+ ]]; then
echo 'Invalid version number';
exit 2;
fi
}
# Resolve SVNDIR to an absolute dir
# One-liner similar to PHP's __DIR__ -- omits trailing slash
function get_abs_pwd {
SRCDIR="$( cd "$(dirname "$0")" ; pwd -P )"
}
# Make sure the SVNDIR is actually a working copy.
function verify_svn_dir
{
# Remember: the SVNDIR is relative to this file
cd $SVNDIR;
SVNDIR=`pwd`;
SVNTRUNK=`svn info ${SVNDIR} | grep 'URL:' | sed -e 's/URL: //'`
SVNTAGS=$(echo $SVNTRUNK | sed -e 's/trunk/tags/')
# Verify Data
if [[ -d $SVNDIR ]] && [[ -d ${SVNDIR}/.svn ]]; then
echo "SVN repository directory detected at ${SVNDIR}"
else
echo "${SVNDIR} is not an SVN working copy.";
exit 1;
fi
}
function update_svn {
cd $SVNDIR;
svn update
}
function get_current_version {
cd $SVNDIR;
CURRENTVERSION=`grep 'Stable tag:' readme.txt | cut -d : -f 2 | tr -d '[[:space:]]'`
echo "Latest stable tag referenced by SVN trunk is version ${CURRENTVERSION}";
}
# Gotta have the proper notices in place
function verify_readme {
cd $SRCDIR
CNT=`grep "${VERSION}" readme.txt | wc -l`
if [[ $CNT -lt 3 ]]; then
echo "readme.txt must have entries for the Change Log and Upgrade Notice!";
echo "Aborting version release.";
exit 4;
fi
}
# Update the plugin version
function update_version {
if [[ $VERSION < $CURRENTVERSION ]]; then
echo 'New version must be greater than existing versions!';
exit 3;
fi
cd $SRCDIR;
echo "Updating documentation in source files to version ${VERSION}";
sed -i '' "s/Version:.*/Version: ${VERSION}/" index.php
sed -i '' "s/Stable tag:.*/Stable tag: ${VERSION}/" readme.txt
sed -i '' "s/Version:.*/Version: ${VERSION}/" readme.txt
sed -i '' "s/.*const version = .*/ const version = '${VERSION}'\;/" includes/CCTM.php
}
function mv_thru_tmpdir
{
rm -rf $TMPDIR;
echo "Syncing to ${TMPDIR}"
# We want rsync to use the trailing slash for referencing this directory, otherwise a sub-dir will be created
rsync -arz ${SRCDIR}/ $TMPDIR --exclude=".git" --exclude=".gitignore" --exclude="*.sh" --exclude=".idea";
echo "Syncing from ${TMPDIR}/ to $SVNDIR"
rsync -arvz ${TMPDIR}/ $SVNDIR;
cd $SVNDIR;
svn add *
}
# Will remove files from SVN control if they are not in the
# Git repo
function remove_files_from_svn {
# Get relative paths
cd $SVNDIR
SVNFILES=`find * -type f`
while read -r LINE; do
TESTFILE=${SRCDIR}/${LINE}
if [[ ! -e $TESTFILE ]]; then
echo "${TESTFILE} is being removed from the repo";
svn delete ${TESTFILE};
fi
done <<< "$SVNFILES"
}
function tag_git_version
{
# Tag the Git repo
cd $SRCDIR;
git tag -a v${1} -m "Tagging version ${1} via automated script"
git push origin v${1}
}
# Tag the version
function tag_svn_version
{
# Commit
svn commit ${SVNDIR} -m "Committing changes for version ${1} via automated script"
# SVN copy from trunk to tag
svn copy ${SVNTRUNK} ${SVNTAGS}/${1} -m "Tagging version ${1} via automated script"
}
#################################################
# MAIN
#################################################
verify_version;
get_abs_pwd;
verify_svn_dir;
update_svn;
get_current_version;
update_version;
verify_readme;
mv_thru_tmpdir;
remove_files_from_svn;
tag_git_version;
tag_svn_version;
# SUCCESS
exit 0;