tagscript.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/bin/bash
  2. ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
  3. ##### release a version of FreeSWITCH
  4. sdir="."
  5. [ -n "${0%/*}" ] && sdir="${0%/*}"
  6. . $sdir/ci/common.sh
  7. check_pwd
  8. showusage() {
  9. cat >&2 <<EOF
  10. SYNOPSIS
  11. $0 [-s] <version>
  12. DESCRIPTION
  13. Creates a new FreeSWITCH tag after performing some sanity checks.
  14. The tag is optionally signed if '-s' is provided, but you should
  15. really sign any public release tags, so pass '-s'.
  16. <version> follows the format:
  17. 1.2-alpha3
  18. 1.2-beta3
  19. 1.2-rc3
  20. 1.2
  21. 1.2.13-rc4
  22. 1.2.13
  23. etc.
  24. This tool will take care of correctly naming the tag to be
  25. consistent with FreeSWITCH git policy from there.
  26. OPTIONS
  27. -s
  28. Signs the resulting tag.
  29. -d
  30. Debug mode. Remove the tag after creating it and don't warn about
  31. the lack of a signature.
  32. EOF
  33. exit 1;
  34. }
  35. opts=""
  36. debug=false
  37. while getopts "ds" o; do
  38. case "$o" in
  39. d) debug=true ;;
  40. s) opts="-s" ;;
  41. esac
  42. done
  43. shift $(($OPTIND-1))
  44. if [ -z "$1" ]; then
  45. showusage
  46. fi
  47. eval $(parse_version "$1")
  48. ngrep () { (echo "$2" | grep -e "$1" >/dev/null); }
  49. err () { echo "$1" >&2; exit 1; }
  50. ngrep '^[1-9]*$' "$gmajor" || \
  51. err "The major version '$gmajor' appears invalid."
  52. ngrep '^[0-9]*$' "$gminor" || \
  53. err "The minor version '$gminor' appears invalid."
  54. [ -z "$gmicro" ] || ngrep '^[0-9]*$' "$gmicro" || \
  55. err "The micro version '$gmicro' appears invalid."
  56. [ -z "$grev" ] || ngrep '^[.-]' "$grev" || \
  57. err "The revision '$grev' appears invalid."
  58. echo "We're going to release freeswitch v$gver" >&2
  59. echo >&2
  60. if ! ($debug || ngrep '-s' "$opts"); then
  61. cat >&2 <<EOF
  62. You've asked me to tag a release but haven't asked to me sign it by
  63. passing -s. I'll do this if you really want, but it's a bad idea if
  64. you're making an actual release of FreeSWITCH that'll be seen
  65. publicly.
  66. EOF
  67. while true; do
  68. echo -n "Is this just a test tag? (yes/no): " >&2
  69. read r
  70. [ -z "$r" ] && continue
  71. if [ "$r" = yes ] || [ "$r" = y ]; then
  72. (echo; echo "OK, I believe you."; echo) >&2
  73. break
  74. else
  75. (echo; echo "This is a bad idea then."; echo) >&2
  76. fi
  77. while true; do
  78. echo -n "Are you really really sure? (yes/no): " >&2
  79. read r
  80. [ -z "$r" ] && continue
  81. if [ "$r" = yes ] || [ "$r" = y ]; then
  82. (echo; echo "As you wish, you've been warned."; echo) >&2
  83. break
  84. else
  85. (echo; echo "Great; go setup a GPG key and try again with -s"; echo) >&2
  86. exit 1
  87. fi
  88. break
  89. done
  90. break
  91. done
  92. fi
  93. echo "Saving uncommitted changes before tagging..." >&2
  94. ret=$(git stash save "Save uncommitted changes before tagging.")
  95. if (ngrep '^Saved' "$ret"); then
  96. stash_saved=1
  97. fi
  98. echo "Determining next-release (release+1) version..." >&2
  99. if [ -n "$grev" ] && ngrep '[0-9]*$' "$grev"; then
  100. rev_ver="$(echo "$grev" | sed -e 's/^[^0-9]*\([0-9]*\)$/\1/')"
  101. next_rev="$((rev_ver+1))"
  102. next_ver="${gver%%$rev_ver}${next_rev}"
  103. elif [ -n "$grev" ]; then
  104. next_ver="${gver}1"
  105. elif ! [ "$gmicro" = "0" ]; then
  106. next_ver="${gver%%$micro}$((micro+1))"
  107. else
  108. next_ver="${gmajor}.$((gminor+1))-rc1"
  109. fi
  110. echo "Setting next-release version ($next_ver)..." >&2
  111. echo "${next_ver}" > build/next-release.txt
  112. git add build/next-release.txt
  113. echo "Changing the version of configure.ac..." >&2
  114. set_fs_ver "$gver" "$gmajor" "$gminor" "$gmicro" "$grev"
  115. echo "Committing the new version..." >&2
  116. git add configure.ac
  117. if ! (git commit --allow-empty -m "release FreeSWITCH $gver"); then
  118. cat >&2 <<EOF
  119. Committing the new version failed for some reason. Definitely look
  120. into this before proceeding.
  121. EOF
  122. err "Stopping here."
  123. fi
  124. echo "Tagging freeswitch v$gver..." >&2
  125. if ! (git tag -a ${opts} -m "FreeSWITCH $gver" "v$gver"); then
  126. cat >&2 <<EOF
  127. Committing the new tag failed for some reason. Maybe you didn't
  128. delete an old tag with this name? Definitely figure out what's wrong
  129. before proceeding.
  130. EOF
  131. err "Stopping here."
  132. fi
  133. if $debug; then
  134. (echo; echo "We're in debug mode, so we're cleaning up...") >&2
  135. git tag -d "v$gver" || true
  136. git reset --hard HEAD^ || true
  137. fi
  138. if [ -n "$stash_saved" ]; then
  139. echo "Restoring your uncommitted changes to your working directory..." >&2
  140. git stash pop >/dev/null
  141. fi
  142. cat 1>&2 <<EOF
  143. ----------------------------------------------------------------------
  144. The v$gver tag has been committed locally, but it will not be
  145. globally visible until you 'git push --tags' this repository up to the
  146. server (I didn't do that for you, as you might want to review first).
  147. Next step:
  148. git push --tags
  149. ----------------------------------------------------------------------
  150. EOF
  151. exit 0