release.sh: use the remote consistently.
[xorg-util-modular.git] / release.sh
blobaee00c3d714145912442d5bc30bf0fcc73bca067
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.freedesktop.org"
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 --exit-code > /dev/null 2>&1
128 if [ $? -ne 0 ]; then
129 abort_for_changes
132 git status > /dev/null 2>&1
133 if [ $? -eq 0 ]; then
134 abort_for_changes
136 set -e
139 # Check if the object has been pushed. Do do so
140 # 1. Check if the current branch has the object. If not, abort.
141 # 2. Check if the object is on $remote/branchname. If not, abort.
142 local_sha=`git rev-list -1 $tag_current`
143 current_branch=`git branch | grep "\*" | sed -e "s/\* //"`
144 set +e
145 git rev-list $current_branch | grep $local_sha > /dev/null
146 if [ $? -eq 1 ]; then
147 echo "Cannot find tag '$tag_current' on current branch. Aborting."
148 echo "Switch to the correct branch and re-run the script."
149 exit 1
152 revs=`git rev-list $remote/$current_branch..$current_branch | wc -l`
153 if [ $revs -ne 0 ]; then
154 git rev-list $remote/$current_branch..$current_branch | grep $local_sha > /dev/null
156 if [ $? -ne 1 ]; then
157 echo "$remote/$current_branch doesn't have object $local_sha"
158 echo "for tag '$tag_current'. Did you push branch first? Aborting."
159 exit 1
162 set -e
164 tarball_dir="$(dirname $(find . -name config.status))"
165 module="${tag_current%-*}"
166 if [ "x$module" = "x$tag_current" ]; then
167 # version-number-only tag.
168 pwd=`pwd`
169 module=`basename $pwd`
170 version="$tag_current"
171 else
172 # module-and-version style tag
173 version="${tag_current##*-}"
176 detected_module=`grep 'PACKAGE = ' $tarball_dir/Makefile | sed 's|PACKAGE = ||'`
177 if [ -f $detected_module-$version.tar.bz2 ]; then
178 module=$detected_module
181 modulever=$module-$version
182 tarbz2="$modulever.tar.bz2"
183 targz="$modulever.tar.gz"
184 announce="$tarball_dir/$modulever.announce"
186 echo "checking parameters"
187 if ! [ -f "$tarball_dir/$tarbz2" ] ||
188 ! [ -f "$tarball_dir/$targz" ] ||
189 [ -z "$tag_previous" ] ||
190 [ -z "$section" ]; then
191 echo "error: incorrect parameters!"
192 usage
193 exit 1
196 if [ "$section" = "libdrm" ]; then
197 section_path="libdrm"
198 srv_path="/srv/$host_dri/www/$section_path"
199 else
200 section_path="archive/individual/$section"
201 srv_path="/srv/$host_xorg/$section_path"
204 echo "checking for proper current dir"
205 if ! [ -d .git ]; then
206 echo "error: do this from your git dir, weenie"
207 exit 1
210 echo "checking for an existing tag"
211 if ! git tag -l $tag_current >/dev/null; then
212 echo "error: you must tag your release first!"
213 exit 1
216 echo "checking for an existing release"
217 if ssh $user$host_people ls $srv_path/$targz >/dev/null 2>&1 ||
218 ssh $user$host_people ls $srv_path/$tarbz2 >/dev/null 2>&1; then
219 if [ "x$force" = "xyes" ]; then
220 echo "warning: overriding released file ... here be dragons."
221 else
222 echo "error: file already exists!"
223 exit 1
227 echo "generating announce mail template, remember to sign it"
228 gen_announce_mail >$announce
229 echo " at: $announce"
231 echo "installing release into server"
232 scp $tarball_dir/$targz $tarball_dir/$tarbz2 $user$host_people:$srv_path
234 echo "pushing tag upstream"
235 git push $remote $tag_current