3 # This needs a bit more work, mostly on the "discplined engineering" front.
4 # IOW, instead of this UPSTREAM_BASE hack it would be better to have 3
6 # 1) pristine upstream: for tracking upstream progress/retrogression
7 # 2) patched upstream: pristine upstream with our patches applied
8 # 3) working local: patches upstream + a set of scripts (like this) to
9 # do everyday stuff like making new releases, exporting stuff to
12 # show help on usage and exit
15 echo "usage: $0 [options]"
16 echo "The possible options are"
17 echo " -n <name> name of the package"
18 echo " -v <version> version to give to this release"
19 echo " --release <gitrev> git branch, tag or SHA1 to release"
20 echo " --baseline <base> use <base> as baseline for release"
21 echo " --obs prepare for OBS release"
22 echo " --gerrit-review prepare for gerrit review"
23 echo " --gerrit-release prepare for gerrit release"
25 echo "<name> is the name of the package. <version> is the version you want"
26 echo "to give to this release in RPM. <gitrev> is the actual git version"
27 echo "(typically tag, branch, or SHA1) you want to release. If <base> is"
28 echo "specified the release will contain a set of patches on top of this"
29 echo "baseline. Otherwise no patches will be generated. If --obs is given"
30 echo "the relase will be generated in a format (spec, tarball + patches)"
31 echo "suitable for importing to OBS. If --gerrit-review or --gerrit-release"
32 echo "is used, the release will be generated as a branch suitable to be"
33 echo "pushed to gerrit for review or review-bypassing release."
36 echo "Prepare a branch of 'HEAD' for gerrit review as 0.0.9:"
37 echo " $0 --release HEAD -v 0.0.9 --gerrit-review"
39 echo "Prepare a branch of 'tizen' for gerrit release as 0.10.1:"
40 echo " $0 --release tizen -v 0.10.1 --gerrit-release"
42 echo "Prepare directory obs-0.5.0 from 'foobar' suitable for exporting"
43 echo "to OBS as version 0.5.0:"
44 echo " $0 --release foobar -v 0.5.0 --baseline foo"
46 echo "<name> defaults to $(basename $(pwd))"
47 echo "<release> defaults to HEAD"
48 echo "<version> defaults to $(default_version)"
53 # emit an error message to stderr
58 # emit an info message to stdout
63 # emit a warning message to stderr
65 echo "warning: $*" 1>&2
70 local _prefix="${1:- }"
75 # record an undo action
77 if [ -n "$UNDO" ]; then
84 # execute recorded undo actions
86 if [ -n "$UNDO" ]; then
87 echo "Executing recorded undo actions."
91 echo "Exiting due to errors."
95 # enable automatic undo
102 # generate default version number
104 echo "$(date +'%Y%m%d')"
107 # generate a tarball for a given package and version from git to a directory
109 local _pkg="$1" _pkgversion="$2" _gitversion="$3" _dir="$4"
110 local _tarball="$_dir/$_pkg-$_pkgversion.tar"
112 info "* Generating tarball $_tarball.gz..."
113 git archive --format=tar --prefix=$_pkg-$_pkgversion/ \
114 $_gitversion > $_tarball && \
118 # generate patches to a directory against a baseline, print list of patches
120 local _baseline="$1" _head="$2" _dir="$3" _patchret="$4" _patchlist
122 info "* Generating patches from $_baseline till $_head..." 1>&2
123 pushd $_dir >& /dev/null && \
124 _patchlist="`git format-patch -n $_baseline..$_head`" && \
127 if [ -n "$_patchret" ]; then
128 eval "$_patchret=\"$_patchlist\""
134 # generate a spec file from a spec template filling in version and patches
135 generate_specfile() {
136 local _specin="$1" _specout="$2" _version="$3" _patchlist
141 info "* Generating spec file $_specout (from $_specin)..."
143 cat $_specin | sed "s/@VERSION@/$_version/g" > $_specout.tmp && \
144 cat $_specout.tmp | while read -r line; do
148 for patch in $_patchlist; do
149 echo "Patch$i: $patch"
155 for patch in $_patchlist; do
164 done > $_specout && \
168 # generate a changelog for the release (with no real changelog content)
169 generate_changelog() {
170 local _chlog="$1" _version="$2" _gitver="$3" _author="$4"
173 info "* Generating changelog $_chlog for version $_version ($_gitver)..." |
176 _last="`git tag -l | grep accepted/$TARGET/ | tail -1`"
177 _sha="`git rev-parse $_gitver`"
179 rm -f $_chlog && touch $_chlog
181 echo "* $(date '+%a %b %d %H:%M:%S %Z %Y') $_author - $_version" > $_chlog
182 echo "- release: released $_version (git: $_sha)." >> $_chlog
184 if [ -n "$_last" ]; then
186 git cat-file -p $_last:$_chlog >> $_chlog
192 # generate linker scripts
193 generate_linker_scripts() {
194 info "* Generating linker scripts..."
195 ./bootstrap && ./configure && make generate-linker-scripts
198 # generate a release branch
200 local _br="$1" _rel="$2" _current
202 info "* Creating release branch $_br from $_rel..."
204 _current="`git_current_branch`"
206 git branch $_br $_rel
207 record_undo "git branch -D $_br"
210 record_undo "git checkout $_current"
213 # add files/directories to the repository
219 git commit -n -m "$_msg" $*
222 # add an annotated git tag
224 local _tag="$1" _msg="$2"
226 info "* Tagging for release..."
228 git tag -a -m "$_msg" $_tag
229 record_undo "git branch -D $_tag"
232 # run package-specific GBS quirks
233 package_gbs_quirks() {
237 _pkg_quirks="${0%/prepare-release.sh}/gbs-quirks"
238 if [ -f $_pkg_quirks ]; then
239 info "* Running package-specific GBS quirks ($_pkg_quirks)..."
242 info "* No package-specific GBS quirks found ($_pkg_quirks)..."
246 # parse the command line for configuration
247 parse_configuration() {
248 while [ -n "${1#-}" ]; do
251 if [ -z "$PKG" ]; then
255 error "Multiple package names ($PKG, $1) specified."
260 if [ -z "$VERSION" ]; then
264 error "Multiple versions ($VERSION, $1) specified."
268 --release|-R|--head|-H)
269 if [ -z "$RELEASE" ]; then
273 error "Multiple git versions ($RELEASE, $1) specified."
277 --base|--baseline|-B)
278 if [ -z "$BASELINE" ]; then
282 error "Multiple git baselines ($BASELINE, $1) specified."
290 if [ -z "$GBS" ]; then
294 error "Multiple --gbs options specified."
299 if [ -z "$GBS" ]; then
300 TYPE="${1#--gerrit-}"
303 error "Multiple --gerrit options specified."
308 if [ -z "$TARGET" ]; then
312 error "Multiple targets ($TARGET, $1) specified."
317 if [ -z "$AUTHOR" ]; then
321 error "Multiple authors ($AUTHOR, $1) specified."
330 DEBUG=$((${DEBUG:-0} + 1))
333 error "Unknown option or unexpected argument '$1'."
341 # determine current git branch
342 git_current_branch() {
345 _br="`git branch -l | grep '^[^ ]' | cut -d ' ' -f 2`"
352 local _dir _specin _specout _chlog _patches
353 local _stamp _branch _tag _remote
356 _specin=packaging.in/$PKG.spec.in
357 _specout=$_dir/$PKG.spec
358 _chlog=$_dir/$PKG.changes
359 _stamp=$(date -u +%Y%m%d.%H%M%S)
360 _branch=release/$TARGET/$_stamp
361 _tag=submit/$TARGET/$_stamp
364 release) _remote=refs/heads/$TARGET;;
365 review|*) _remote=refs/for/$TARGET;;
369 record_undo "rm -fr $TOPDIR/$_dir"
371 if [ -z "$BASELINE" ]; then
376 generate_patches $_base $RELEASE $_dir _patches
377 echo "$_patches" | tr -s '\t' ' ' | tr ' ' '\n' | indent "PATCHES: "
380 generate_specfile $_specin $_specout $VERSION $_patches | indent "GENSPEC: "
382 generate_branch $_branch $_base | indent " BRANCH: "
384 package_gbs_quirks 2>&1 | indent "QUIRKS: "
386 generate_changelog $_chlog $VERSION $RELEASE "$AUTHOR"
388 git_add "packaging: added packaging." $_dir | indent " GITADD: "
390 git_tag $_tag "Tagged $_stamp ($VERSION) for release to $TARGET." | \
394 info "Branch $_branch prepared for release. Please check if"
395 info "everything looks okay. If it does, you can proceed with the"
396 info "release by executing the following commands:"
398 info " git push <remote-repo> $_branch:$_remote"
399 info " git push <remote-repo> $_tag"
405 local _patches _dir _specin _specout
408 _specin=packaging.in/$PKG.spec.in
409 _specout=$_dir/$PKG.spec
412 rm -f $_dir/*.spec $_dir/*.tar.gz $_dir/*.patches
414 if [ -n "$BASELINE" ]; then
416 _patches="`generate_patches $_base $RELEASE $_dir`"
422 generate_specfile $_specin $_specout $VERSION $_patches
423 generate_tarball $PKG $VERSION $_base $_dir
427 #########################
430 if [ ! -d .git ]; then
431 error "Please always run ${0##*/} from the top directory."
434 TOPDIR=$(basename $(pwd))
437 parse_configuration $*
439 [ -z "$PKG" ] && PKG=$(basename `pwd`)
440 [ -z "$RELEASE" ] && RELEASE=HEAD
441 [ -z "$VERSION" ] && VERSION=$(default_version)
442 [ -z "$TARGET" ] && TARGET="tizen"
443 [ -z "$AUTHOR" ] && AUTHOR="`git config user.name` <`git config \
448 [ -n "$OBS" ] && kind=$(($kind + 1))
449 [ -n "$GBS" ] && kind=$(($kind + 1))
451 if [ "$kind" -gt 1 ]; then
452 error "Multiple release types specified (--obs, --gbs)."
455 if [ "$kind" = "0" ]; then
460 echo "Release configuration for package $PKG:"
461 echo " releasing: $RELEASE"
462 echo " as version: $VERSION"
463 echo " baseline: ${BASELINE:--}"
465 # enable recording and excuting undo actions
468 if [ -n "$OBS" ]; then