5ca8d5a9b144f89d7c470fc6ea7ed0c184c70b01
[cvc5.git] / contrib / cut-release
1 #!/bin/bash
2 #
3 # usage: cut-release [-n] version-designation [make-args...]
4 #
5
6 function isthatright {
7 echo -n "Does that look right? [y/n] "
8 while read yn; do
9 if [ "$yn" = y -o "$yn" = Y -o "$yn" = yes -o "$yn" = YES -o "$yn" = Yes ]; then
10 break
11 elif [ "$yn" = n -o "$yn" = N -o "$yn" = no -o "$yn" = NO -o "$yn" = No ]; then
12 echo "Aborting as per user request." >&2
13 exit 1
14 else
15 echo -n "[y/n] "
16 fi
17 done
18 }
19
20 if [ "$1" = -n ]; then
21 dryrun=true
22 shift
23 else
24 dryrun=false
25 fi
26
27 if [ $# -lt 1 ]; then
28 echo "Usage: $(basename "$0") [-n] version-designation [make-args...]" >&2
29 echo "-n does a dry run (i.e., do sanity checks and build but don't touch the repository)"
30 exit 1
31 fi
32
33 if ! [ -e src/expr/node.h -a -e .svn ]; then
34 echo "$(basename "$0"): ERROR: you should run this from the top-level of a CVC4 subversion working directory" >&2
35 exit 1
36 fi
37
38 version="$1"
39 shift
40
41 if echo "$version" | grep '[^a-zA-Z0-9_.+(){}^%#-]' &>/dev/null; then
42 echo "$(basename "$0"): ERROR: version designation \`$version' contains illegal characters" >&2
43 exit 1
44 fi
45
46 vs=($(echo "$version" | sed 's,^\([0-9]*\)\.\([0-9]*\)\(\.\([0-9]*\)\)\?\(.*\),\1 \2 \4 \5,'))
47 major=${vs[0]}
48 minor=${vs[1]}
49 release=${vs[2]-0}
50 extra=${vs[3]}
51 echo
52 echo "Major : $major"
53 echo "Minor : $minor"
54 echo "Release: $release"
55 echo "Extra : $extra"
56 echo
57 version="$major.$minor"
58 if [ "$release" != 0 ]; then
59 version="$version.$release"
60 fi
61 version="$version$extra"
62 echo "Version: $version"
63 echo
64 isthatright
65
66 if ! svn ls "https://subversive.cims.nyu.edu/cvc4/cvc4/tags/releases/$version" 2>&1 >/dev/null | grep non-existent >/dev/null; then
67 echo "$(basename "$0"): ERROR: subversion repo already contains a release \`$version'" >&2
68 $dryrun || exit 1
69 fi
70
71 if $dryrun; then
72 if [ -n "$(svn status -q configure.ac)" ]; then
73 echo "$(basename "$0"): ERROR: in dry-run mode, cannot operate properly with local modifications to \"configure.ac\", sorry" >&2
74 exit 1
75 fi
76 elif [ -n "$(svn status -q)" ]; then
77 echo "$(basename "$0"): ERROR: \"svn status\" indicates there are local modifications; please commit first" >&2
78 exit 1
79 fi
80
81 root="$(svn info | grep "^Repository Root: https://subversive.cims.nyu.edu/.*" | cut -f3 -d' ')"
82 if [ -z "$root" ]; then
83 echo "$(basename "$0"): ERROR: can't get repository root URL" 2>&1
84 $dryrun || exit 1
85 fi
86
87 if [ `svn -uq status | wc -l` -ne 1 ]; then
88 echo "$(basename "$0"): ERROR: this working directory isn't up to date" 2>&1
89 $dryrun || exit 1
90 fi
91
92 if ! grep '^m4_define(_CVC4_MAJOR, *[0-9][0-9]* *)' configure.ac &>/dev/null ||
93 ! grep '^m4_define(_CVC4_MINOR, *[0-9][0-9]* *)' configure.ac &>/dev/null ||
94 ! grep '^m4_define(_CVC4_RELEASE, *[0-9][0-9]* *)' configure.ac &>/dev/null ||
95 ! grep '^m4_define(_CVC4_EXTRAVERSION, *\[.*\] *)' configure.ac &>/dev/null; then
96 echo "$(basename "$0"): ERROR: cannot locate the version info lines of configure.ac" >&2
97 $dryrun || exit 1
98 fi
99 perl -pi -e 's/^m4_define\(_CVC4_MAJOR, ( *)[0-9]+( *)\)/m4_define(_CVC4_MAJOR, ${1}'"$major"'$2)/;
100 s/^m4_define\(_CVC4_MINOR, ( *)[0-9]+( *)\)/m4_define(_CVC4_MINOR, ${1}'"$minor"'$2)/;
101 s/^m4_define\(_CVC4_RELEASE, ( *)[0-9]+( *)\)/m4_define(_CVC4_RELEASE, ${1}'"$release"'$2)/;
102 s/^m4_define\(_CVC4_EXTRAVERSION, ( *)\[.*\]( *)\)/m4_define(_CVC4_EXTRAVERSION, $1\['"$extra"'\]$2)/' configure.ac
103
104 trap 'echo; echo; echo "Aborting in error."; svn revert configure.ac; echo' EXIT
105
106 echo
107 echo 'Made the following change to configure.ac:'
108 echo
109 svn diff configure.ac
110 echo
111 isthatright
112
113 if ! grep '^m4_define(_CVC4_MAJOR, *'"$major"' *)' configure.ac &>/dev/null ||
114 ! grep '^m4_define(_CVC4_MINOR, *'"$minor"' *)' configure.ac &>/dev/null ||
115 ! grep '^m4_define(_CVC4_RELEASE, *'"$release"' *)' configure.ac &>/dev/null ||
116 ! grep '^m4_define(_CVC4_EXTRAVERSION, *\['"$extra"'\] *)' configure.ac &>/dev/null; then
117 echo "$(basename "$0"): INTERNAL ERROR: cannot find the modified version info lines in configure.ac, bailing..." >&2
118 exit 1
119 fi
120 if [ -z "$(svn status -q configure.ac)" ]; then
121 echo "$(basename "$0"): INTERNAL ERROR: \"svn status\" indicates there are no local modifications to configure.ac; I expected the ones I just made!" >&2
122 exit 1
123 fi
124
125 if ! $SHELL -c '\
126 version="'$version'"; \
127 set -ex; \
128 ./autogen.sh; \
129 mkdir "release-$version"; \
130 cd "release-$version"; \
131 ../configure production-cln-staticbinary --disable-shared --enable-unit-testing --with-cudd --with-readline; \
132 make dist "$@"; \
133 tar xf "cvc4-$version.tar.gz"; \
134 cd "cvc4-$version"; \
135 ./configure production-cln-staticbinary --disable-shared --enable-unit-testing --with-cudd --with-readline; \
136 make check "$@"; \
137 make distcheck "$@"; \
138 '; then
139 exit 1
140 fi
141
142 if ! [ -e release-$version/cvc4-$version.tar.gz ]; then
143 echo "$(basename "$0"): INTERNAL ERROR: cannot find the distribution tarball I just built" >&2
144 exit 1
145 fi
146 if ! [ -e release-$version/src/main/cvc4 ]; then
147 echo "$(basename "$0"): INTERNAL ERROR: cannot find the binary I just built" >&2
148 exit 1
149 fi
150
151 echo
152 echo 'This release of CVC4 will identify itself as:'
153 echo
154 release-$version/src/main/cvc4 --version
155 echo
156 isthatright
157
158 echo
159 echo 'This binary release of CVC4 will identify itself as being configured like this:'
160 echo
161 release-$version/src/main/cvc4 --show-config
162 echo
163 isthatright
164
165 echo
166 echo "Signing tarball..."
167 cp -p "release-$version/cvc4-$version.tar.gz" .
168 gpg -b --armor "cvc4-$version.tar.gz"
169
170 echo
171 echo "Signing binary..."
172 cp -p "release-$version/src/main/cvc4" "cvc4-$version"
173 gpg -b --armor "cvc4-$version"
174
175 echo
176 echo "About to run: svn commit -m \"Cutting release $version.\""
177 isthatright
178 $dryrun || svn commit -m "Cutting release $version."
179
180 echo
181 echo "About to run: svn copy -m \"Cutting release $version.\" \"$root\" \"https://subversive.cims.nyu.edu/cvc4/cvc4/tags/releases/$version\""
182 isthatright
183 $dryrun || svn copy -m "Cutting release $version." "$root" "https://subversive.cims.nyu.edu/cvc4/cvc4/tags/releases/$version"
184
185 trap '' EXIT
186