Commit 86a18b2d authored by Thomas Haller's avatar Thomas Haller

contrib/rpm: make "snapshot" for package version configurable via script

Will be used by CI trigger to name packages that are build during testing
of a github pull request with the corresponding pull request ID.

"build_clean.sh" now supports a command line option -s|--snapshot. But the
same paramter can also be set via $NM_BUILD_SNAPSHOT environment
variable. Using the environment variable is useful to support older versions
and new versions of "build_clean.sh", so that the script can just ignore the
snapshot setting if it doesn't understand it yet.
parent 37eed698
......@@ -19,7 +19,7 @@
%global rpm_version __VERSION__
%global real_version __VERSION__
%global release_version __RELEASE_VERSION__
%global snapshot %{nil}
%global snapshot __SNAPSHOT__
%global git_sha __COMMIT__
%global obsoletes_device_plugins 1:0.9.9.95-1
......
......@@ -8,6 +8,7 @@
# BUILDTYPE=|SRPM
# NM_RPMBUILD_ARGS=<additional argus for rpmbuild>
# RELEASE_VERSION=
# SNAPSHOT=
# VERSION=
# COMMIT_FULL=
# COMMIT=
......@@ -96,6 +97,7 @@ exec 2>&1
UUID=`uuidgen`
RELEASE_VERSION="${RELEASE_VERSION:-$(git rev-list HEAD | wc -l)}"
SNAPSHOT="${SNAPSHOT:-%{nil\}}"
VERSION="${VERSION:-$(get_version || die "Could not read $VERSION")}"
COMMIT_FULL="${COMMIT_FULL:-$(git rev-parse --verify HEAD || die "Error reading HEAD revision")}"
COMMIT="${COMMIT:-$(printf '%s' "$COMMIT_FULL" | sed 's/^\(.\{10\}\).*/\1/' || die "Error reading HEAD revision")}"
......@@ -131,6 +133,7 @@ fi
LOG "VERSION=$VERSION"
LOG "RELEASE_VERSION=$RELEASE_VERSION"
LOG "SNAPSHOT=$SNAPSHOT"
LOG "COMMIT_FULL=$COMMIT_FULL"
LOG "COMMIT=$COMMIT"
LOG "USERNAME=$USERNAME"
......@@ -164,6 +167,7 @@ write_changelog
sed -e "s/__VERSION__/$VERSION/g" \
-e "s/__RELEASE_VERSION__/$RELEASE_VERSION/g" \
-e "s/__SNAPSHOT__/$SNAPSHOT/g" \
-e "s/__COMMIT__/$COMMIT/g" \
-e "s/__COMMIT_FULL__/$COMMIT_FULL/g" \
-e "s/__SNAPSHOT__/$SNAPSHOT/g" \
......
......@@ -23,6 +23,7 @@ usage() {
echo " -N|--no-dist: skip creating the source tarball if you already did \`make dist\`"
echo " -w|--with \$OPTION: pass --with \$OPTION to rpmbuild. For example --with debug"
echo " -W|--without \$OPTION: pass --without \$OPTION to rpmbuild. For example --without debug"
echo " -s|--snapshot TEXT: use TEXT as the snapshot version for the new package (overwrites \$NM_BUILD_SNAPSHOT environment)"
}
......@@ -41,14 +42,11 @@ QUICK=0
NO_DIST=0
WITH_LIST=()
SOURCE_FROM_GIT=0
SNAPSHOT="$NM_BUILD_SNAPSHOT"
_next_with=
for A; do
if [ -n "$_next_with" ]; then
WITH_LIST=("${WITH_LIST[@]}" "$_next_with" "$A")
_next_with=
continue
fi
while [[ $# -gt 0 ]]; do
A="$1"
shift
case "$A" in
-h|--help|-\?|help)
usage
......@@ -63,6 +61,11 @@ for A; do
-S|--srpm)
BUILDTYPE=SRPM
;;
-s|--snapshot)
[[ $# -gt 0 ]] || die "Missing argument to $A"
SNAPSHOT="$1"
shift
;;
-g|--git)
NO_DIST=1
IGNORE_DIRTY=1
......@@ -77,10 +80,14 @@ for A; do
SOURCE_FROM_GIT=0
;;
-w|--with)
_next_with=--with
[[ $# -gt 0 ]] || die "Missing argument to $A"
WITH_LIST=("${WITH_LIST[@]}" "--with" "$1")
shift
;;
-W|--without)
_next_with=--without
[[ $# -gt 0 ]] || die "Missing argument to $A"
WITH_LIST=("${WITH_LIST[@]}" "--without" "$1")
shift
;;
*)
usage
......@@ -89,8 +96,6 @@ for A; do
esac
done
test -n "$_next_with" && die "Missing argument to $_next_with"
if [[ $GIT_CLEAN == 1 ]]; then
git clean -fdx :/
fi
......@@ -151,6 +156,7 @@ fi
export SOURCE_FROM_GIT
export BUILDTYPE
export NM_RPMBUILD_ARGS="${WITH_LIST[@]}"
export SNAPSHOT
"$SCRIPTDIR"/build.sh
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment