Commit 2404d2b2 authored by Dominik Charousset's avatar Dominik Charousset

Merge pull request #364 from firegurafiku/develop

Simplify obs-commit-version.sh
parents ebc206ea af46925f
...@@ -8,16 +8,14 @@ ...@@ -8,16 +8,14 @@
# $ make # $ make
# $ make test # $ make test
# $ make doc <-- this is a necessary step! # $ make doc <-- this is a necessary step!
# $ obs-commit-version.sh --release <-- for release build # $ scripts/obs-commit-version.sh
# -or-
# $ obs-commit-version.sh --nightly <-- for nightly build
# #
# In brief, it performs the following steps: # In brief, it performs the following steps:
# #
# 1. Determines current version from <caf/config.h> header. It's crucial to # 1. Determines current version from <caf/config.h> header. It's crucial to
# have this version set correctly for script to operate properly. # have this version set correctly for script to operate properly.
# 2. If was run in '--nightly' mode, ask Git to describe current position on # 2. Determines current branch. If it's 'master' then rebuild stable
# the revision tree related to determined stable version. # packages, if it's 'develop' then rebuild nightly.
# 3. Checks out OBS project using "osc" tool. It uses default credentials # 3. Checks out OBS project using "osc" tool. It uses default credentials
# specified in ~/.oscrc configuration file. # specified in ~/.oscrc configuration file.
# 4. Puts new source tarball into OBS project. # 4. Puts new source tarball into OBS project.
...@@ -25,6 +23,7 @@ ...@@ -25,6 +23,7 @@
# 6. Commits changes files to trigger new OBS build. # 6. Commits changes files to trigger new OBS build.
# #
# Copyright (c) 2015, Pavel Kretov <firegurafiku@gmail.com> # Copyright (c) 2015, Pavel Kretov <firegurafiku@gmail.com>
# Copyright (c) 2015, Dominik Charousset <dominik.charousset@haw-hamburg.de>
# #
# Distributed under the terms and conditions of the BSD 3-Clause License or # Distributed under the terms and conditions of the BSD 3-Clause License or
# (at your option) under the terms and conditions of the Boost Software # (at your option) under the terms and conditions of the Boost Software
...@@ -37,69 +36,87 @@ ...@@ -37,69 +36,87 @@
set -o nounset set -o nounset
set -o errexit set -o errexit
# check for `osc` command # Script configuration (yet unlikely to change in the future).
type osc > /dev/null 2>&1 || { confReleaseBranch="master"
confNightlyBranch="develop"
confReleaseProject="devel:libraries:caf"
confNightlyProject="devel:libraries:caf:nightly"
confReleasePackage="caf"
confNightlyPackage="caf"
# Check for 'osc' command.
type osc >/dev/null 2>&1 || {
echo "This script requires 'osc', please install it first." >&2 echo "This script requires 'osc', please install it first." >&2
exit 1 exit 1
} }
# check if header exists sourceDir="$PWD"
if [ ! -f "libcaf_core/caf/config.hpp" ] ; then
# Check if header exists.
if [ ! -f "$sourceDir/libcaf_core/caf/config.hpp" ] ; then
echo "This script must be called from the root directly of CAF." >&2 echo "This script must be called from the root directly of CAF." >&2
exit 1 exit 1
fi fi
# check arguments if [ ! -d "$sourceDir/html" \
if [ $# -ne 2 ] || [ $1 != "--release" -a $1 != "--nightly" ] ; then -o ! -f "$sourceDir/manual/manual.html"\
echo "Usage: $0 (--release|--nightly) NAMESPACE:PROJECT/PACKAGE" >&2 -o ! -f "$sourceDir/manual/manual.pdf" ] ; then
echo "Documentation must be generated before calling this script." >&2
exit 1 exit 1
fi fi
operatingMode="$1" # Extract version information from header file.
packageFqn="$2"
projectName="$(dirname "$packageFqn")"
packageName="$(basename "$packageFqn")"
sourceDir="$PWD"
# 1.
versionAsInt=$(grep "#define CAF_VERSION" libcaf_core/caf/config.hpp | awk '{print $3'}) versionAsInt=$(grep "#define CAF_VERSION" libcaf_core/caf/config.hpp | awk '{print $3'})
versionMajor=$(echo "$versionAsInt / 10000" | bc) versionMajor=$(echo "$versionAsInt / 10000" | bc)
versionMinor=$(echo "( $versionAsInt / 100 ) % 100" | bc) versionMinor=$(echo "( $versionAsInt / 100 ) % 100" | bc)
versionPatch=$(echo "$versionAsInt % 100" | bc) versionPatch=$(echo "$versionAsInt % 100" | bc)
versionAsStr="$versionMajor.$versionMinor.$versionPatch" versionAsStr="$versionMajor.$versionMinor.$versionPatch"
# 2. # Retrieve current branch from git.
version=$versionAsStr gitBranch=`git rev-parse --abbrev-ref HEAD`
if [ "$operatingMode" = "--nightly" ] ; then
version="${versionAsStr}_$(date +%Y%m%d)" if [ "$gitBranch" = "$confReleaseBranch" ] ; then
projectName="$confReleaseProject"
packageName="$confReleasePackage"
packageVersion="${versionAsStr}"
elif [ "$gitBranch" = "$confNightlyBranch" ] ; then
projectName="$confNightlyProject"
packageName="$confNightlyPackage"
packageVersion="${versionAsStr}_$(date +%Y%m%d)"
else
# Don't prevent other branches from building, but issue a warning.
echo "Not on '$confReleaseBranch' or '$confNightlyBranch' branch. Exitting." >&2
exit
fi fi
# 3, 4 packageFqn="$projectName/$packageName"
sourceTarball="${versionAsStr}.tar.gz"
buildDir="$sourceDir/build" buildDir="$sourceDir/build"
obsDir="$buildDir/obs-temp" obsDir="$buildDir/obs-temp"
if [ -d "$obsDir" ]; then
rm -rf "$obsDir" # Prepare a directory for checkout.
fi [ -d "$obsDir" ] && rm -rf "$obsDir"
mkdir -p "$obsDir" mkdir -p "$obsDir"
cd "$obsDir" cd "$obsDir"
# Checkout the project from OBS into a newly created directory.
echo "[obs-commit-version] Checking out"
osc checkout "$packageFqn" osc checkout "$packageFqn"
# Remove old tarball.
cd "$packageFqn" cd "$packageFqn"
osc remove *.tar.gz osc remove *.tar.gz
# And generate a new tarball.
cd "$sourceDir" cd "$sourceDir"
echo "[obs-commit-version] Generating tarball: ${versionAsStr}.tar.gz"
echo "generate tarball: ${version}.tar.gz"
sourceTarball="${version}.tar.gz"
tar czf "$obsDir/$packageFqn/$sourceTarball" --exclude ".git" --exclude "build" * tar czf "$obsDir/$packageFqn/$sourceTarball" --exclude ".git" --exclude "build" *
cd - cd - >/dev/null
osc add "$sourceTarball" osc add "$sourceTarball"
# 5. # Fix package version and commit.
sed -i.bk -E -e "s/^Version:([ ]+).+/Version:\1$version/g" "$packageName.spec" sed -i.bk -E -e "s/^Version:([ ]+).+/Version:\1$packageVersion/g" "$packageName.spec"
echo "[obs-commit-version] Comitting: $packageVersion, $gitBranch"
# 6. osc commit -m "Automatic commit: $packageVersion, $gitBranch"
osc commit -m "Automatic commit: $version, $operatingMode"
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