aboutsummaryrefslogtreecommitdiff
path: root/tools/release.sh
blob: 106799ceb2a833b54b71bef0da712425e0694951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
#!/bin/sh -e
# release.sh: openocd release process automation
# Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net>
# Release under the GNU GPL v2 (or later versions).

## set these to control the build process
#CONFIG_OPTS=""
#MAKE_OPTS=""

## DO NOT PERFORM LIVE RELEASES UNLESS YOU ARE THE RELEASE MANAGER!!!
RELEASE_DRY_RUN=1
## set this to perform individual steps on past releases
RELEASE_VERSION=

die() {
	echo "$@" >&2
	exit 1
}

svn_info_get() {
	svn info | grep "$1" | cut -d':' -f2- | cut -c2-
}

svn_setup_load() {
	SVN_ROOT="$(svn_info_get 'Repository Root')"
	SVN_URL="$(svn_info_get 'URL')"

	SVN_TRUNK="${SVN_ROOT}/trunk"

	SVN_BRANCHES="${SVN_ROOT}/branches"
	PACKAGE_BRANCH="${SVN_BRANCHES}/${PACKAGE_RELEASE}"

	SVN_TAGS="${SVN_ROOT}/tags"
	PACKAGE_TAG="${SVN_TAGS}/${PACKAGE_RELEASE}"

	if [ "${SVN_URL}" = "${SVN_TRUNK}" ]; then
		RELEASE_TYPE=minor
	elif [ "${SVN_URL/${SVN_BRANCHES}/}" != "${SVN_URL}" ]; then
		RELEASE_TYPE=micro
	else
		echo "error: bad URL: ${SVN_URL}" >&2
		die "unable to branch from the current location"
	fi
}
svn_setup_show() {
	cat <<INFO
Release Type: ${RELEASE_TYPE}
  Branch URL: ${PACKAGE_BRANCH}
     Tag URL: ${PACKAGE_TAG}
INFO
}

do_svn_echo_msg() { echo "svn: $1: $3"; }
do_svn_echo() {
	case "$1" in
	commit)
		do_svn_echo_msg "$@"
		shift 3
		[ "$*" ] && echo "Files: $@"
		;;
	copy|move)
		do_svn_echo_msg "$@"
		echo "From: ${4:-$2}"
		echo "  To: ${5:-$3}"
		;;
	*)
		local ACTION="$1"
		shift
		echo "svn: ${ACTION}: $@"
		;;
	esac
}
do_svn() {
	do_svn_echo "$@"
	[ "${RELEASE_DRY_RUN}" ] || svn "$@"
}
do_svn_switch() {
	do_svn switch "$@"
	package_info_load
}


package_info_load_name() {
	grep AC_INIT configure.in | perl -ne 's/^.+\(\[([-\w]*)\],.+$/$1/ and print'
}
package_info_load_version() {
	grep AC_INIT configure.in | perl -ne 's/^.+\[([-\w\.]*)\],$/$1/ and print'
}

package_info_load() {
	[ -f "configure.in" ] || \
		die "package_info_load: configure.in is missing"

	PACKAGE_NAME="$(package_info_load_name)"
	# todo: fix this
	PACKAGE_TARNAME="${PACKAGE_NAME}"

	PACKAGE_VERSION="$(package_info_load_version)"
	[ "${RELEASE_VERSION}" ] || \
		RELEASE_VERSION=${PACKAGE_VERSION/-in-development/}

	[ "${PACKAGE_NAME}" -a "${PACKAGE_VERSION}" ] || \
		die "package information is missing from configure script"

	PACKAGE_VERSION_TAGS=
	[ "${PACKAGE_VERSION/-/}" = "${PACKAGE_VERSION}" ] || \
		PACKAGE_VERSION_TAGS="-${PACKAGE_VERSION#*-}"
	PACKAGE_VERSION_BASE="${PACKAGE_VERSION%%-*}"
	PACKAGE_MICRO="${PACKAGE_VERSION_BASE##*.}"
	PACKAGE_MAJOR_AND_MINOR="${PACKAGE_VERSION_BASE%.*}"
	PACKAGE_MAJOR="${PACKAGE_MAJOR_AND_MINOR%.*}"
	PACKAGE_MINOR="${PACKAGE_MAJOR_AND_MINOR#*.}"

	PACKAGE_STRING="${PACKAGE_NAME} ${PACKAGE_VERSION}"
	if [ "${RELEASE_DRY_RUN}" ]; then
		PACKAGE_RELEASE="${PACKAGE_TARNAME}-${PACKAGE_VERSION}"
	else
		PACKAGE_RELEASE="${PACKAGE_TARNAME}-${RELEASE_VERSION}"
	fi
}

package_info_show() {
	cat <<INFO
Name: ${PACKAGE_TARNAME}
Release: ${RELEASE_VERSION}
Version: ${PACKAGE_VERSION}
   Number: ${PACKAGE_VERSION_BASE}
   Series: ${PACKAGE_MAJOR_AND_MINOR}
    Major: ${PACKAGE_MAJOR}
    Minor: ${PACKAGE_MINOR}
    Micro: ${PACKAGE_MICRO}
     Tags: ${PACKAGE_VERSION_TAGS}
 Branch: ${PACKAGE_RELEASE}
Release: ${PACKAGE_TARNAME}-${PACKAGE_VERSION_BASE}${PACKAGE_VERSION_TAGS}
INFO
}

usage() {
	cat << USAGE
usage: $0 <command>

Main Commands:
  info          Show a summary of the next pending release.
  release       Release the current tree as an archive.
  upload        Upload archives to berliOS project site

Build Commands:
  bootstrap     Prepare the working copy for configuration and building.
  configure     Configures the package; runs bootstrap, if needed.
  build         Compiles the project; runs configure, if needed.

Packaging Commands:
  changelog     Generate a new ChangeLog using svn2cl.
  package       Produce new distributable source archives.
  stage         Move archives to staging area for upload.

Repository Commands:
  commit        Perform branch and tag, as appropriate for the version.
  branch        Create a release branch from the project trunk.
  tag           Create a tag for the current release branch.

Other Commands:
  version ...   Perform version number and tag manipulations.
  maryslamb     Mary had a little lamb, but no one noticed.
  clean         Forces regeneration of results.
  clean_all     Removes all traces of the release process.
  help          Provides this list of commands.
  
For more information about this script, see the Release Processes page
in the OpenOCD Developer's Manual (doc/manual/release.txt).

WARNING: This script should be used by the Release Manager ONLY.
USAGE
	exit 0
}
do_usage() { usage; }
do_help()  { usage; }

do_info_show() {
	echo "Current Release Analysis:"
	package_info_show
	svn_setup_show
}

do_info() {
	package_info_load
	svn_setup_load
	do_info_show
}

do_bootstrap() {
	echo -n "Bootstrapping..."
	./bootstrap 2>&1 | perl tools/logger.pl > "release-bootstrap.log"
}
maybe_bootstrap() { [ -f "configure" ] || do_bootstrap; }

do_configure() {
	maybe_bootstrap
	echo -n "Configuring..."
	./configure ${CONFIG_OPTS} 2>&1 | perl tools/logger.pl > "release-config.log"
}
maybe_configure() { [ -f "Makefile" ] || do_configure; }

do_build() {
	maybe_configure
	echo -n "Compiling OpenOCD ${PACKAGE_VERSION}"
	make ${MAKE_OPTS} -C doc stamp-vti 2>&1 \
		| perl tools/logger.pl > "release-version.log"
	make ${MAKE_OPTS} 2>&1 \
		| perl tools/logger.pl > "release-make.log"
}
maybe_build() { [ -f "src/openocd" ] || do_build; }
do_build_clean() { [ -f Makefile ] && make maintainer-clean >/dev/null; }

do_changelog() {
	echo "Updating working copy to HEAD..."
	do_svn update
	echo "Creating ChangeLog..."
	svn2cl -i --authors AUTHORS.ChangeLog
}
maybe_changelog() {
	if [ -z "${RELEASE_DRY_RUN}" ] \
		|| [ ! -f ChangeLog ] \
		|| [ "$(cat ChangeLog | wc -l)" -lt 2 ]
	then
		do_changelog
	fi
}
do_changelog_clean() {
	do_svn revert ChangeLog
}

do_package() {
	package_info_load
	maybe_changelog
	maybe_build
	echo "Building distribution packages..."
	make ${MAKE_OPTS} distcheck 2>&1 | perl tools/logger.pl > "release-pkg.log"
}
maybe_package() { [ -f "${PACKAGE_RELEASE}.zip" ] || do_package; }
do_package_clean() {
	for EXT in tar.gz tar.bz2 zip; do
		rm -v -f *.${EXT}
	done
}

do_stage() {
	maybe_package
	echo "Staging package archives:"
	mkdir -p archives
	for EXT in tar.gz tar.bz2 zip; do
		local FILE="${PACKAGE_RELEASE}.${EXT}"
		# create archive signatures
		for HASH in md5 sha1; do
			echo "sign: ${FILE}.${HASH}"
			${HASH}sum "${FILE}" > "archives/${FILE}.${HASH}"
		done
		# save archive
		mv -v "${FILE}" archives/
	done
	cp -a NEWS archives/
	cp -a ChangeLog archives/
}
do_stage_clean() { rm -v -f -r archives; }

do_clean() {
	do_build_clean
	do_package_clean
	rm -v -f configure

	svn revert configure.in
	rm -v -f release-*.log
}
do_clean_all() {
	do_clean
	do_changelog_clean
	do_stage_clean
}

do_version_usage() {
	cat << USAGE
usage: $0 version <command>
Version Commands:
  tag {add|remove} <label>     Add or remove the specified tag.
  bump {major|minor|micro}     Bump the specified version number, and
                               reset less-significant numbers to zero.
  bump tag <label>             Add or bump a versioned tag (e.g. -rcN).
  bump final <label>           Remove a versioned tag (e.g. -rcN).
USAGE
}

do_version_sed() {
	local OLD_VERSION="${PACKAGE_VERSION}"
	local NEW_VERSION="$1"
	local MSG="$2"

	sed -i -e "/AC_INIT/ s|${OLD_VERSION}|${NEW_VERSION}|" configure.in
	package_info_load
	echo "${MSG}: ${OLD_VERSION} -> ${NEW_VERSION}"
}
do_version_bump_sed() {
	local NEW_VERSION="$1"
	[ -z "${PACKAGE_VERSION_TAGS}" ] || \
		NEW_VERSION="${NEW_VERSION}${PACKAGE_VERSION_TAGS}"

	do_version_sed "${NEW_VERSION}" \
		"Bump ${CMD} package version number"
}
do_version_bump_major() {
	do_version_bump_sed "$((PACKAGE_MAJOR + 1)).0.0"
}
do_version_bump_minor() {
	do_version_bump_sed "${PACKAGE_MAJOR}.$((PACKAGE_MINOR + 1)).0"
}
do_version_bump_micro() {
	do_version_bump_sed "${PACKAGE_MAJOR_AND_MINOR}.$((PACKAGE_MICRO + 1))"
}
do_version_bump_tag() {
	local TAG="$1"
	[ "${TAG}" ] || die "TAG argument is missing"
	local TAGS="${PACKAGE_VERSION_TAGS}"
	if has_version_tag "${TAG}"; then
		local RC=$(do_version_tag_value "${TAG}")
		RC=$((${RC} + 1))
		TAGS=$(echo ${TAGS} | perl -npe "s/-${TAG}[\\d]*/-${TAG}${RC}/")
	else
		TAGS="-${TAG}1${PACKAGE_VERSION_TAGS}"
	fi
	PACKAGE_VERSION_TAGS="${TAGS}"
	do_version_bump_sed "${PACKAGE_VERSION_BASE}"
}
do_version_bump_final() {
	local TAG="$1"
	[ "${TAG}" ] || die "TAG argument is missing"
	has_version_tag "${TAG}" || die "-${TAG} tag is missing"
	do_version_tag_remove "${TAG}$(do_version_tag_value "${TAG}")"
}
do_version_bump() {
	CMD="$1"
	shift
	case "${CMD}" in
	major|minor|micro|final|tag)
		eval "do_version_bump_${CMD}" "$@"
		;;
	*)
		do_version_usage
		;;
	esac
}

has_version_tag() {
	test "${PACKAGE_VERSION/-${1}/}" != "${PACKAGE_VERSION}"
}
do_version_tag_value() {
	local TAG="$1"
	echo ${PACKAGE_VERSION_TAGS} | perl -ne "/-${TAG}"'(\d+)/ && print $1'
}
do_version_tag_add() {
	local TAG="$1"
	has_version_tag "${TAG}" && \
		die "error: tag '-${TAG}' exists in '${PACKAGE_VERSION}'"
	do_version_sed "${PACKAGE_VERSION}-${TAG}" \
		"Add '-${TAG}' version tag"
}
do_version_tag_remove() {
	local TAG="$1"
	has_version_tag "${TAG}" || \
		die "error: tag '-${TAG}' missing from '${PACKAGE_VERSION}'"
	do_version_sed "${PACKAGE_VERSION/-${TAG}/}" \
		"Remove '-${TAG}' version tag"
}
do_version_tag() {
	CMD="$1"
	shift
	case "${CMD}" in
	add|remove)
		local i=
		for i in "$@"; do 
			eval "do_version_tag_${CMD}" "${i}"
		done
		;;
	*)
		do_version_usage
		;;
	esac
}

do_version_commit() {
	[ "$(svn diff configure.in | wc -l)" -gt 0 ] || \
		die "error: no version changes to commit"
	do_svn commit -m "$1" configure.in
}

do_version() {
	package_info_load
	CMD="$1"
	shift
	case "${CMD}" in
	tag|bump)
		do_version_commit "$(eval "do_version_${CMD}" "$@")"
		;;
	commit)
		local MSG="$1"
		[ "${MSG}" ] || die "usage: $0 version commit <message>"
		do_version_commit "${MSG}"
		;;
	*)
		do_version_usage
		;;
	esac
}


do_branch() {
	package_info_load
	svn_setup_load
	do_svn copy -m "Branching version ${PACKAGE_VERSION}" \
		"${SVN_TRUNK}" "${PACKAGE_BRANCH}"
}
do_tag() {
	package_info_load
	svn_setup_load
	do_svn copy -m "Tagging version ${PACKAGE_VERSION}" \
		"${PACKAGE_BRANCH}" "${PACKAGE_TAG}"
}
do_commit() {
	package_info_load
	svn_setup_load

	[ "${PACKAGE_VERSION/in-development/}" = "${PACKAGE_VERSION}" ] || \
		die "'${PACKAGE_NAME}-${PACKAGE_VERSION}' cannot be released"

	[ "${PACKAGE_VERSION%.0}" = "${PACKAGE_VERSION}" ] || \
		do_branch
	do_tag
}


do_release_step_prep() {
	do_version tag remove in-development
	# reset RELEASE_VERSION now to allow release version to be detected
	export RELEASE_VERSION=
}
do_release_step_commit() { do_commit; }

do_release_step_branch_bump() {
	local TYPE="$1"
	echo "Bump ${TYPE} version and add tag:"
	do_version_bump ${TYPE}
	do_version_tag_add in-development
}
do_release_step_branch() {
	do_svn_switch "${PACKAGE_BRANCH}"
	do_version_commit "$(do_release_step_branch_bump micro)"
	do_svn_switch "${SVN_URL}"
}
do_release_step_news_msg() {
	cat <<MSG
Archive released NEWS file: NEWS -> NEWS-${RELEASE_VERSION}
Create new NEWS file from relesse script template.
MSG
}
do_release_step_news() {
	# archive NEWS and create new one from template
	do_svn move "NEWS" "NEWS-${RELEASE_VERSION}"

	[ "${RELEASE_DRY_RUN}" ] || cat >NEWS <<NEWS
This file should include items worth mentioning in the
OpenOCD ${PACKAGE_RELEASE} source archive release.

The following areas of OpenOCD functionality changed in this release:

JTAG Layer:
Target Layer:
Flash Layer:
Board, Target, and Interface Configuration Scripts:
Documentation:
Build and Release:

For more details about what has changed since the last release,
see the ChangeLog associated with this source archive.  For older NEWS,
see the NEWS files associated with each release (i.e. NEWS-<version>).

For more information about contributing test reports, bug fixes, or new
features and device support, please read the new Developer Manual (or
the BUGS and PATCHES files in the source archive).
NEWS
	do_svn add NEWS

	local MSG="$(do_release_step_news_msg)"
	do_svn commit -m "${MSG}" NEWS NEWS-${RELEASE_VERSION}
}
do_release_step_bump() {
	# major and minor releases require branch version update too
	[ "${RELEASE_TYPE}" = "micro" ] || do_release_step_branch
	# bump the current tree version as required.
	do_version_commit "$(do_release_step_branch_bump "${RELEASE_TYPE}")"

	[ "${RELEASE_TYPE}" = "micro" ] || do_release_step_news
}
do_release_step_package() {
	local A=${PACKAGE_TAG}
	local B=${A/https/http}
	local PACKAGE_BUILD=${B/${USER}@/}

	do_svn_switch "${PACKAGE_TAG}"
	do_svn_switch --relocate "${PACKAGE_TAG}" "${PACKAGE_BUILD}"

	# required to force SVN to update the in-source URL keyword
	[ "${RELEASE_DRY_RUN}" ] || rm -v -f src/openocd.c
	do_svn revert src/openocd.c

	do_stage
	do_clean

	do_svn_switch --relocate "${PACKAGE_BUILD}" "${PACKAGE_TAG}"
	do_svn_switch "${SVN_URL}"
}

do_release_step_1() { do_release_step_prep; }
do_release_step_2() { do_release_step_commit; }
do_release_step_3() { do_release_step_bump; }
do_release_step_4() { do_release_step_package; }

do_release_check() {
	echo -n "Are you sure you want to release '${PACKAGE_RELEASE}'?"
	read ANSWER
	if [ "${ANSWER}" != 'y' ]; then
		echo "Live release aborted!"
		exit 0
	fi
}
do_countdown() {
	echo -n "$1 in "
	for i in $(seq 5 -1 1); do
		echo -n "$i, "
	done
	echo "go!"
}

do_release() {
	package_info_load
	package_info_show

	if [ -z "${RELEASE_DRY_RUN}" ]; then
		do_release_check
		do_countdown "Starting live release"
	fi

	local i=
	for i in $(seq 1 4); do
		eval "do_release_step_${i}"
	done
}
do_all() { do_release "$@"; }

do_reset() {
	maybe_bootstrap
	maybe_configure
	do_clean_all
	svn revert configure.in
}

OPTIONS=$(getopt -o V --long live -n $0 -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "${OPTIONS}"
while true; do
	case "$1" in
	--live)
		export RELEASE_DRY_RUN=
		shift
		;;
	-V)
		exec $0 info
		;;
	--)
		shift
		break
		;;
	*)
		echo "Internal error"
		exit 1
		;;
	esac
done

CMD=$1
[ "${CMD}" ] || usage
shift

ACTION_CMDS="bootstrap|configure|build|changelog|package|stage|clean"
MISC_CMDS="all|info|version|tag|branch|commit|release|reset|help|usage"
CLEAN_CMDS="build_clean|changelog_clean|package_clean|stage_clean|clean_all"
CMDS="|${ACTION_CMDS}|${CLEAN_CMDS}|${MISC_CMDS}|"
is_command() { echo "${CMDS}" | grep "|$1|" >/dev/null; }

if is_command "${CMD}"; then
	eval "do_${CMD}" "$@"
else
	echo "error: unknown command: '${CMD}'"
	usage
fi