]> git.notmuchmail.org Git - notmuch/blob - devel/release-checks.sh
util: Fix two corner-cases in boolean term quoting function
[notmuch] / devel / release-checks.sh
1 #!/usr/bin/env bash
2
3 set -eu
4 #set -x # or enter bash -x ... on command line
5
6 if [ x"${BASH_VERSION-}" = x ]
7 then    echo
8         echo "Please execute this script using 'bash' interpreter"
9         echo
10         exit 1
11 fi
12
13 set -o posix
14 set -o pipefail # bash feature
15
16 readonly DEFAULT_IFS="$IFS" # Note: In this particular case quotes are needed.
17
18 # Avoid locale-specific differences in output of executed commands
19 LANG=C LC_ALL=C; export LANG LC_ALL
20
21 readonly PV_FILE='bindings/python/notmuch/version.py'
22
23 # Using array here turned out to be unnecessarily complicated
24 emsgs=''
25 emsg_count=0
26 append_emsg ()
27 {
28         emsg_count=$((emsg_count + 1))
29         emsgs="${emsgs:+$emsgs\n}  $1"
30 }
31
32 for f in ./version debian/changelog NEWS "$PV_FILE"
33 do
34         if   [ ! -f "$f" ]; then append_emsg "File '$f' is missing"
35         elif [ ! -r "$f" ]; then append_emsg "File '$f' is unreadable"
36         elif [ ! -s "$f" ]; then append_emsg "File '$f' is empty"
37         fi
38 done
39
40 if [ -n "$emsgs" ]
41 then
42         echo 'Release files problems; fix these and try again:'
43         echo -e "$emsgs"
44         exit 1
45 fi
46
47 if read VERSION
48 then
49         if read rest
50         then    echo "'version' file contains more than one line"
51                 exit 1
52         fi
53 else
54         echo "Reading './version' file failed (suprisingly!)"
55         exit 1
56 fi < ./version
57
58 readonly VERSION
59
60 # In the rest of this file, tests collect list of errors to be fixed
61
62 verfail ()
63 {
64         echo No.
65         append_emsg "$@"
66         append_emsg "  Please follow the instructions in RELEASING to choose a version"
67 }
68
69 echo -n "Checking that '$VERSION' is good with digits and periods... "
70 case $VERSION in
71         *[^0-9.]*)
72                 verfail "'$VERSION' contains other characters than digits and periods" ;;
73         .*)     verfail "'$VERSION' begins with a period" ;;
74         *.)     verfail "'$VERSION' ends with a period" ;;
75         *..*)   verfail "'$VERSION' contains two consecutive periods" ;;
76         *.*)    echo Yes. ;;
77         *)      verfail "'$VERSION' is a single number" ;;
78 esac
79
80 echo -n "Checking that LIBNOTMUCH version macros & variables match ... "
81 # lib/notmuch.h
82 LIBNOTMUCH_MAJOR_VERSION=broken
83 LIBNOTMUCH_MINOR_VERSION=broken
84 LIBNOTMUCH_MICRO_VERSION=broken
85 # lib/Makefile.local
86 LIBNOTMUCH_VERSION_MAJOR=borken
87 LIBNOTMUCH_VERSION_MINOR=borken
88 LIBNOTMUCH_VERSION_RELEASE=borken
89
90 eval `awk 'NF == 3 && $1 == "#define" && $2 ~ /^LIBNOTMUCH_[A-Z]+_VERSION$/ \
91         && $3 ~ /^[0-9]+$/ { print $2 "=" $3 }' lib/notmuch.h`
92
93 eval `awk 'NF == 3 && $1 ~ /^LIBNOTMUCH_VERSION_[A-Z]+$/ && $2 == "=" \
94         && $3 ~ /^[0-9]+$/ { print $1 "=" $3 }' lib/Makefile.local`
95
96
97 check_version_component ()
98 {
99         eval local v1=\$LIBNOTMUCH_$1_VERSION
100         eval local v2=\$LIBNOTMUCH_VERSION_$2
101         if [ $v1 != $v2 ]
102         then    append_emsg "LIBNOTMUCH_$1_VERSION ($v1) does not equal LIBNOTMUCH_VERSION_$2 ($v2)"
103         fi
104 }
105
106 old_emsg_count=$emsg_count
107 check_version_component MAJOR MAJOR
108 check_version_component MINOR MINOR
109 check_version_component MICRO RELEASE
110 [ $old_emsg_count = $emsg_count ] && echo Yes. || echo No.
111
112 echo -n "Checking that this is Debian package for notmuch... "
113 read deb_notmuch deb_version rest < debian/changelog
114 if [ "$deb_notmuch" = 'notmuch' ]
115 then
116         echo Yes.
117 else
118         echo No.
119         append_emsg "Package name '$deb_notmuch' is not 'notmuch' in debian/changelog"
120 fi
121
122 echo -n "Checking that Debian package version is $VERSION-1... "
123
124 if [ "$deb_version" = "($VERSION-1)" ]
125 then
126         echo Yes.
127 else
128         echo No.
129         append_emsg "Version '$deb_version' is not '($VERSION-1)' in debian/changelog"
130 fi
131
132 echo -n "Checking that python bindings version is $VERSION... "
133 py_version=`python -c "execfile('$PV_FILE'); print __VERSION__"`
134 if [ "$py_version" = "$VERSION" ]
135 then
136         echo Yes.
137 else
138         echo No.
139         append_emsg "Version '$py_version' is not '$VERSION' in $PV_FILE"
140 fi
141
142 echo -n "Checking that NEWS header is tidy... "
143 if [ "`exec sed 's/./=/g; 1q' NEWS`" = "`exec sed '1d; 2q' NEWS`" ]
144 then
145         echo Yes.
146 else
147         echo No.
148         if [ "`exec sed '1d; s/=//g; 2q' NEWS`" != '' ]
149         then
150                 append_emsg "Line 2 in NEWS file is not all '=':s"
151         else
152                 append_emsg "Line 2 in NEWS file does not have the same length as line 1"
153         fi
154 fi
155
156 echo -n "Checking that this is Notmuch NEWS... "
157 read news_notmuch news_version news_date < NEWS
158 if [ "$news_notmuch" = "Notmuch" ]
159 then
160         echo Yes.
161 else
162         echo No.
163         append_emsg "First word '$news_notmuch' is not 'Notmuch' in NEWS file"
164 fi
165
166 echo -n "Checking that NEWS version is $VERSION... "
167 if [ "$news_version" = "$VERSION" ]
168 then
169         echo Yes.
170 else
171         echo No.
172         append_emsg "Version '$news_version' in NEWS file is not '$VERSION'"
173 fi
174
175 #eval `date '+year=%Y mon=%m day=%d'`
176 today0utc=`date --date=0Z +%s` # gnu date feature
177
178 echo -n "Checking that NEWS date is right... "
179 case $news_date in
180  '('[2-9][0-9][0-9][0-9]-[01][0-9]-[0123][0-9]')')
181         newsdate0utc=`nd=${news_date#\\(}; date --date="${nd%)} 0Z" +%s`
182         ddiff=$((newsdate0utc - today0utc))
183         if [ $ddiff -lt -86400 ] # since beginning of yesterday...
184         then
185                 echo No.
186                 append_emsg "Date $news_date in NEWS file is too much in the past"
187         elif [ $ddiff -gt 172800 ] # up to end of tomorrow...
188         then
189                 echo No.
190                 append_emsg "Date $news_date in NEWS file is too much in the future"
191         else
192                 echo Yes.
193         fi ;;
194  *)
195         echo No.
196         append_emsg "Date '$news_date' in NEWS file is not in format (yyyy-mm-dd)"
197 esac
198
199 readonly DATE=${news_date//[()]/} # bash feature
200 manthdata ()
201 {
202         set x $*
203         if [ $# != 7 ]
204         then
205                 append_emsg "'$mp' has too many '.TH' lines"
206                 man_mismatch=1
207         fi
208         man_date=${5-} man_version=${7-}
209 }
210
211 echo -n "Checking that manual page dates and versions are $DATE and $VERSION... "
212 manfiles=`find man -type f | sort`
213 man_pages_ok=Yes
214 for mp in $manfiles
215 do
216         case $mp in
217                 *.[0-9]) ;; # fall below this 'case ... esac'
218
219                 */Makefile.local | */Makefile ) continue ;;
220                 */.gitignore)   continue ;;
221                 *.bak)          continue ;;
222
223                 *)      append_emsg "'$mp': extra file"
224                         man_pages_ok=No
225                         continue
226         esac
227         manthdata `sed -n '/^[.]TH NOTMUCH/ { y/"/ /; p; }' "$mp"`
228         if [ "$man_version" != "$VERSION" ]
229         then    append_emsg "Version '$man_version' is not '$VERSION' in $mp"
230                 mman_pages_ok=No
231         fi
232         if [ "$man_date" != "$DATE" ]
233         then    append_emsg "DATE '$man_date' is not '$DATE' in $mp"
234                 man_pages_ok=No
235         fi
236 done
237 echo $man_pages_ok.
238
239 if [ -n "$emsgs" ]
240 then
241         echo
242         echo 'Release check failed; check these issues:'
243         echo -e "$emsgs"
244         exit 1
245 fi
246
247 echo 'All checks this script executed completed successfully.'
248 echo 'Make sure that everything else mentioned in RELEASING'
249 echo 'file is in order, too.'
250
251
252 # Local variables:
253 # mode: shell-script
254 # sh-basic-offset: 8
255 # tab-width: 8
256 # End:
257 # vi: set sw=8 ts=8