Accepting request 105039 from home:aspiers:branches:openSUSE:Tools

Change agreed with Adrian last week - only change the first occurrence of Version: header.

Also, when auto-detecting the version, use the newest matching file, since this allows it to work with tar_scm during disabledrun even without cleaning up old tarballs.

OBS-URL: https://build.opensuse.org/request/show/105039
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-set_version?expand=0&rev=6
This commit is contained in:
Adrian Schröter 2012-02-15 16:17:11 +00:00 committed by Git OBS Bridge
parent d5929060a1
commit c0d8590b17
3 changed files with 70 additions and 43 deletions

View File

@ -1,3 +1,20 @@
-------------------------------------------------------------------
Tue Feb 14 20:01:13 GMT 2012 - aspiers@suse.com
- only change the first occurrence of Version: header
- output useful info during run
- when auto-detecting the version, use the newest matching file
-------------------------------------------------------------------
Tue Feb 14 17:54:29 GMT 2012 - aspiers@suse.com
- patch License to follow spdx.org standard
-------------------------------------------------------------------
Mon Jan 30 17:54:19 GMT 2012 - aspiers@suse.com
- add --basename to usage help text
-------------------------------------------------------------------
Fri Jul 8 15:43:23 UTC 2011 - andrea@opensuse.org

View File

@ -1,7 +1,7 @@
#
# spec file for package obs-service-set_version
#
# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -18,10 +18,10 @@
Name: obs-service-set_version
License: GPL v2 or later
License: GPL-2.0+
Group: Development/Tools/Building
Summary: An OBS source service: Update spec file version
Version: 0.1
Version: 0.2
Release: 1
Source: set_version
Source1: set_version.service

View File

@ -36,52 +36,62 @@ while test $# -gt 0; do
;;
*)
echo Unknown parameter $1.
echo 'Usage: set_version --version $VERSION --file $FILE --outdir $OUT'
echo 'Usage: set_version --version $VERSION --file $FILE --basename $BASENAME --outdir $OUT'
exit 1
;;
esac
shift
done
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).tar.*,\1,p" | head -n 1`
fi
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).tgz$,\1,p" | head -n 1`
fi
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).tbz2$,\1,p" | head -n 1`
fi
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1 | sed -n "s,$BASENAME.*-\([0123456789].*\).zip$,\1,p" | head -n 1`
fi
if [ -z "$MYVERSION" ]; then
echo "ERROR: no version is given and can't get detected automatically"
exit 1
fi
if [ -z "$FILES" ]; then
FILES="*.spec *.dsc"
fi
if [ -z "$MYOUTDIR" ]; then
echo "ERROR: no output directory is given via --outdir parameter!"
exit 1
fi
for i in $FILES; do
FILE=`ls -1 $i 2>/dev/null`
[ -e "$FILE" ] || continue
sed "s,^Version:.*,Version: $MYVERSION," "$FILE" > "$MYOUTDIR/$FILE" || exit 1
if [ "${FILE%.spec}" != "$FILE" ]; then
# set release back to zero after version upgrade, will be increased by OBS during build
# also keep macros in release in case of fedora/mandriva
sed -r -i 's,^Release:[^%]*,Release: 0,' "$MYOUTDIR/$FILE" || exit 1
fi
if [ "${FILE#_service:}" != "$FILE" ]; then
# we can remove service files, no need to store them twice
rm -f "$FILE"
get_version_from_file () {
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tar.*,\1,p" | head -n 1`
fi
done
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tgz$,\1,p" | head -n 1`
fi
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tbz2$,\1,p" | head -n 1`
fi
if [ -z "$MYVERSION" ]; then
MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).zip$,\1,p" | head -n 1`
fi
if [ -z "$MYVERSION" ]; then
echo "ERROR: no version is given and can't get detected automatically"
exit 1
fi
echo "Detected version as $MYVERSION"
}
write_files () {
if [ -z "$FILES" ]; then
FILES="*.spec *.dsc"
fi
if [ -z "$MYOUTDIR" ]; then
echo "ERROR: no output directory is given via --outdir parameter!"
exit 1
fi
for i in $FILES; do
FILE=`ls -1 $i 2>/dev/null`
[ -e "$FILE" ] || continue
sed "0,/^Version:.*/s//Version: $MYVERSION/" "$FILE" > "$MYOUTDIR/$FILE" || exit 1
echo "Updated first occurrence (if any) of Version in $FILE to $MYVERSION"
if [ "${FILE%.spec}" != "$FILE" ]; then
# set release back to zero after version upgrade, will be increased by OBS during build
# also keep macros in release in case of fedora/mandriva
sed -r -i 's,^Release:[^%]*,Release: 0,' "$MYOUTDIR/$FILE" || exit 1
fi
if [ "${FILE#_service:}" != "$FILE" ]; then
# we can remove service files, no need to store them twice
rm -f "$FILE"
fi
done
}
get_version_from_file
write_files
exit 0