Skip to content

Instantly share code, notes, and snippets.

@firegurafiku
Last active August 29, 2015 14:22
Show Gist options
  • Save firegurafiku/6567488cdcaaae4a56c7 to your computer and use it in GitHub Desktop.
Save firegurafiku/6567488cdcaaae4a56c7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# obs-commit-version.sh: update CAF packages on OBS from Jenkins.
# This shell script is created for easy updating CAF binary packages located
# on OpenSUSE Build Service (OBS). It should be issued from the Jenkins after
# release has proven to be operating, like this:
#
# $ make
# $ make test
# $ make doc <-- this is a necessary step!
# $ obs-commit-version.sh --release <-- for release build
# -or-
# $ obs-commit-version.sh --nightly <-- for nightly build
#
# In brief, it performs the following steps:
#
# 1. Determines current version from <caf/config.h> header. It's crucial to
# have this version set correctly for script to operate properly.
# 2. If was run in '--nightly' mode, ask Git to describe current position on
# the revision tree related to determined stable version.
# 3. Checks out OBS project using "osc" tool. It uses default credentials
# specified in ~/.oscrc configuration file.
# 4. Puts new source tarball into OBS project.
# 5. Updates version in various spec files.
# 6. Commits changes files to trigger new OBS build.
#
# Copyright (c) 2015, Pavel Kretov <firegurafiku@gmail.com>
# Distributed under the terms of Boost Software License, or any other license
# used by C++ actor framework by the time you see this notice.
set -o nounset
set -o errexit
if [ $# -ne 2 ] ||
[ $1 != "--release" -a $1 != "--nightly" ] ; then
echo "Usage: $0 (--release|--nightly) NAMESPACE:PROJECT/PACKAGE" 2>&1
exit 1
fi
operatingMode="$1"
packageFqn="$2"
projectName="$(dirname "$packageFqn")"
packageName="$(basename "$packageFqn")"
sourceDir="$(pwd)"
# 1.
versionAsInt="$(sed -ne 's/# *define \+CAF_VERSION \+\([0-9]\)/\1/gp' libcaf_core/caf/config.hpp)"
versionMajor=$(( $versionAsInt / 10000 ))
versionMinor=$(( $versionAsInt / 100 % 100 ))
versionPatch=$(( $versionAsInt % 100 ))
versionAsStr="$versionMajor.$versionMinor.$versionPatch"
# 2.
version="$versionAsStr"
if [ "$operatingMode" = "--nightly" ] ; then
revisionDescription="$(git describe --tags --match="*${versionAsStr}*")"
revisionOffset=""
if [[ "$revisionDescription" =~ "${versionAsStr}"-([0-9]+.+) ]] ; then
revisionOffset="${BASH_REMATCH[1]/-/_}"
echo "CN = $revisionOffset"
fi
version="${version}_$revisionOffset"
fi
# 3, 4
buildDir="$sourceDir/build"
obsDir="$buildDir/obs-temp"
mkdir -p "$obsDir"
rm -rf "$obsDir"/*
cd "$obsDir"
osc checkout "$packageFqn"
cd "$packageFqn"
osc remove *.tar.gz
cd "$sourceDir"
sourceTarball="${version}.tar.gz"
tar czf "$obsDir/$packageFqn/$sourceTarball" * --exclude ".git" --exclude "build"
cd -
osc add *.tar.gz
# 5.
sed -i -e "s/^Version:\( \+\).\+/Version:\1$version/g" "$packageName.spec"
# 6.
osc commit "Automatic commit: $version, $operatingMode"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment