You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

362 lines
8.5 KiB

  1. #!/bin/bash
  2. # release.sh: openocd release process automation
  3. # Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net>
  4. # Release under the GNU GPL v2 (or later versions).
  5. # FIXME Remove more bash-isms. Fix errors making "ash -e" lose.
  6. ## set these to control the build process
  7. #CONFIG_OPTS=""
  8. #MAKE_OPTS=""
  9. ## specifies the --next release type: major, minor, micro, rc, tag
  10. #RELEASE_TYPE=tag
  11. ## For tag release type, specifies the name of the tag (e.g. "foo").
  12. ## The default is the current user name, as found by the 'id' command.
  13. #RELEASE_TAG="$(id -un)"
  14. . "tools/release/helpers.sh"
  15. VERSION_SH="tools/release/version.sh"
  16. usage() {
  17. cat << USAGE
  18. usage: $0 <command> ...
  19. Command Options:
  20. --next name The branch's next release type: major, minor, micro, rc, tag.
  21. --next-tag name The name for the package version tag.
  22. --live Perform the actions in the repository.
  23. Main Commands:
  24. info Show a summary of the next pending release.
  25. release Release the current tree as an archive.
  26. Build Commands:
  27. bootstrap Prepare the working copy for configuration and building.
  28. configure Configures the package; runs bootstrap, if needed.
  29. build Compiles the project; runs configure, if needed.
  30. Packaging Commands:
  31. package Produce new distributable source archives.
  32. stage Move archives to staging area for upload.
  33. Other Commands:
  34. clean Forces regeneration of results.
  35. clean_all Removes all traces of the release process.
  36. help Provides this list of commands.
  37. For more information about this script, see the Release Processes page
  38. in the OpenOCD Developer's Manual (doc/manual/release.txt).
  39. USAGE
  40. exit 0
  41. }
  42. do_usage() { usage; }
  43. do_help() { usage; }
  44. do_info() {
  45. echo "Current Release Analysis:"
  46. package_info_show
  47. }
  48. do_bootstrap() {
  49. echo -n "Bootstrapping..."
  50. ./bootstrap 2>&1 | perl tools/logger.pl > "release-bootstrap.log"
  51. }
  52. maybe_bootstrap() { [ -f "configure" ] || do_bootstrap; }
  53. do_configure() {
  54. maybe_bootstrap
  55. echo -n "Configuring..."
  56. ./configure ${CONFIG_OPTS} 2>&1 | perl tools/logger.pl > "release-config.log"
  57. }
  58. maybe_configure() { [ -f "Makefile" ] || do_configure; }
  59. do_build() {
  60. maybe_configure
  61. echo -n "Compiling OpenOCD ${PACKAGE_VERSION}"
  62. make ${MAKE_OPTS} -C doc stamp-vti 2>&1 \
  63. | perl tools/logger.pl > "release-version.log"
  64. make ${MAKE_OPTS} 2>&1 \
  65. | perl tools/logger.pl > "release-make.log"
  66. }
  67. maybe_build() { [ -f "src/openocd" ] || do_build; }
  68. do_build_clean() { [ -f Makefile ] && make maintainer-clean >/dev/null; }
  69. do_package() {
  70. maybe_build
  71. echo "Building distribution packages..."
  72. make ${MAKE_OPTS} distcheck 2>&1 | perl tools/logger.pl > "release-pkg.log"
  73. }
  74. maybe_package() { [ -f "${PACKAGE_RELEASE}.zip" ] || do_package; }
  75. do_package_clean() {
  76. for EXT in tar.gz tar.bz2 zip; do
  77. rm -v -f *.${EXT}
  78. done
  79. }
  80. do_stage() {
  81. maybe_package
  82. echo "Staging package archives:"
  83. mkdir -p archives
  84. for EXT in tar.gz tar.bz2 zip; do
  85. local FILE="${PACKAGE_RELEASE}.${EXT}"
  86. # create archive signatures
  87. for HASH in md5 sha1; do
  88. echo "sign: ${FILE}.${HASH}"
  89. ${HASH}sum "${FILE}" > "archives/${FILE}.${HASH}"
  90. done
  91. # save archive
  92. mv -v "${FILE}" archives/
  93. done
  94. cp -a NEWS archives/
  95. }
  96. do_stage_clean() { rm -v -f -r archives; }
  97. do_clean() {
  98. do_build_clean
  99. do_package_clean
  100. rm -v -f release-*.log
  101. }
  102. do_clean_all() {
  103. do_clean
  104. do_stage_clean
  105. }
  106. do_version_commit() {
  107. [ "$*" ] || die "usage: $0 commit <message>"
  108. git add configure.in || die "error: no version changes to commit"
  109. git commit -q -m "$*" configure.in
  110. }
  111. do_version_finalize() {
  112. echo "The ${PACKAGE_NAME} ${RELEASE_VERSION} release."
  113. echo
  114. ${VERSION_SH} tag remove dev
  115. [ -z "${RELEASE_FINAL}" ] || ${VERSION_SH} bump final rc
  116. }
  117. has_dev_tag() {
  118. [ "${PACKAGE_VERSION/dev/}" != "${PACKAGE_VERSION}" ]
  119. }
  120. do_release_step_branch() {
  121. git checkout -b "v${RELEASE_VERSION}-release"
  122. }
  123. do_release_step_tag() {
  124. do_version_commit "$(do_version_finalize)"
  125. package_info_load
  126. [ "${PACKAGE_VERSION/dev/}" = "${PACKAGE_VERSION}" ] || \
  127. die "'${PACKAGE_NAME}-${PACKAGE_VERSION}' should not be tagged"
  128. local MSG="The ${PACKAGE_STRING} release."
  129. git tag -m "${MSG}" "v${PACKAGE_VERSION}"
  130. }
  131. do_bump_version() {
  132. echo -n "Bump ${RELEASE_TYPE} "
  133. [ -z "${RELEASE_TAG}" ] || echo -n "-${RELEASE_TAG} "
  134. echo -n "version and add "
  135. [ -z "${RELEASE_START_RC}" ] || echo -n "-rc0"
  136. echo "-dev tag."
  137. echo
  138. ${VERSION_SH} bump "${RELEASE_TYPE}" "${RELEASE_TAG}"
  139. [ -z "${RELEASE_START_RC}" ] || ${VERSION_SH} bump tag rc
  140. ${VERSION_SH} tag add dev
  141. }
  142. do_release_step_bump() {
  143. # bump the version number
  144. do_version_commit "$(do_bump_version)"
  145. }
  146. do_release_step_news_msg() {
  147. cat <<MSG
  148. Archive and recreate NEWS file.
  149. Archive released NEWS file as NEWS-${RELEASE_VERSION}.
  150. Create new NEWS file from release script template.
  151. MSG
  152. }
  153. do_release_step_news() {
  154. # only archive the NEWS file for major/minor releases
  155. [ "${RELEASE_TYPE}" = "major" -o "${RELEASE_TYPE}" = "minor" ] || \
  156. return 0
  157. # archive NEWS and create new one from template
  158. git mv "NEWS" "NEWS-${RELEASE_VERSION}"
  159. cat >NEWS <<NEWS
  160. This file includes highlights of the changes made in the
  161. OpenOCD ${NEXT_RELEASE_VERSION} source archive release. See the
  162. repository history for details about what changed, including
  163. bugfixes and other issues not mentioned here.
  164. JTAG Layer:
  165. Boundary Scan:
  166. Target Layer:
  167. Flash Layer:
  168. Board, Target, and Interface Configuration Scripts:
  169. Documentation:
  170. Build and Release:
  171. For more details about what has changed since the last release,
  172. see the git repository history. With gitweb, you can browse that
  173. in various levels of detail.
  174. For older NEWS, see the NEWS files associated with each release
  175. (i.e. NEWS-<version>).
  176. For more information about contributing test reports, bug fixes, or new
  177. features and device support, please read the new Developer Manual (or
  178. the BUGS and PATCHES.txt files in the source archive).
  179. NEWS
  180. git add NEWS
  181. local MSG="$(do_release_step_news_msg)"
  182. git commit -q -m "${MSG}" NEWS "NEWS-${RELEASE_VERSION}"
  183. }
  184. do_release_step_package() {
  185. [ -z "${RELEASE_FAST}" ] || return 0
  186. git checkout -q "v${RELEASE_VERSION}"
  187. do_stage
  188. do_clean
  189. }
  190. do_release_step_rebranch() {
  191. # return to the new development head
  192. local OLD_BRANCH="v${RELEASE_VERSION}-release"
  193. git checkout "${OLD_BRANCH}"
  194. # create new branch with new version information
  195. package_info_load
  196. git checkout -b "v${PACKAGE_VERSION}"
  197. git branch -d "${OLD_BRANCH}"
  198. }
  199. do_release_setup() {
  200. echo "Starting $CMD for ${RELEASE_VERSION}..."
  201. [ "${RELEASE_TYPE}" ] || \
  202. die "The --next release type must be provided. See --help."
  203. }
  204. do_release_check() {
  205. [ -z "${RELEASE_FAST}" ] || return 0
  206. echo "Are you sure you want to ${CMD} '${PACKAGE_RELEASE}', "
  207. echo -n " to start a new ${RELEASE_TYPE} development cycle? (y/N) "
  208. read ANSWER
  209. if [ "${ANSWER}" != 'y' ]; then
  210. echo "Live release aborted!"
  211. exit 0
  212. fi
  213. do_countdown "Starting live release"
  214. }
  215. do_countdown() {
  216. echo -n "$1 in "
  217. for i in $(seq 5 -1 1); do
  218. echo -n "$i, "
  219. sleep 1
  220. done
  221. echo "go!"
  222. }
  223. do_branch() {
  224. do_release_setup
  225. local i=
  226. for i in branch bump rebranch; do
  227. "do_release_step_${i}"
  228. done
  229. }
  230. do_release() {
  231. local CMD='release'
  232. do_release_setup
  233. do_release_check
  234. local i=
  235. for i in branch tag bump news package rebranch; do
  236. "do_release_step_${i}"
  237. done
  238. }
  239. do_all() { do_release "$@"; }
  240. do_reset() {
  241. maybe_bootstrap
  242. maybe_configure
  243. do_clean_all
  244. git checkout configure.in
  245. }
  246. LONGOPTS="fast,final,start-rc,next-tag:,next:,help"
  247. OPTIONS=$(getopt -o 'V,n:' --long "${LONGOPTS}" -n $0 -- "$@")
  248. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  249. eval set -- "${OPTIONS}"
  250. while true; do
  251. case "$1" in
  252. --fast)
  253. RELEASE_FAST=yes
  254. shift
  255. ;;
  256. --final)
  257. RELEASE_FINAL=yes
  258. shift
  259. ;;
  260. --start-rc)
  261. RELEASE_START_RC=yes
  262. shift
  263. ;;
  264. -n|--next)
  265. export RELEASE_TYPE="$2"
  266. shift 2
  267. ;;
  268. --next-tag)
  269. export RELEASE_TAG="$2"
  270. shift 2
  271. ;;
  272. -V)
  273. exec $0 info
  274. ;;
  275. --)
  276. shift
  277. break
  278. ;;
  279. --help)
  280. usage
  281. shift
  282. ;;
  283. *)
  284. echo "Internal error"
  285. exit 1
  286. ;;
  287. esac
  288. done
  289. case "${RELEASE_TYPE}" in
  290. major|minor|micro|rc)
  291. ;;
  292. tag)
  293. [ "${RELEASE_TAG}" ] || RELEASE_TAG="$(id -u -n)"
  294. ;;
  295. '')
  296. ;;
  297. *)
  298. die "Unknown release type '${RELEASE_TYPE}'"
  299. ;;
  300. esac
  301. CMD=$1
  302. [ "${CMD}" ] || usage
  303. shift
  304. ACTION_CMDS="bootstrap|configure|build|package|stage|clean"
  305. MISC_CMDS="all|info|release|branch|reset|help|usage"
  306. CLEAN_CMDS="build_clean|package_clean|stage_clean|clean_all"
  307. CMDS="|${ACTION_CMDS}|${CLEAN_CMDS}|${MISC_CMDS}|"
  308. is_command() { echo "${CMDS}" | grep "|$1|" >/dev/null; }
  309. package_info_load
  310. if is_command "${CMD}"; then
  311. "do_${CMD}" "$@"
  312. echo "Done with '${CMD}'." >&2
  313. else
  314. echo "error: unknown command: '${CMD}'"
  315. usage
  316. fi