]> git.notmuchmail.org Git - notmuch/blob - devel/release-checks.sh
bf0d68a444b6ce940dc7e8f265f8efff56c7f4bf
[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 echo -n "Checking that git working directory is clean... "
63 git_status=`git status --porcelain`
64 if [ "$git_status" = '' ]
65 then
66         echo Yes.
67 else
68         echo No.
69         append_emsg "Git working directory is not clean (git status --porcelain)."
70 fi
71 unset git_status
72
73 verfail ()
74 {
75         echo No.
76         append_emsg "$@"
77         append_emsg "  Please follow the instructions in RELEASING to choose a version"
78 }
79
80 echo -n "Checking that '$VERSION' is good with digits and periods... "
81 case $VERSION in
82         *[!0-9.]*)
83                 verfail "'$VERSION' contains other characters than digits and periods" ;;
84         .*)     verfail "'$VERSION' begins with a period" ;;
85         *.)     verfail "'$VERSION' ends with a period" ;;
86         *..*)   verfail "'$VERSION' contains two consecutive periods" ;;
87         *.*)    echo Yes. ;;
88         *)      verfail "'$VERSION' is a single number" ;;
89 esac
90
91 echo -n "Checking that LIBNOTMUCH version macros & variables match ... "
92 # lib/notmuch.h
93 LIBNOTMUCH_MAJOR_VERSION=broken
94 LIBNOTMUCH_MINOR_VERSION=broken
95 LIBNOTMUCH_MICRO_VERSION=broken
96 # lib/Makefile.local
97 LIBNOTMUCH_VERSION_MAJOR=borken
98 LIBNOTMUCH_VERSION_MINOR=borken
99 LIBNOTMUCH_VERSION_RELEASE=borken
100
101 eval `awk 'NF == 3 && $1 == "#define" && $2 ~ /^LIBNOTMUCH_[A-Z]+_VERSION$/ \
102         && $3 ~ /^[0-9]+$/ { print $2 "=" $3 }' lib/notmuch.h`
103
104 eval `awk 'NF == 3 && $1 ~ /^LIBNOTMUCH_VERSION_[A-Z]+$/ && $2 == "=" \
105         && $3 ~ /^[0-9]+$/ { print $1 "=" $3 }' lib/Makefile.local`
106
107
108 check_version_component ()
109 {
110         eval local v1=\$LIBNOTMUCH_$1_VERSION
111         eval local v2=\$LIBNOTMUCH_VERSION_$2
112         if [ $v1 != $v2 ]
113         then    append_emsg "LIBNOTMUCH_$1_VERSION ($v1) does not equal LIBNOTMUCH_VERSION_$2 ($v2)"
114         fi
115 }
116
117 old_emsg_count=$emsg_count
118 check_version_component MAJOR MAJOR
119 check_version_component MINOR MINOR
120 check_version_component MICRO RELEASE
121 [ $old_emsg_count = $emsg_count ] && echo Yes. || echo No.
122
123 echo -n "Checking that this is Debian package for notmuch... "
124 read deb_notmuch deb_version rest < debian/changelog
125 if [ "$deb_notmuch" = 'notmuch' ]
126 then
127         echo Yes.
128 else
129         echo No.
130         append_emsg "Package name '$deb_notmuch' is not 'notmuch' in debian/changelog"
131 fi
132
133 echo -n "Checking that Debian package version is $VERSION-1... "
134
135 if [ "$deb_version" = "($VERSION-1)" ]
136 then
137         echo Yes.
138 else
139         echo No.
140         append_emsg "Version '$deb_version' is not '($VERSION-1)' in debian/changelog"
141 fi
142
143 echo -n "Checking that python bindings version is $VERSION... "
144 py_version=`python -c "with open('$PV_FILE') as vf: exec(vf.read()); print(__VERSION__)"`
145 if [ "$py_version" = "$VERSION" ]
146 then
147         echo Yes.
148 else
149         echo No.
150         append_emsg "Version '$py_version' is not '$VERSION' in $PV_FILE"
151 fi
152
153 echo -n "Checking that NEWS header is tidy... "
154 if [ "`exec sed 's/./=/g; 1q' NEWS`" = "`exec sed '1d; 2q' NEWS`" ]
155 then
156         echo Yes.
157 else
158         echo No.
159         if [ "`exec sed '1d; s/=//g; 2q' NEWS`" != '' ]
160         then
161                 append_emsg "Line 2 in NEWS file is not all '=':s"
162         else
163                 append_emsg "Line 2 in NEWS file does not have the same length as line 1"
164         fi
165 fi
166
167 echo -n "Checking that this is Notmuch NEWS... "
168 read news_notmuch news_version news_date < NEWS
169 if [ "$news_notmuch" = "Notmuch" ]
170 then
171         echo Yes.
172 else
173         echo No.
174         append_emsg "First word '$news_notmuch' is not 'Notmuch' in NEWS file"
175 fi
176
177 echo -n "Checking that NEWS version is $VERSION... "
178 if [ "$news_version" = "$VERSION" ]
179 then
180         echo Yes.
181 else
182         echo No.
183         append_emsg "Version '$news_version' in NEWS file is not '$VERSION'"
184 fi
185
186 #eval `date '+year=%Y mon=%m day=%d'`
187 today0utc=`date --date=0Z +%s` # gnu date feature
188
189 echo -n "Checking that NEWS date is right... "
190 case $news_date in
191  '('[2-9][0-9][0-9][0-9]-[01][0-9]-[0123][0-9]')')
192         newsdate0utc=`nd=${news_date#\\(}; date --date="${nd%)} 0Z" +%s`
193         ddiff=$((newsdate0utc - today0utc))
194         if [ $ddiff -lt -86400 ] # since beginning of yesterday...
195         then
196                 echo No.
197                 append_emsg "Date $news_date in NEWS file is too much in the past"
198         elif [ $ddiff -gt 172800 ] # up to end of tomorrow...
199         then
200                 echo No.
201                 append_emsg "Date $news_date in NEWS file is too much in the future"
202         else
203                 echo Yes.
204         fi ;;
205  *)
206         echo No.
207         append_emsg "Date '$news_date' in NEWS file is not in format (yyyy-mm-dd)"
208 esac
209
210 if [ -n "$emsgs" ]
211 then
212         echo
213         echo 'Release check failed; check these issues:'
214         echo -e "$emsgs"
215         exit 1
216 fi
217
218 echo 'All checks this script executed completed successfully.'
219 echo 'Make sure that everything else mentioned in RELEASING'
220 echo 'file is in order, too.'
221
222
223 # Local variables:
224 # mode: shell-script
225 # sh-basic-offset: 8
226 # tab-width: 8
227 # End:
228 # vi: set sw=8 ts=8