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.
 
 
 
 
 
 

375 lines
8.9 KiB

  1. #!/bin/sh -e
  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. ## set these to control the build process
  6. #CONFIG_OPTS=""
  7. #MAKE_OPTS=""
  8. ## specifies the --next release type: major, minor, micro, rc, tag
  9. #RELEASE_TYPE=tag
  10. ## For tag release type, specifies the name of the tag (e.g. "foo").
  11. ## The default is the current user name, as found by the 'id' command.
  12. #RELEASE_TAG="$(id -un)"
  13. source "tools/release/helpers.sh"
  14. VERSION_SH="tools/release/version.sh"
  15. usage() {
  16. cat << USAGE
  17. usage: $0 <command> ...
  18. Command Options:
  19. --next name The branch's next release type: major, minor, micro, rc, tag.
  20. --next-tag name The name for the package version tag.
  21. --live Perform the actions in the repository.
  22. Main Commands:
  23. info Show a summary of the next pending release.
  24. release Release the current tree as an archive.
  25. Build Commands:
  26. bootstrap Prepare the working copy for configuration and building.
  27. configure Configures the package; runs bootstrap, if needed.
  28. build Compiles the project; runs configure, if needed.
  29. Packaging Commands:
  30. changelog Generate a new ChangeLog using ${SCM}2cl.
  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_changelog() {
  70. echo "Creating ChangeLog..."
  71. local CMD=tools/git2cl/git2cl
  72. eval ${CMD} ${OPTS} > ChangeLog
  73. }
  74. do_changelog_clean() {
  75. git checkout ChangeLog
  76. }
  77. do_package() {
  78. do_changelog
  79. maybe_build
  80. echo "Building distribution packages..."
  81. make ${MAKE_OPTS} distcheck 2>&1 | perl tools/logger.pl > "release-pkg.log"
  82. }
  83. maybe_package() { [ -f "${PACKAGE_RELEASE}.zip" ] || do_package; }
  84. do_package_clean() {
  85. for EXT in tar.gz tar.bz2 zip; do
  86. rm -v -f *.${EXT}
  87. done
  88. }
  89. do_stage() {
  90. maybe_package
  91. echo "Staging package archives:"
  92. mkdir -p archives
  93. for EXT in tar.gz tar.bz2 zip; do
  94. local FILE="${PACKAGE_RELEASE}.${EXT}"
  95. # create archive signatures
  96. for HASH in md5 sha1; do
  97. echo "sign: ${FILE}.${HASH}"
  98. ${HASH}sum "${FILE}" > "archives/${FILE}.${HASH}"
  99. done
  100. # save archive
  101. mv -v "${FILE}" archives/
  102. done
  103. cp -a NEWS archives/
  104. cp -a ChangeLog archives/
  105. }
  106. do_stage_clean() { rm -v -f -r archives; }
  107. do_clean() {
  108. do_build_clean
  109. do_package_clean
  110. do_changelog_clean
  111. rm -v -f release-*.log
  112. }
  113. do_clean_all() {
  114. do_clean
  115. do_stage_clean
  116. }
  117. do_version_commit() {
  118. [ "$*" ] || die "usage: $0 commit <message>"
  119. git add configure.in || die "error: no version changes to commit"
  120. git commit -q -m "$*" configure.in
  121. }
  122. do_version_finalize() {
  123. echo "The ${PACKAGE_NAME} ${RELEASE_VERSION} release."
  124. echo
  125. ${VERSION_SH} tag remove dev
  126. [ -z "${RELEASE_FINAL}" ] || ${VERSION_SH} bump final rc
  127. }
  128. has_dev_tag() {
  129. [ "${PACKAGE_VERSION/dev/}" != "${PACKAGE_VERSION}" ]
  130. }
  131. do_release_step_branch() {
  132. git checkout -b "v${RELEASE_VERSION}-release"
  133. }
  134. do_release_step_tag() {
  135. do_version_commit "$(do_version_finalize)"
  136. package_info_load
  137. [ "${PACKAGE_VERSION/dev/}" = "${PACKAGE_VERSION}" ] || \
  138. die "'${PACKAGE_NAME}-${PACKAGE_VERSION}' should not be tagged"
  139. local MSG="The ${PACKAGE_STRING} release."
  140. git tag -m "${MSG}" "v${PACKAGE_VERSION}"
  141. }
  142. do_bump_version() {
  143. echo -n "Bump ${RELEASE_TYPE} "
  144. [ -z "${RELEASE_TAG}" ] || echo -n "-${RELEASE_TAG} "
  145. echo -n "version and add "
  146. [ -z "${RELEASE_START_RC}" ] || echo -n "-rc0"
  147. echo "-dev tag."
  148. echo
  149. ${VERSION_SH} bump "${RELEASE_TYPE}" "${RELEASE_TAG}"
  150. [ -z "${RELEASE_START_RC}" ] || ${VERSION_SH} bump tag rc
  151. ${VERSION_SH} tag add dev
  152. }
  153. do_release_step_bump() {
  154. # bump the version number
  155. do_version_commit "$(do_bump_version)"
  156. }
  157. do_release_step_news_msg() {
  158. cat <<MSG
  159. Archive and recreate NEWS file.
  160. Archive released NEWS file as NEWS-${RELEASE_VERSION}.
  161. Create new NEWS file from release script template.
  162. MSG
  163. }
  164. do_release_step_news() {
  165. # only archive the NEWS file for major/minor releases
  166. [ "${RELEASE_TYPE}" = "major" -o "${RELEASE_TYPE}" = "minor" ] || \
  167. return 0
  168. # archive NEWS and create new one from template
  169. git mv "NEWS" "NEWS-${RELEASE_VERSION}"
  170. cat >NEWS <<NEWS
  171. This file should include items worth mentioning in the
  172. OpenOCD ${NEXT_RELEASE_VERSION} source archive release.
  173. The following areas of OpenOCD functionality changed in this release:
  174. JTAG Layer:
  175. Target Layer:
  176. Flash Layer:
  177. Board, Target, and Interface Configuration Scripts:
  178. Documentation:
  179. Build and Release:
  180. For more details about what has changed since the last release,
  181. see the ChangeLog associated with this source archive. For older NEWS,
  182. see the NEWS files associated with each release (i.e. NEWS-<version>).
  183. For more information about contributing test reports, bug fixes, or new
  184. features and device support, please read the new Developer Manual (or
  185. the BUGS and PATCHES files in the source archive).
  186. NEWS
  187. git add NEWS
  188. local MSG="$(do_release_step_news_msg)"
  189. git commit -q -m "${MSG}" NEWS "NEWS-${RELEASE_VERSION}"
  190. }
  191. do_release_step_package() {
  192. [ -z "${RELEASE_FAST}" ] || return 0
  193. git checkout -q "v${RELEASE_VERSION}"
  194. do_stage
  195. do_clean
  196. }
  197. do_release_step_rebranch() {
  198. # return to the new development head
  199. local OLD_BRANCH="v${RELEASE_VERSION}-release"
  200. git checkout "${OLD_BRANCH}"
  201. # create new branch with new version information
  202. package_info_load
  203. git checkout -b "v${PACKAGE_VERSION}"
  204. git branch -d "${OLD_BRANCH}"
  205. }
  206. do_release_step_0() { do_release_step_branch; }
  207. do_release_step_1() { do_release_step_tag; }
  208. do_release_step_2() { do_release_step_bump; }
  209. do_release_step_3() { do_release_step_news; }
  210. do_release_step_4() { do_release_step_package; }
  211. do_release_step_5() { do_release_step_rebranch; }
  212. do_release_setup() {
  213. echo "Starting $CMD for ${RELEASE_VERSION}..."
  214. [ "${RELEASE_TYPE}" ] || \
  215. die "The --next release type must be provided. See --help."
  216. }
  217. do_release_check() {
  218. [ -z "${RELEASE_FAST}" ] || return 0
  219. echo "Are you sure you want to ${CMD} '${PACKAGE_RELEASE}', "
  220. echo -n " to start a new ${RELEASE_TYPE} development cycle? (y/N) "
  221. read ANSWER
  222. if [ "${ANSWER}" != 'y' ]; then
  223. echo "Live release aborted!"
  224. exit 0
  225. fi
  226. do_countdown "Starting live release"
  227. }
  228. do_countdown() {
  229. echo -n "$1 in "
  230. for i in $(seq 5 -1 1); do
  231. echo -n "$i, "
  232. sleep 1
  233. done
  234. echo "go!"
  235. }
  236. do_branch() {
  237. do_release_setup
  238. local i=
  239. for i in 0 2 5; do
  240. "do_release_step_${i}"
  241. done
  242. }
  243. do_release() {
  244. local CMD='release'
  245. do_release_setup
  246. do_release_check
  247. local i=
  248. for i in $(seq 0 5); do
  249. "do_release_step_${i}"
  250. done
  251. }
  252. do_all() { do_release "$@"; }
  253. do_reset() {
  254. maybe_bootstrap
  255. maybe_configure
  256. do_clean_all
  257. git checkout configure.in
  258. }
  259. LONGOPTS="fast,final,start-rc,next-tag:,next:,help"
  260. OPTIONS=$(getopt -o 'V,n:' --long "${LONGOPTS}" -n $0 -- "$@")
  261. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  262. eval set -- "${OPTIONS}"
  263. while true; do
  264. case "$1" in
  265. --fast)
  266. RELEASE_FAST=yes
  267. shift
  268. ;;
  269. --final)
  270. RELEASE_FINAL=yes
  271. shift
  272. ;;
  273. --start-rc)
  274. RELEASE_START_RC=yes
  275. shift
  276. ;;
  277. -n|--next)
  278. export RELEASE_TYPE="$2"
  279. shift 2
  280. ;;
  281. --next-tag)
  282. export RELEASE_TAG="$2"
  283. shift 2
  284. ;;
  285. -V)
  286. exec $0 info
  287. ;;
  288. --)
  289. shift
  290. break
  291. ;;
  292. --help)
  293. usage
  294. shift
  295. ;;
  296. *)
  297. echo "Internal error"
  298. exit 1
  299. ;;
  300. esac
  301. done
  302. case "${RELEASE_TYPE}" in
  303. major|minor|micro|rc)
  304. ;;
  305. tag)
  306. [ "${RELEASE_TAG}" ] || RELEASE_TAG="$(id -u -n)"
  307. ;;
  308. '')
  309. ;;
  310. *)
  311. die "Unknown release type '${RELEASE_TYPE}'"
  312. ;;
  313. esac
  314. CMD=$1
  315. [ "${CMD}" ] || usage
  316. shift
  317. ACTION_CMDS="bootstrap|configure|build|changelog|package|stage|clean"
  318. MISC_CMDS="all|info|release|branch|reset|help|usage"
  319. CLEAN_CMDS="build_clean|changelog_clean|package_clean|stage_clean|clean_all"
  320. CMDS="|${ACTION_CMDS}|${CLEAN_CMDS}|${MISC_CMDS}|"
  321. is_command() { echo "${CMDS}" | grep "|$1|" >/dev/null; }
  322. package_info_load
  323. if is_command "${CMD}"; then
  324. "do_${CMD}" "$@"
  325. echo "Done with '${CMD}'." >&2
  326. else
  327. echo "error: unknown command: '${CMD}'"
  328. usage
  329. fi