summaryrefslogtreecommitdiff
blob: 4f85eb92bbcdf21f65f45be1005abd2745b2318e (plain)
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
##############################################
#
#	John Mylchreest, 2006-04-13.
#
#	The default settings expect CWD to be
#	the branch root (directly below tags/trunk)
#
#	Modified from Daniel Drakes original
#	svn release script to suit my needs.
#	This should also provide more flexibilty
#
##############################################

# Get options
while getopts "f:t:d" opts; do
	case ${opts} in
		f) release_conf="${OPTARG}";;
		t) target=${OPTARG};;
		d) release_debug=1;;
	esac
done
release_cwd=`pwd`

# Source config
release_conf="${release_conf:-".release"}"

if [[ ! -f "${release_conf}" ]]; then
	echo "WARNING: Unable to find release config. Using defaults."
fi

# Setup Defaults
webuser=${GENTOO_USER:-${USER}}
webrelease=0
webpath="~${GENTOO_USER}/public_html/"
svntags=./tags/
svntrunk=./trunk/
branch_root=../
branch_prefix=
output_dir=/tmp/
mailvia=ssh
announce_mailto=${webuser}@gentoo.org

# Source options
[[ -f ${release_conf} ]] && source ${release_conf}

# Sanitise as neccessary
if [[ -n "$(svn status ${svntrunk})" ]] ; then
	echo "FATAL: There are files in conflict with SVN in ${svntrunk},"
	echo "FATAL: Please make sure it is up to date, with no outstanding changes."
	exit -1
fi

echo "ACTION: Performing svn up."
svn up ${svntags}/../ >/dev/null

# Compute targets
echo "ACTION: Tracing Previous Releases..."
# Sorry for all the pipes, its just easier to read :)
release_history="$(svn ls ${svntags} | sed -e 's:/::g' | sort -n)"

# Find target
if [[ -z ${target} ]]; then
	# Since all we need is the last release, lets do that.
	for i in ${release_history}; do
		target=${i%-*}
	done
fi

# Set target release
hightarget=0
for i in ${release_history}; do
	if [[ -z ${i/*${target}*} ]]; then
		lasttag=${i//*-}
		if [[ ${lasttag} -ge ${hightarget} ]]; then
			hightarget=$((${lasttag} + 1))
			target_release=${target}-${hightarget}
		fi
	fi
done
[[ -n "${lasttag}" ]] && lasttag=$((${hightarget} - 1))
[[ -z "${target_release}" ]] && target_release=${target}-1

# replace branch prefix?
if [[ -z "${branch_prefix}" ]]; then
	pushd ${branch_root} >/dev/null
	branch_prefix=`pwd`
	branch_prefix=${branch_prefix/*\/}-patches
	popd >/dev/null
fi

# Print Debug
if [[ ${release_debug} -gt 0 ]]; then
	for var in \
		release_conf \
		release_cwd \
		branch_root \
		branch_prefix \
		release_history \
		lasttag \
		target \
		target_release \
		output_dir \
		svntags \
		svntrunk \
		webrelease \
		mailvia \
		announce_mailto \
		webuser \
		webpath; do

		spacing="                  "
		len=$((${#spacing} - ${#var}))
		spacing=${spacing:0:${len}}
		echo -e "${var}${spacing}= ${!var}"
	done
fi;

echo "ACTION: Rolling release tarballs..."
tarball_prefix="${output_dir}/${branch_prefix}-${target_release}"
pushd ${svntrunk} >/dev/null
tar -cjf ${tarball_prefix}.tar.bz2 --exclude=".svn" ${target}/*
popd >/dev/null
echo "md5: $(md5sum ${tarball_prefix}.tar.bz2)"

cat << EOF

We have the tarballs, so we're ready to go.

I will now:

1.	Tag a new ${target_release} branch
2.	Upload the tarballs to d.g.o:/space/distfiles-local
EOF

if [[ ${webrelease} -gt 0 ]]; then
	cat << EOF
3.	Create a release shortlog
4.	Upload the release shortlog to ${webpath}
5.	Upload the broken-out patches and tarballs 
	to ${webpath}/{broken-out,releases}
6.	Send an announcement email to ${announce_mailto}

To continue, Hit enter."
EOF
fi
read

echo "ACTION: Tagging release in svn..."
svn cp \
	${svntrunk}/${target} \
	${svntags}/${target_release} \
	>/dev/null

echo "ACTION: Comitting release..."
svn ci ${svntags}/${target_release} -m "Releasing ${target_release}"

echo "ACTION: Uploading tarballs to distfiles..."
scp ${tarball_prefix}* \
	${webuser}@dev.gentoo.org:/space/distfiles-local \
	>/dev/null

if [[ ${webrelease} -gt 0 ]]; then
	tmpfile=$(mktemp /tmp/myemail-XXXXXXX)
	tmppath=${webpath%*\/}
	tmppath=${tmppath/*\/}
	shortlog=$(mktemp /tmp/myshortlog-XXXXXXX)

	echo "ACTION: Creating Shortlog..."
	if [[ ${target_release//*-} == 1 ]]; then
		echo "Initial Import" > ${shortlog}
	else
		checktag=$((${lasttag} - 1))
		lastrev=$(svn info ${svntags}/${target}-${lasttag}/ \
			| grep "Last Changed Rev")
		lastrev=${lastrev//*:}

		svn log -v -r ${lastrev}:HEAD \
			${svntrunk}/${target} \
			> ${shortlog}
	fi

	#make directories
	ssh ${webuser}@dev.gentoo.org \
		mkdir -p ${webpath}/broken-out/ \
		${webpath}/releases \
		${webpath}/logs/ \
		>/dev/null
	
	echo "ACTION: Uploading Shortlog..."
	scp ${shortlog} \
		${webuser}@dev.gentoo.org:${webpath}/logs/shortlog-${target_release} \
		>/dev/null
	ssh ${webuser}@dev.gentoo.org chmod a+r \
		${webpath}/logs/shortlog-${target_release} \
		>/dev/null

	#upload broken patches
	echo "ACTION: Uploading broken-out patches..."
	scp -r ${svntags}/${target_release} \
		${webuser}@dev.gentoo.org:${webpath}/broken-out/ \
		>/dev/null

	#upload release tarballs
	echo "ACTION: Uploading release tarballs..."
	scp ${tarball_prefix}* \
		${webuser}@dev.gentoo.org:${webpath}/releases/ \
		>/dev/null

	# Email section
	cat << EOF >> ${tmpfile}
This is an automated email to say that ${branch_prefix}-${target_release}
has just been released.

You can find a shortlog, broken out patches and release tarballs at:
http://dev.gentoo.org/~${webuser}/${tmppath}

Changes since ${target}-${lasttag} are as follows:
EOF

	cat < ${shortlog} >> ${tmpfile}

	# Send the email
	case ${mailvia} in
		ssh)	scp ${tmpfile} ${webuser}@dev.gentoo.org:tmpannounce;
				ssh ${webuser}@dev.gentoo.org "cat tmpannounce | mailx -s \
					\"[ANNOUNCE] ${branch_prefix}-${target_release} Released\" \
					${announce_mailto}";
				ssh ${webuser}@dev.gentoo.org rm tmpannounce;;
		mailx)	cat ${tmpfile} | mail \
				-s "[gentoo-kernel] [ANNOUNCE] ${branch_prefix}-${target_release} Release" \
				${announce_mailto};;
	esac
	rm ${tmpfile}
	rm ${shortlog}
fi