release.sh: use git-diff --quiet instead of git status
[xorg-util-modular.git] / release.sh
blobec52f9af17d55d5e45834d9d4d73bbbab5d1e339
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 host_people=annarchy.freedesktop.org
9 host_xorg=xorg.freedesktop.org
10 host_dri=dri.freedesktop.org
11 user=
12 remote=origin
14 usage()
16 cat <<HELP
17 Usage: `basename $0` [options] <section> <tag_previous> <tag_current>
19 Options:
20 --force force overwritting an existing release
21 --user <name> username on $host_people
22 --help this help message
23 --ignore-local-changes don't abort on uncommitted local changes
24 --remote git remote where the change should be pushed (default "origin")
25 HELP
28 abort_for_changes()
30 cat <<ERR
31 Uncommitted changes found. Did you forget to commit? Aborting.
32 Use --ignore-local-changes to skip this check.
33 ERR
34 exit 1
37 gen_announce_mail()
39 case "$tag_previous" in
40 initial)
41 range="$tag_current"
44 range="$tag_previous".."$tag_current"
46 esac
48 MD5SUM=`which md5sum || which gmd5sum`
49 SHA1SUM=`which sha1sum || which gsha1sum`
51 if [ $section = libdrm ]; then
52 host=$host_dri
53 list=$dri_list
54 else
55 host=$host_xorg
56 list=$xorg_list
59 cat <<RELEASE
60 Subject: [ANNOUNCE] $module $version
61 To: $announce_list
62 CC: $list
64 `git log --no-merges "$range" | git shortlog`
66 git tag: $tag_current
68 http://$host/$section_path/$tarbz2
69 MD5: `cd $tarball_dir && $MD5SUM $tarbz2`
70 SHA1: `cd $tarball_dir && $SHA1SUM $tarbz2`
72 http://$host/$section_path/$targz
73 MD5: `cd $tarball_dir && $MD5SUM $targz`
74 SHA1: `cd $tarball_dir && $SHA1SUM $targz`
76 RELEASE
79 export LC_ALL=C
81 while [ $# != 0 ]; do
82 case "$1" in
83 --force)
84 force="yes"
85 shift
87 --help)
88 usage
89 exit 0
91 --user)
92 shift
93 user=$1@
94 shift
96 --ignore-local-changes)
97 ignorechanges=1
98 shift
100 --remote)
101 shift
102 remote=$1
103 shift
105 --*)
106 echo "error: unknown option"
107 usage
108 exit 1
111 section="$1"
112 tag_previous="$2"
113 tag_current="$3"
114 shift 3
115 if [ $# != 0 ]; then
116 echo "error: unknown parameter"
117 usage
118 exit 1
121 esac
122 done
124 # Check for uncommitted/queued changes.
125 if [ "x$ignorechanges" != "x1" ]; then
126 set +e
127 git diff --quiet HEAD > /dev/null 2>&1
128 if [ $? -ne 0 ]; then
129 abort_for_changes
131 set -e
134 # Check if the object has been pushed. Do do so
135 # 1. Check if the current branch has the object. If not, abort.
136 # 2. Check if the object is on $remote/branchname. If not, abort.
137 local_sha=`git rev-list -1 $tag_current`
138 current_branch=`git branch | grep "\*" | sed -e "s/\* //"`
139 set +e
140 git rev-list $current_branch | grep $local_sha > /dev/null
141 if [ $? -eq 1 ]; then
142 echo "Cannot find tag '$tag_current' on current branch. Aborting."
143 echo "Switch to the correct branch and re-run the script."
144 exit 1
147 revs=`git rev-list $remote/$current_branch..$current_branch | wc -l`
148 if [ $revs -ne 0 ]; then
149 git rev-list $remote/$current_branch..$current_branch | grep $local_sha > /dev/null
151 if [ $? -ne 1 ]; then
152 echo "$remote/$current_branch doesn't have object $local_sha"
153 echo "for tag '$tag_current'. Did you push branch first? Aborting."
154 exit 1
157 set -e
159 tarball_dir="$(dirname $(find . -name config.status))"
160 module="${tag_current%-*}"
161 if [ "x$module" = "x$tag_current" ]; then
162 # version-number-only tag.
163 pwd=`pwd`
164 module=`basename $pwd`
165 version="$tag_current"
166 else
167 # module-and-version style tag
168 version="${tag_current##*-}"
171 detected_module=`grep 'PACKAGE = ' $tarball_dir/Makefile | sed 's|PACKAGE = ||'`
172 if [ -f $detected_module-$version.tar.bz2 ]; then
173 module=$detected_module
176 modulever=$module-$version
177 tarbz2="$modulever.tar.bz2"
178 targz="$modulever.tar.gz"
179 announce="$tarball_dir/$modulever.announce"
181 echo "checking parameters"
182 if ! [ -f "$tarball_dir/$tarbz2" ] ||
183 ! [ -f "$tarball_dir/$targz" ] ||
184 [ -z "$tag_previous" ] ||
185 [ -z "$section" ]; then
186 echo "error: incorrect parameters!"
187 usage
188 exit 1
191 if [ "$section" = "libdrm" ]; then
192 section_path="libdrm"
193 srv_path="/srv/$host_dri/www/$section_path"
194 else
195 section_path="archive/individual/$section"
196 srv_path="/srv/$host_xorg/$section_path"
199 echo "checking for proper current dir"
200 if ! [ -d .git ]; then
201 echo "error: do this from your git dir, weenie"
202 exit 1
205 echo "checking for an existing tag"
206 if ! git tag -l $tag_current >/dev/null; then
207 echo "error: you must tag your release first!"
208 exit 1
211 echo "checking for an existing release"
212 if ssh $user$host_people ls $srv_path/$targz >/dev/null 2>&1 ||
213 ssh $user$host_people ls $srv_path/$tarbz2 >/dev/null 2>&1; then
214 if [ "x$force" = "xyes" ]; then
215 echo "warning: overriding released file ... here be dragons."
216 else
217 echo "error: file already exists!"
218 exit 1
222 echo "generating announce mail template, remember to sign it"
223 gen_announce_mail >$announce
224 echo " at: $announce"
226 echo "installing release into server"
227 scp $tarball_dir/$targz $tarball_dir/$tarbz2 $user$host_people:$srv_path
229 echo "pushing tag upstream"
230 git push $remote $tag_current