release.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/sh
  2. set -ue
  3. PATH=./.cabal-sandbox/bin${PATH:+:$PATH}
  4. ChoicesQuestion() {
  5. local question="$1" default="$2" first="$3" ans
  6. shift; shift; shift
  7. while true; do
  8. { echo -n "$question ["
  9. [ "$default" = "$first" ] && echo -n "$first" | tr '[a-z]' '[A-Z]' || echo -n "$first"
  10. for c in "$@"; do
  11. echo -n '/'
  12. [ "$default" = "$c" ] && echo -n "$c" | tr '[a-z]' '[A-Z]' || echo -n "$c"
  13. done
  14. echo -n '] '
  15. read ans;
  16. } </dev/tty >/dev/tty
  17. if ! [ "$ans" ]; then
  18. echo "$default"
  19. return
  20. else
  21. for c in "$first" "$@"; do
  22. [ "$ans" != "$c" ] || { echo "$ans"; return; }
  23. done
  24. fi
  25. done
  26. }
  27. YesNoQuestion() {
  28. local r=$(ChoicesQuestion "$1" "${2:-y}" y n)
  29. [ "$r" = y ]
  30. }
  31. Question() {
  32. local question="$1" default="$2" ans
  33. echo -n "$question [$default] " >/dev/tty
  34. read ans </dev/tty
  35. [ "$ans" ] || ans="$default"
  36. echo "$ans"
  37. }
  38. edit() {
  39. [ "${EDITOR:-}" ] || { echo "$$EDITOR is not set." >&2; exit 1; }
  40. $EDITOR "$1"
  41. [ ! -s "$1" ] || git add -v "$1"
  42. }
  43. updateVersion() {
  44. local version="$1"
  45. # Update the version number in the cabal file
  46. sed -ri "s/^(version:\s+).*/\1$version/
  47. s/\b(Agda\s+==\s+)[0-9.]+(,?)/\1$version\2/" \
  48. Agda.cabal
  49. # Update the version number in the elisp file
  50. sed -ri "s/(\(\s*defvar\s+agda2-version\s+)\"[0-9.]+\"/\1\"$version\"/" \
  51. src/data/emacs-mode/agda2-mode.el
  52. sed -ri "s/^(VERSION\s+=\s+).*/\1$version/" mk/paths.mk
  53. sed -ri "s/\"Agda version [0-9.]+\"/\"Agda version $version\"/" \
  54. test/interaction/Issue1244a.out \
  55. test/interaction/Issue1244b.out
  56. }
  57. run () {
  58. "$@" || YesNoQuestion "Error: Command \`$*' failed. Abort?" || exit 1
  59. }
  60. srcdir=$(mktemp -d --tmpdir "Agda-XXXXXX")
  61. trap 'rm -rf -- "$srcdir"' EXIT
  62. url=https://github.com/agda/agda
  63. git clone "$url" "$srcdir"
  64. cd "$srcdir"
  65. version=$( sed -rn '/^version:\s*([0-9]+\.[0-9]+)\.([0-9]+)(\.[0-9]+)?\s*$/ {s//\1 \2/p; q}' Agda.cabal \
  66. | { read maj min; echo "$maj.$(( 1 + $min))"; } )
  67. version=$( Question "Release version number?" "$version" )
  68. echo "$version" | grep -Eqx "[0-9]+(\.[0-9]+){2,3}" || { echo "Bad version number: $version" >&2; exit 1; }
  69. echo "$version" | grep -Eqx "[0-9]+(\.[0-9]+){2}" && maint=${version##*.} || maint=0
  70. notes=doc/release-notes/$( echo "$version" | tr . - ).txt
  71. ! YesNoQuestion "Edit release notes (in $notes)?" || edit "$notes"
  72. ! YesNoQuestion "Update README.md?" n || edit README.md
  73. ! YesNoQuestion "Update LICENSE file?" n || edit LICENSE
  74. updateVersion "$version"
  75. git add -v Agda.cabal \
  76. src/data/emacs-mode/agda2-mode.el \
  77. mk/paths.mk \
  78. test/interaction/Issue1244a.out \
  79. test/interaction/Issue1244b.out
  80. # Add a second source-repository section to Agda.cabal:
  81. cat >> Agda.cabal <<-EOF
  82. source-repository this
  83. type: git
  84. location: $url
  85. tag: $version
  86. EOF
  87. # Remove -Werror from Agda.cabal
  88. #
  89. # (Agda uses code generated by Cabal, Paths_Agda, and under some
  90. # configurations this code gives rise to warnings.)
  91. sed -ri '/-Werror(\s.*)?$/ {
  92. s/^(\s+ghc-options:)\s+-Werror(\s.*)?$/\1\2/; t
  93. /^\s+-Werror\s*$/d
  94. }' Agda.cabal
  95. # Ensure that cabal haddock works
  96. cabal sandbox init
  97. cabal update
  98. cabal install --only-dependencies -j
  99. cabal install alex haddock -j
  100. cabal configure
  101. run cabal haddock
  102. # Ensure that the Emacs mode can be compiled without errors or
  103. # warnings (except for the "cl package required at runtime" warning):
  104. find "src/data/emacs-mode" -type f -name '*.el' -print0 \
  105. | xargs -r0 emacs --batch -L "src/data/emacs-mode" -f batch-byte-compile
  106. find "src/data/emacs-mode" -type f -name '*.elc' -delete
  107. cabal sdist
  108. cabal check
  109. cabal install
  110. AGDA_BIN="`pwd`/.cabal-sandbox/bin/agda"
  111. export AGDA_BIN
  112. make install-fix-agda-whitespace
  113. run make test
  114. # Ensure that all the packages build properly.
  115. testdir=$(mktemp -d --tmpdir "Agda-XXXXXX-$version")
  116. trap 'rm -rf -- "$srcdir" "$testdir"' EXIT
  117. cd "$testdir"
  118. tar -xz --strip-components=1 -f "$srcdir/dist/Agda-$version.tar.gz"
  119. cabal sandbox init
  120. cabal update
  121. cabal install --only-dependencies -j
  122. cabal configure
  123. cabal install
  124. AGDA_BIN="`pwd`/.cabal-sandbox/bin/agda"
  125. export AGDA_BIN
  126. stdlib=std-lib
  127. git clone https://github.com/agda/agda-stdlib "$stdlib"
  128. cd "$stdlib"
  129. cabal sandbox --sandbox=../.cabal-sandbox init
  130. make Everything.agda
  131. cd "$srcdir"
  132. # XXX Do not forget to test the Emacs mode.
  133. git diff-index --cached --quiet HEAD || git commit -vm "Preparing new release ($version)."
  134. git tag "$version"
  135. git push --tags HEAD
  136. git checkout Agda.cabal
  137. cabal upload "dist/Agda-$version.tar.gz"
  138. # XXX Update the Agda Wiki.
  139. # XXX Announce the release of the new version on the Agda mailing list.
  140. [ $maint = 0 ] && maintv="$version" || maintv="${version%.*}"
  141. git checkout -b "maint-$maintv"
  142. updateVersion "${maintv}.$(( $maint + 1 ))"
  143. sed -ri 's/^#\s*(override CABAL_OPTS\+=--program-suffix=-\$\(VERSION\))$/\1/' Makefile
  144. git add Makefile
  145. git commit -vm "Release ${maintv}.$(( $maint + 1))."
  146. git checkout master
  147. git merge "maint-$version"
  148. if [ $maint = 0 ]; then
  149. # new major release
  150. git rm "$notes"
  151. notes=doc/release-notes/$( echo "${version%.*}.$(( 1 + ${version##*.}))" | tr . - ).txt
  152. cp -f template.txt "$notes"
  153. sed -ri "s/\bX\.Y\.Z\b/$version/" "$notes"
  154. sed -ri "s/^(\s+)-\smaster$/&\n\1- maint-$maintv/" .travis.yml
  155. git add -v .travis.yml "$notes"
  156. git commit -vm "Release $version."
  157. fi
  158. git push
  159. git checkout "maint-$version"
  160. git push -u origin "maint-$version"