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.
 
 
 
 
 
 

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