continuous_build.sh
author dermotm
Mon, 24 Jul 2006 12:30:39 +0000
branchgnome-2-10
changeset 19949 94f49bf19351
parent 19377 27a5aa8e43a4
permissions -rwxr-xr-x
access control test #4

#!/bin/bash

# host to rcp the rpms to
RHOST=blader

# user to rsh/rcp as (has to have root@<this host> in it's .rhosts file)
RUSER=gbuild

# directory to copy rpms/srpms to on the remote host
RPMSDIR=/sgnome/pkgs/gnome2.10/rpms/live
SRPMSDIR=/sgnome/pkgs/gnome2.10/srpms/live

# reply-to/to address to send the build log as/to
[email protected]
[email protected]

# date format appended to the Release tag in the spec files
# (passed to the date command on the cmd line)
RELEASE_DATE_FMT="%y%m%d.%H"

# date format used for naming the directories
DIR_DATE_FMT="%Y-%m-%d"

# document root of the web server
WEBROOT=/scde/web/docs

# subdir to keep logs and reports on the webserver
WEBDIR=gnome/releng/jds/gnome2.10/live
LOGDIR=$WEBDIR/logs

# subdir where nightly builds go
NIGHTLY_DIR=$WEBROOT/gnome/releng/jds/gnome2.10/nightly

# ------------ nothing to configure below this line --------------

#if [ "x$I_KNOW_WHAT_IM_DOING" != xyes ]; then
#    echo " ,---------------------------------------------------------------."
#    echo "| This script is intended to be run from cron for producing      |"
#    echo "| official nightly builds. It will mail responsible engineers    |"
#    echo "| if any build failure occurs, sends build reports to            v"
#    echo "| RE and update web pages."
#    echo "|"
#    echo "| Don't run it unless you know what you are doing. Thanks."
#    echo "|"
#    echo "| Mail [email protected] if you need more info."
#    echo "\`------>                                                         +"
#    exit 1
#fi

MYNAME="$0"
MYDIR=$(cd `dirname $0`; pwd)

if [ "x$1" != x ]; then
    SPECDIR="$1"
else
    SPECDIR="$MYDIR"
fi

# remove temporary files on exit
clean_up () {
  case "$MYNAME" in
  /tmp/continuous_build.copy.* )
        rm -f $MYNAME
        ;;
  esac
  exit
}

trap clean_up HUP INT TERM QUIT EXIT

# make a copy of this script in /tmp and execute that in order to
# avoid disasters caused by cvs update.
case "$MYNAME" in
    /tmp/continuous_build.copy.* )
        ;;
    *)
        cp $MYNAME /tmp/continuous_build.copy.$$
        chmod 755 /tmp/continuous_build.copy.$$
        cd /tmp
        exec /tmp/continuous_build.copy.$$ "$MYDIR"
        ;;
esac


fatal_error () {
  echo "ERROR: $*"
  exit 1
}

cd $SPECDIR || fatal_error "$SPECDIR not found"

N=2

while true; do

    DIR_DATE=`date +$DIR_DATE_FMT`

    if [ ! -d $NIGHTLY_DIR/$DIR_DATE ]; then
	./cron-script.sh
    fi

    RELEASE_DATE=`date +$RELEASE_DATE_FMT`

#   uninstall all pkgs left behind by a previous build
    ./build-gnome2 -q uninstall-pkgs *.spec

    cvs -q up -Pd > /dev/null 2>&1 || fatal_error "CVS update failed"

#   if the script changed during cvs update, restart with the updated script
    if ! /usr/bin/cmp -s ./continuous_build.sh $MYNAME; then
	exec ./continuous_build.sh;
    fi

    rm -f /usr/src/packages/SRPMS/* /usr/src/packages/RPMS/*/*

#   if the log directory exists, open a new one with numbered suffix
   
    if [ "x$N" = x2 ]; then
	N=1
    else
	N=2
    fi

    cp $WEBROOT/$WEBDIR/live.html $WEBROOT/$WEBDIR/live_prev.html

    rm -rf $WEBROOT/$LOGDIR.$N
    mkdir -p $WEBROOT/$LOGDIR.$N

#   start the build
    ./build-gnome2 -v --nightly --date "$RELEASE_DATE" build --target i586 *.spec \
        --logdir=$WEBROOT/$LOGDIR.$N \
        --logdir-url=http://gnome.ireland/$LOGDIR.$N \
        --mail-errors-file=MAINTAINERS \
        [email protected] \
	--prodname="G2.10/Linux" \
        --good-build-dir=/sgnome/pkgs/gnome2.10/rpms \
        --summary-log=$WEBROOT/$WEBDIR/live.html \
	--live-summary \
        --summary-title="Live Build Report `date +'%d %B %Y, %H:%M'`" \
          > /tmp/build.log.$$ 2>&1

#   the number of failed pkgs is returned
    FAILED=$?

    if [ $FAILED -gt 50 ]; then
	cat /tmp/build.log.$$ | \
	    mail -s "WARNING: G2.10/Linux build STOPPED: $FAILED pkgs failed" \
	        -R $REPLY_TO [email protected]
	rm -f /tmp/build.log.$$
	exit 1
    fi

#   remove old rpms
    echo '' | rsh $RHOST -l $RUSER "rm -rf $RPMSDIR.prev; mv $RPMSDIR $RPMSDIR.prev; mkdir -p $RPMSDIR"

#   copy new rpms
    echo '' | rcp `./build-gnome2 --nightly --date "$RELEASE_DATE" install-order \
	--full-path --target i586\
	*.spec` $RUSER@$RHOST:$RPMSDIR

#   remove old srpms
    echo '' | rsh $RHOST -l $RUSER "rm -rf $SRPMSDIR.prev; mv $SRPMSDIR $SRPMSDIR.prev; mkdir -p $SRPMSDIR"
#   copy new srpms
    echo '' | rcp /usr/src/packages/SRPMS/*.*src.rpm \
	$RUSER@$RHOST:$SRPMSDIR

#   send log by email
    cat /tmp/build.log.$$ | \
	mail -s "G2.10/Linux continuous build: $FAILED pkgs failed" \
	     -R $REPLY_TO $EMAIL_ADDR

    rm -f /tmp/build.log.$$

    if [ -f /tmp/stop-continuous-build ]; then
        rm /tmp/stop-continuous-build
        exit 0
    fi

done

exit 255