release.sh: Add user verification of auto-detected values
[xorg-util-modular.git] / release.sh
blob3e49d174c679e52aa7f24b17a8772de3fd1a4a81
1 #!/bin/sh
3 set -e
5 announce_list="xorg-announce@lists.freedesktop.org"
6 xorg_list="xorg@lists.freedesktop.org"
7 dri_list="dri-devel@lists.sourceforge.net"
8 xkb_list="xkb@listserv.bat.ru"
10 host_people=annarchy.freedesktop.org
11 host_xorg=xorg.freedesktop.org
12 host_dri=dri.freedesktop.org
13 user=
14 remote=origin
15 moduleset=
17 usage()
19 cat <<HELP
20 Usage: `basename $0` [options] [<section> [<tag_previous> [<tag_current>]]]
21 or: `basename $0` [options] <section> initial [<tag_current>]
23 Options:
24 --force force overwritting an existing release
25 --user <name> username on $host_people
26 --help this help message
27 --ignore-local-changes don't abort on uncommitted local changes
28 --remote git remote where the change should be pushed (default "origin")
29 --moduleset jhbuild moduleset to update with relase info
30 HELP
33 abort_for_changes()
35 cat <<ERR
36 Uncommitted changes found. Did you forget to commit? Aborting.
37 Use --ignore-local-changes to skip this check.
38 ERR
39 exit 1
42 gen_announce_mail()
44 case "$tag_previous" in
45 initial)
46 range="$tag_current"
49 range="$tag_previous".."$tag_current"
51 esac
53 MD5SUM=`which md5sum || which gmd5sum`
54 SHA1SUM=`which sha1sum || which gsha1sum`
55 SHA256SUM=`which sha256sum || which gsha256sum`
57 if [ "$section" = "libdrm" ]; then
58 host=$host_dri
59 list=$dri_list
60 elif [ "$section" = "xkeyboard-config" ]; then
61 host=$host_xorg
62 list=$xkb_list
63 else
64 host=$host_xorg
65 list=$xorg_list
68 cat <<RELEASE
69 Subject: [ANNOUNCE] $module $version
70 To: $announce_list
71 CC: $list
73 `git log --no-merges "$range" | git shortlog`
75 git tag: $tag_current
77 http://$host/$section_path/$tarbz2
78 MD5: `cd $tarball_dir && $MD5SUM $tarbz2`
79 SHA1: `cd $tarball_dir && $SHA1SUM $tarbz2`
80 SHA256: `cd $tarball_dir && $SHA256SUM $tarbz2`
82 http://$host/$section_path/$targz
83 MD5: `cd $tarball_dir && $MD5SUM $targz`
84 SHA1: `cd $tarball_dir && $SHA1SUM $targz`
85 SHA256: `cd $tarball_dir && $SHA256SUM $targz`
87 RELEASE
90 export LC_ALL=C
92 while [ $# != 0 ]; do
93 case "$1" in
94 --force)
95 force="yes"
96 shift
98 --help)
99 usage
100 exit 0
102 --user)
103 shift
104 user=$1@
105 shift
107 --ignore-local-changes)
108 ignorechanges=1
109 shift
111 --remote)
112 shift
113 remote=$1
114 shift
116 --moduleset)
117 shift
118 moduleset=$1
119 shift
121 --*)
122 echo "error: unknown option"
123 usage
124 exit 1
127 section="$1"
128 shift
129 if [ $# != 0 ]; then
130 tag_previous="$1"
131 shift
132 if [ $# != 0 ]; then
133 tag_current="$1"
134 shift
137 if [ $# != 0 ]; then
138 echo "error: unknown parameter"
139 usage
140 exit 1
143 esac
144 done
147 # Attempt to auto-detect values if not specified
148 auto_detected="no"
150 if [ -z "$section" ]; then
151 section="$(git config --get "remote.${remote}.url" | sed -n 's%^.*freedesktop.org/git/xorg/\([^/]*\).*$%\1%p')"
152 echo "Detected section: $section"
153 auto_detected="yes"
156 if [ -z "$tag_previous" ]; then
157 tag_previous="$(git describe --abbrev=0 HEAD^)"
158 echo "Detected previous tag: $tag_previous"
159 auto_detected="yes"
162 if [ -z "$tag_current" ]; then
163 tag_current="$(git describe --abbrev=0)"
164 echo "Detected current tag: $tag_current"
165 auto_detected="yes"
168 if [ "${auto_detected}" = "yes" ] ; then
169 echo -n "Proceed? (Y/N) "
170 while read answer ; do
171 case "$answer" in
172 y*|Y*) break ;;
173 n*|N*) exit 1 ;;
174 *) echo -n "Incorrect Response. Proceed? (Y/N) " ; continue ;;
175 esac
176 done
179 # Check for required values
180 if [ -z "$section" ]; then
181 echo "error: section not found."
182 usage
183 exit 1
186 if [ -z "$tag_previous" ] ; then
187 echo "error: previous tag not found."
188 usage
189 exit 1
192 if [ -z "$tag_current" ] ; then
193 echo "error: current tag not found."
194 usage
195 exit 1
198 if [ "x$tag_previous" = "x$tag_current" ] ; then
199 echo "current tag ($tag_current) must be different than"
200 echo "previous tag ($tag_previous)"
201 exit 1
204 # Check for uncommitted/queued changes.
205 if [ "x$ignorechanges" != "x1" ]; then
206 set +e
207 git diff --quiet HEAD > /dev/null 2>&1
208 if [ $? -ne 0 ]; then
209 abort_for_changes
211 set -e
214 # Check if the object has been pushed. Do do so
215 # 1. Check if the current branch has the object. If not, abort.
216 # 2. Check if the object is on $remote/branchname. If not, abort.
217 local_sha=`git rev-list -1 $tag_current`
218 current_branch=`git branch | grep "\*" | sed -e "s/\* //"`
219 set +e
220 git rev-list $current_branch | grep $local_sha > /dev/null
221 if [ $? -eq 1 ]; then
222 echo "Cannot find tag '$tag_current' on current branch. Aborting."
223 echo "Switch to the correct branch and re-run the script."
224 exit 1
227 revs=`git rev-list $remote/$current_branch..$current_branch | wc -l`
228 if [ $revs -ne 0 ]; then
229 git rev-list $remote/$current_branch..$current_branch | grep $local_sha > /dev/null
231 if [ $? -ne 1 ]; then
232 echo "$remote/$current_branch doesn't have object $local_sha"
233 echo "for tag '$tag_current'. Did you push branch first? Aborting."
234 exit 1
237 set -e
239 tarball_dir="$(dirname $(find . -name config.status))"
240 module="${tag_current%-*}"
241 if [ "x$module" = "x$tag_current" ]; then
242 # version-number-only tag.
243 pwd=`pwd`
244 module=`basename $pwd`
245 version="$tag_current"
246 else
247 # module-and-version style tag
248 version="${tag_current##*-}"
251 detected_module=`grep 'PACKAGE = ' $tarball_dir/Makefile | sed 's|PACKAGE = ||'`
252 if [ -f $detected_module-$version.tar.bz2 ]; then
253 module=$detected_module
256 modulever=$module-$version
257 tarbz2="$modulever.tar.bz2"
258 targz="$modulever.tar.gz"
259 announce="$tarball_dir/$modulever.announce"
261 echo "checking parameters"
262 if ! [ -f "$tarball_dir/$tarbz2" ] ||
263 ! [ -f "$tarball_dir/$targz" ]; then
264 echo "error: tarballs not found. Did you run make dist?"
265 usage
266 exit 1
269 if [ -n "$moduleset" ]; then
270 echo "checking for moduleset"
271 if ! [ -w "$moduleset" ]; then
272 echo "moduleset $moduleset does not exist or is not writable"
273 exit 1
277 if [ "$section" = "libdrm" ]; then
278 section_path="libdrm"
279 srv_path="/srv/$host_dri/www/$section_path"
280 elif [ "$section" = "xkeyboard-config" ]; then
281 section_path="archive/individual/data"
282 srv_path="/srv/$host_xorg/$section_path"
283 else
284 section_path="archive/individual/$section"
285 srv_path="/srv/$host_xorg/$section_path"
288 echo "checking for proper current dir"
289 if ! [ -d .git ]; then
290 echo "error: do this from your git dir, weenie"
291 exit 1
294 echo "checking for an existing tag"
295 if ! git tag -l $tag_current >/dev/null; then
296 echo "error: you must tag your release first!"
297 exit 1
300 echo "checking for an existing release"
301 if ssh $user$host_people ls $srv_path/$targz >/dev/null 2>&1 ||
302 ssh $user$host_people ls $srv_path/$tarbz2 >/dev/null 2>&1; then
303 if [ "x$force" = "xyes" ]; then
304 echo "warning: overriding released file ... here be dragons."
305 else
306 echo "error: file already exists!"
307 exit 1
311 echo "generating announce mail template, remember to sign it"
312 gen_announce_mail >$announce
313 echo " at: $announce"
315 if [ -n "$moduleset" ]; then
316 echo "updating moduleset $moduleset"
317 real_script_path=`readlink -f "$0"`
318 modulardir=`dirname "$real_script_path"`
319 sha1sum=`cd $tarball_dir && $SHA1SUM $targz | cut -d' ' -f1`
320 $modulardir/update-moduleset.sh $moduleset $sha1sum $targz
323 echo "installing release into server"
324 scp $tarball_dir/$targz $tarball_dir/$tarbz2 $user$host_people:$srv_path
326 echo "pushing tag upstream"
327 git push $remote $tag_current