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