2
0

release-state-fn.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #! /bin/sh
  2. # Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # This will increase the version number and pre-release tag, according to the
  9. # current state of the source tree, and the function's first argument (called
  10. # |next| internally), which is how the caller tells what the next step should
  11. # be.
  12. #
  13. # The possible current source tree states are:
  14. # '' The source is in a released state.
  15. # 'dev' The source is in development. This is the normal state.
  16. # 'alpha', 'alphadev'
  17. # The source is undergoing a series of alpha releases.
  18. # 'beta', 'betadev'
  19. # The source is undergoing a series of beta releases.
  20. # These states are computed from $PRE_LABEL and $TYPE
  21. #
  22. # The possible |next| values are:
  23. # 'alpha' The source tree should move to an alpha release state, or
  24. # stay there. This trips the alpha / pre-release counter.
  25. # 'beta' The source tree should move to a beta release state, or
  26. # stay there. This trips the beta / pre-release counter.
  27. # 'final' The source tree should move to a final release (assuming it's
  28. # currently in one of the alpha or beta states). This turns
  29. # off the alpha or beta states.
  30. # '' The source tree should move to the next release. The exact
  31. # meaning depends on the current source state. It may mean
  32. # tripping the alpha / beta / pre-release counter, or increasing
  33. # the PATCH number.
  34. #
  35. # 'minor' The source tree should move to the next minor version. This
  36. # should only be used in the master branch when a release branch
  37. # has been created.
  38. #
  39. # This function expects there to be a function called fixup_version(), which
  40. # SHOULD take the |next| as first argument, and SHOULD increase the label
  41. # counter or the PATCH number accordingly, but only when the current
  42. # state is "in development".
  43. next_release_state () {
  44. local next="$1"
  45. local today="$(date '+%-d %b %Y')"
  46. local retry=true
  47. local before="$PRE_LABEL$TYPE"
  48. while $retry; do
  49. retry=false
  50. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$before=$before"
  51. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$next=$next"
  52. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$MAJOR=$MAJOR"
  53. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$MINOR=$MINOR"
  54. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$PATCH=$PATCH"
  55. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$TYPE=$TYPE"
  56. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$PRE_LABEL=$PRE_LABEL"
  57. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$PRE_NUM=$PRE_NUM"
  58. $DEBUG >&2 "DEBUG[next_release_state]: BEGIN: \$RELEASE_DATE=$RELEASE_DATE"
  59. case "$before+$next" in
  60. # MAKING ALPHA RELEASES ##################################
  61. # Alpha releases can't be made from beta versions or real versions
  62. beta*+alpha | +alpha )
  63. echo >&2 "Invalid state for an alpha release"
  64. echo >&2 "Try --beta or --final, or perhaps nothing"
  65. exit 1
  66. ;;
  67. # For alpha releases, the tag update is dev => alpha or
  68. # alpha dev => alpha for the release itself, and
  69. # alpha => alpha dev for post release.
  70. dev+alpha | alphadev+alpha )
  71. TYPE=
  72. RELEASE_DATE="$today"
  73. fixup_version "alpha"
  74. ;;
  75. alpha+alpha )
  76. TYPE=dev
  77. RELEASE_DATE=
  78. fixup_version "alpha"
  79. ;;
  80. # MAKING BETA RELEASES ###################################
  81. # Beta releases can't be made from real versions
  82. +beta )
  83. echo >&2 "Invalid state for beta release"
  84. echo >&2 "Try --final, or perhaps nothing"
  85. exit 1
  86. ;;
  87. # For beta releases, the tag update is dev => beta1, or
  88. # alpha{n}-dev => beta1 when transitioning from alpha to
  89. # beta, or beta{n}-dev => beta{n} for the release itself,
  90. # or beta{n} => beta{n+1}-dev for post release.
  91. dev+beta | alphadev+beta | betadev+beta )
  92. TYPE=
  93. RELEASE_DATE="$today"
  94. fixup_version "beta"
  95. ;;
  96. beta+beta )
  97. TYPE=dev
  98. RELEASE_DATE=
  99. fixup_version "beta"
  100. ;;
  101. # It's possible to switch from alpha to beta in the
  102. # post release. That's what --next-beta does.
  103. alpha+beta )
  104. TYPE=dev
  105. RELEASE_DATE=
  106. fixup_version "beta"
  107. ;;
  108. # MAKING FINAL RELEASES ##################################
  109. # Final releases can't be made from the main development branch
  110. dev+final)
  111. echo >&2 "Invalid state for final release"
  112. echo >&2 "This should have been preceded by an alpha or a beta release"
  113. exit 1
  114. ;;
  115. # For final releases, the starting point must be a dev state
  116. alphadev+final | betadev+final )
  117. TYPE=
  118. RELEASE_DATE="$today"
  119. fixup_version "final"
  120. ;;
  121. # The final step of a final release is to switch back to
  122. # development
  123. +final )
  124. TYPE=dev
  125. RELEASE_DATE=
  126. fixup_version "final"
  127. ;;
  128. # SWITCHING TO THE NEXT MINOR RELEASE ####################
  129. *+minor )
  130. TYPE=dev
  131. RELEASE_DATE=
  132. fixup_version "minor"
  133. ;;
  134. # MAKING DEFAULT RELEASES ################################
  135. # If we're coming from a non-dev, simply switch to dev.
  136. # fixup_version() should trip up the PATCH number.
  137. + )
  138. TYPE=dev
  139. fixup_version ""
  140. ;;
  141. # If we're coming from development, switch to non-dev, unless
  142. # the PATCH number is zero. If it is, we force the caller to
  143. # go through the alpha and beta release process.
  144. dev+ )
  145. if [ "$PATCH" = "0" ]; then
  146. echo >&2 "Can't update PATCH version number from 0"
  147. echo >&2 "Please use --alpha or --beta"
  148. exit 1
  149. fi
  150. TYPE=
  151. RELEASE_DATE="$today"
  152. fixup_version ""
  153. ;;
  154. # If we're currently in alpha, we continue with alpha, as if
  155. # the user had specified --alpha
  156. alpha*+ )
  157. next=alpha
  158. retry=true
  159. ;;
  160. # If we're currently in beta, we continue with beta, as if
  161. # the user had specified --beta
  162. beta*+ )
  163. next=beta
  164. retry=true
  165. ;;
  166. *)
  167. echo >&2 "Invalid combination of options"
  168. exit 1
  169. ;;
  170. esac
  171. $DEBUG >&2 "DEBUG[next_release_state]: END: \$before=$before"
  172. $DEBUG >&2 "DEBUG[next_release_state]: END: \$next=$next"
  173. $DEBUG >&2 "DEBUG[next_release_state]: END: \$MAJOR=$MAJOR"
  174. $DEBUG >&2 "DEBUG[next_release_state]: END: \$MINOR=$MINOR"
  175. $DEBUG >&2 "DEBUG[next_release_state]: END: \$PATCH=$PATCH"
  176. $DEBUG >&2 "DEBUG[next_release_state]: END: \$TYPE=$TYPE"
  177. $DEBUG >&2 "DEBUG[next_release_state]: END: \$PRE_LABEL=$PRE_LABEL"
  178. $DEBUG >&2 "DEBUG[next_release_state]: END: \$PRE_NUM=$PRE_NUM"
  179. $DEBUG >&2 "DEBUG[next_release_state]: END: \$RELEASE_DATE=$RELEASE_DATE"
  180. done
  181. }