#!/bin/bash
USAGE="usage:
- gbs build [options] [target OBS project]
+ gbs build [options] [target OBS project] [-t tag]
Build package at remote build server, the default target OBS project
is home:<user_id>:branches:Trunk
options:
+ -t/--tag local tag for test build
-v/--verbose verbose mode
-h/--help print this info
"
case $1 in
-v|-d|--verbose) verbose=true
;;
+ -t|--tag) tag=$2
+ shift
+ ;;
-h|--help) echo "$USAGE"
exit
;;
[a-zA-Z0-9]*) target_obsproject=$1
;;
*)
+ if [ -n "$1" ]; then
+ die "Wrong parameters"
+ fi
break
;;
esac
passwd=$(gbs cfg passwd)
HUDSON_SERVER=$(gbs cfg src_server)
passwdx=$(gbs cfg passwdx)
+
+# If specified the tag, backend service will be forced to generate a source
+# tar from this tag instead of search in source server, only used for
+# test build
+
+if [ -n "$tag" ]; then
+ git rev-parse $tag > /dev/null 2>&1|| die "Invalid git object $tag"
+ commitid=$(git rev-list -1 $tag)
+fi
+
echo "Submiting your changes to build server"
-ret_string=$(curl -L -k -i -s -u$user:$passwd -Fname=package.tar.bz2 -Ffile0=@package.tar.bz2 -Fjson='{"parameter": [{"name": "package.tar.bz2", "file": "file0"},{"name":"pkg", "value":"'$prj_name'"},{"name":"parameters","value":"obsproject='$target_obsproject';passwdx='$passwdx'"}]}' -FSubmit=Build "$HUDSON_SERVER/job/build/build")
+ret_string=$(curl -L -k -i -s -u$user:$passwd -Fname=package.tar.bz2 -Ffile0=@package.tar.bz2 -Fjson='{"parameter": [{"name": "package.tar.bz2", "file": "file0"},{"name":"pkg", "value":"'$prj_name'"},{"name":"parameters","value":"obsproject='$target_obsproject';passwdx='$passwdx';commitid='$commitid'"}]}' -FSubmit=Build "$HUDSON_SERVER/job/build/build")
echo $ret_string|grep '302' > /dev/null
}
# Run under release branch, update spec file version, input: new_version, spec
-# Global env: spec
+# Global env: version
update_version()
{
- tag=$1
-
- version=${tag#v}
# Validation check
grep "^Version:" $spec > /dev/null ||die 'Invalid spec file: no "Version" directive defined'
# Golbal evn: srctar_md5sum
get_srctar_md5sum()
{
- tag=$1
+ version=$1
project=$2
+ commitid=$3
info_msg "Getting md5sum value for package $project at ref $tag, from server ..."
- string=`curl -L -k -s -i -u$user:$passwd -Fjson='{"parameter": [{"name": "tag", "value": "'$tag'"},{"name":"project", "value":"'$project'"}]}' -FSubmit=Build "$HUDSON_SERVER/job/srctar_md5sum/build"`
+ string=$(curl -L -k -s -i -u$user:$passwd -Fjson='{"parameter": [{"name": "version", "value": "'$version'"},{"name":"project", "value":"'$project'"},{"name":"parameters","value":"commitid='$commitid'"}]}' -FSubmit=Build "$HUDSON_SERVER/job/packaging/build")
sleep 2
echo $string|grep '302' > /dev/null
die "Server Error, please check your gbs configuration."
fi
- last_id=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/lastBuild/buildNumber"`
- result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/$last_id/api/json"`
+ last_id=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/lastBuild/buildNumber"`
+ result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/$last_id/api/json"`
last_prj=`echo $result_json|python -mjson.tool |grep "project" -A1|tail -1|cut -d'"' -f4`
last_user=`echo $result_json|python -mjson.tool |grep "userName" |cut -d'"' -f4`
# In case the last commit is not made by the user, supposed the last job triggered by '$user' is the one.
echo "Your request has been put in waiting queue of server, waiting to active ..."
while [ true ]
do
- ret_id=$(curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/lastBuild/buildNumber")
+ ret_id=$(curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/lastBuild/buildNumber")
if [ "$last_id" != "$ret_id" ]; then
- result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/$ret_id/api/json"`
+ result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/$ret_id/api/json"`
last_prj=`echo $result_json|python -mjson.tool |grep "project" -A1|tail -1|cut -d'"' -f4`
last_user=`echo $result_json|python -mjson.tool |grep "userName" |cut -d'"' -f4`
if [ "$last_prj" == "$project" -o "$last_user" != "$user" ]; then
# Waiting until the job finished
while [ true ]
do
- result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/$build_id/api/json"`
+ result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/$build_id/api/json"`
status=$(echo $result_json|python -mjson.tool |grep "building.*false")
if [ -n "$status" ]; then
break
done
echo ""
# Execuation result
- result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/$build_id/api/json"`
+ result_json=`curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/$build_id/api/json"`
result=`echo $result_json|python -mjson.tool |grep result|cut -d '"' -f4`
if [ x$result != xSUCCESS ]; then
echo -e "${ERR_COLOR}==== LOG FROM REMOTE SERVER ============${NO_COLOR}"
- curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/$build_id/consoleText"
+ curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/$build_id/consoleText"
echo -e "${ERR_COLOR}========================================${NO_COLOR}"
die 'Remote Server Exception'
else
- srctar_md5sum=$(curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/srctar_md5sum/$build_id/consoleText" | sed -n 's/.*#!#\(.*\)#!#.*/\1/p')
+ srctar_md5sum=$(curl -L -k -s -u$user:$passwd "$HUDSON_SERVER/job/packaging/$build_id/consoleText" | sed -n 's/.*#!#\(.*\)#!#.*/\1/p')
info_msg "md5sum output:"
echo " " "$srctar_md5sum"
echo ""
srctar_md5sum=$@
cp sources sources.origin
sed -i "/[0-9a-f]*\ *$project-.*/d" sources
- echo "$1 $2" >> sources
+ echo "$1" >> sources
}
while :
tag=$(git describe $git_obj --abbrev=0 --tags)
fi
+commitid=$(git rev-list -1 $tag)
+version=${tag#v}
+
user=$(gbs cfg user)
passwd=$(gbs cfg passwd)
HUDSON_SERVER=$(gbs cfg src_server)
info_msg "Packaging for major release ${tag}"
srctar_md5sum=""
-get_srctar_md5sum $tag $project
+get_srctar_md5sum $version $project $commitid
info_msg "Generating patches from $tag to $git_obj ..."
#info_msg " stored under tizen-patches dir"
update_sources "$srctar_md5sum"
info_msg "Updating version info in spec file ..."
-update_version $tag
+update_version
info_msg "Updating patches in spec file ..."
update_patches