]> git.notmuchmail.org Git - notmuch/blob - devel/release-checks.sh
devel/release-checks.sh: check NOTMUCH_(MAJOR|MINOR|MICRO)_VERSION
[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 _set_version_components ()
81 {
82         VERSION_MAJOR=$1
83         VERSION_MINOR=$2
84         VERSION_MICRO=${3:-0} # set to 0 in case $3 is unset or "null" (string)
85 }
86
87 IFS=.
88 _set_version_components $VERSION
89 IFS=$DEFAULT_IFS
90
91 echo -n "Checking that libnotmuch version macros match $VERSION... "
92 NOTMUCH_MAJOR_VERSION=broken
93 NOTMUCH_MINOR_VERSION=broken
94 NOTMUCH_MICRO_VERSION=broken
95 eval `awk 'NF == 3 && $1 == "#define" && $2 ~ /^NOTMUCH_[A-Z]+_VERSION$/ \
96         && $3 ~ /^[0-9]+$/ { print $2 "=" $3 }' lib/notmuch.h`
97
98 check_version_component ()
99 {
100         eval local v1=\$VERSION_$1
101         eval local v2=\$NOTMUCH_$1_VERSION
102         if [ $v1 != $v2 ]
103         then    append_emsg "NOTMUCH_$1_VERSION is defined as '$v2' in lib/notmuch.h instead of '$v1'"
104         fi
105 }
106
107 old_emsg_count=$emsg_count
108 check_version_component MAJOR
109 check_version_component MINOR
110 check_version_component MICRO
111 [ $old_emsg_count = $emsg_count ] && echo Yes. || echo No.
112
113 echo -n "Checking that this is Debian package for notmuch... "
114 read deb_notmuch deb_version rest < debian/changelog
115 if [ "$deb_notmuch" = 'notmuch' ]
116 then
117         echo Yes.
118 else
119         echo No.
120         append_emsg "Package name '$deb_notmuch' is not 'notmuch' in debian/changelog"
121 fi
122
123 echo -n "Checking that Debian package version is $VERSION-1... "
124
125 if [ "$deb_version" = "($VERSION-1)" ]
126 then
127         echo Yes.
128 else
129         echo No.
130         append_emsg "Version '$deb_version' is not '($VERSION-1)' in debian/changelog"
131 fi
132
133 echo -n "Checking that python bindings version is $VERSION... "
134 py_version=`python -c "execfile('$PV_FILE'); print __VERSION__"`
135 if [ "$py_version" = "$VERSION" ]
136 then
137         echo Yes.
138 else
139         echo No.
140         append_emsg "Version '$py_version' is not '$VERSION' in $PV_FILE"
141 fi
142
143 echo -n "Checking that NEWS header is tidy... "
144 if [ "`exec sed 's/./=/g; 1q' NEWS`" = "`exec sed '1d; 2q' NEWS`" ]
145 then
146         echo Yes.
147 else
148         echo No.
149         if [ "`exec sed '1d; s/=//g; 2q' NEWS`" != '' ]
150         then
151                 append_emsg "Line 2 in NEWS file is not all '=':s"
152         else
153                 append_emsg "Line 2 in NEWS file does not have the same length as line 1"
154         fi
155 fi
156
157 echo -n "Checking that this is Notmuch NEWS... "
158 read news_notmuch news_version news_date < NEWS
159 if [ "$news_notmuch" = "Notmuch" ]
160 then
161         echo Yes.
162 else
163         echo No.
164         append_emsg "First word '$news_notmuch' is not 'Notmuch' in NEWS file"
165 fi
166
167 echo -n "Checking that NEWS version is $VERSION... "
168 if [ "$news_version" = "$VERSION" ]
169 then
170         echo Yes.
171 else
172         echo No.
173         append_emsg "Version '$news_version' in NEWS file is not '$VERSION'"
174 fi
175
176 #eval `date '+year=%Y mon=%m day=%d'`
177 today0utc=`date --date=0Z +%s` # gnu date feature
178
179 echo -n "Checking that NEWS date is right... "
180 case $news_date in
181  '('[2-9][0-9][0-9][0-9]-[01][0-9]-[0123][0-9]')')
182         newsdate0utc=`nd=${news_date#\\(}; date --date="${nd%)} 0Z" +%s`
183         ddiff=$((newsdate0utc - today0utc))
184         if [ $ddiff -lt -86400 ] # since beginning of yesterday...
185         then
186                 echo No.
187                 append_emsg "Date $news_date in NEWS file is too much in the past"
188         elif [ $ddiff -gt 172800 ] # up to end of tomorrow...
189         then
190                 echo No.
191                 append_emsg "Date $news_date in NEWS file is too much in the future"
192         else
193                 echo Yes.
194         fi ;;
195  *)
196         echo No.
197         append_emsg "Date '$news_date' in NEWS file is not in format (yyyy-mm-dd)"
198 esac
199
200 readonly DATE=${news_date//[()]/} # bash feature
201 manthdata ()
202 {
203         set x $*
204         if [ $# != 7 ]
205         then
206                 append_emsg "'$mp' has too many '.TH' lines"
207                 man_mismatch=1
208         fi
209         man_date=${5-} man_version=${7-}
210 }
211
212 echo -n "Checking that manual page dates and versions are $DATE and $VERSION... "
213 manfiles=`find man -type f | sort`
214 man_pages_ok=Yes
215 for mp in $manfiles
216 do
217         case $mp in
218                 *.[0-9]) ;; # fall below this 'case ... esac'
219
220                 */Makefile.local | */Makefile ) continue ;;
221                 */.gitignore)   continue ;;
222                 *.bak)          continue ;;
223
224                 *)      append_emsg "'$mp': extra file"
225                         man_pages_ok=No
226                         continue
227         esac
228         manthdata `sed -n '/^[.]TH NOTMUCH/ { y/"/ /; p; }' "$mp"`
229         if [ "$man_version" != "$VERSION" ]
230         then    append_emsg "Version '$man_version' is not '$VERSION' in $mp"
231                 mman_pages_ok=No
232         fi
233         if [ "$man_date" != "$DATE" ]
234         then    append_emsg "DATE '$man_date' is not '$DATE' in $mp"
235                 man_pages_ok=No
236         fi
237 done
238 echo $man_pages_ok.
239
240 if [ -n "$emsgs" ]
241 then
242         echo
243         echo 'Release check failed; check these issues:'
244         echo -e "$emsgs"
245         exit 1
246 fi
247
248 echo 'All checks this script executed completed successfully.'
249 echo 'Make sure that everything else mentioned in RELEASING'
250 echo 'file is in order, too.'
251
252
253 # Local variables:
254 # mode: shell-script
255 # sh-basic-offset: 8
256 # tab-width: 8
257 # End:
258 # vi: set sw=8 ts=8