Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightly builds #60

Merged
2 commits merged into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tools/princess_nightly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## PRINCESS nightly builds

To set up a nightly build:

- make a user to own the build (e.g. "barrelfish")
- create a directory called nightly/ in the home directory of that user
- give user rwx ownership over directory
- the script will look for (or create) a nightly/ dir in user's home directory
- clone Guppy repository into ~/nightly/src
- add to new user's crontab with `crontab -e` (this will run the build against
the dev branch every morning at 5am and against the master branch every morning
at 5:30):

```
0 5 * * * /home/barrelfish/nightly/src/tools/princess_nightly/nightly.sh dev
30 5 * * * /home/barrelfish/nightly/src/tools/princess_nightly/nightly.sh master
```

The way the nightly build works:

nightly.sh pulls Guppy from remote Git repository, rebuilds for x86_64 and
ARMv7, and shoots out an e-mail with the resuls. Only if a build fails with its
STDIN/STDOUT be included in the sent message.
106 changes: 106 additions & 0 deletions tools/princess_nightly/nightly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash
# nightly.sh - nightly build script for Harvard-PRINCESS project

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
MAX_BUILDS=3
RUN_DATE=`date +%Y-%m-%d-%a`
WORK_DIR=${HOME}/nightly
BUILD_DIR=${WORK_DIR}/build
BUILD=${BUILD_DIR}/nightly-$RUN_DATE
MSG_FILE=${BUILD}/nightly-log.out
GIT_REPO_URL=https://github.com/Harvard-PRINCESS/Guppy.git
GIT_REPO_DIR=${WORK_DIR}/src
GIT_BRANCH=$1

say() { echo "* $@ *"; }

gitupdate() {

# download repository if it doesn't exist
if [ ! -d "$GIT_REPO_DIR" ]; then
say 'Barrelfish repository does not exist... cloning'
pushd ${WORK_DIR} > /dev/null
git clone $GIT_REPO_URL src
popd > /dev/null
fi

# get new code
pushd $GIT_REPO_DIR > /dev/null
git fetch --all
git checkout $GIT_BRANCH
git pull origin $GIT_BRANCH
popd > /dev/null
}

# remove all but last $MAX_BUILDS builds
cleanbuilds() {
cd $BUILD_DIR
while [ `ls -td * | wc -l` -gt $MAX_BUILDS ]; do
OLDEST=`ls -td nightly-* | tail -1`
if [ -f $OLDEST ]; then
say "Removing old build directory $OLDEST"
rm -rf $OLDEST
fi
done
}

# build Barrelfish OS for various architectures
dobuild() {

pushd $BUILD > /dev/null
TMP_FILE=/tmp/nightly-$RUN_DATE.out

$GIT_REPO_DIR/hake/hake.sh -s $GIT_REPO_DIR -a armv7 -a x86_64 &> $TMP_FILE
if [ $? -ne 0 ]; then
cat $TMP_FILE
fi

make -j 5 X86_64_Full &> $TMP_FILE
if [ $? -ne 0 ]; then
cat $TMP_FILE
fi

make -j 5 PandaboardES &> $TMP_FILE
if [ $? -ne 0 ]; then
cat $TMP_FILE
fi

rm $TMP_FILE
popd > /dev/null
}

# send script result e-mail
sendmail() {
${SCRIPT_DIR}/sendmail.py -f $MSG_FILE
}

main() {

mkdir -pv $BUILD
touch $MSG_FILE

{
say 'Harvard-PRINCESS Nightly Build ' $RUN_DATE
say 'Downloading source code'
gitupdate
say 'Preparing build'
cleanbuilds
dobuild
say 'Nightly build complete'
} 2>&1 | tee -a $MSG_FILE

#TODO: remove once merged into dev/master
pushd $GIT_REPO_DIR
git checkout ahp_nightly_build
popd

sendmail

#TODO: remove once merged into dev/master
pushd $GIT_REPO_DIR
git checkout ahp_nightly_build
popd
}

main
exit 0
39 changes: 39 additions & 0 deletions tools/princess_nightly/sendmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python2.7

# sendmail.py - e-mail a file with sendmail

import argparse
import datetime
import sys

from subprocess import Popen, PIPE
from email.mime.text import MIMEText

now = datetime.datetime.strftime(datetime.datetime.now(), '%c')
from_address = 'princess-nightly@nomnomnom.seas.harvard.edu'
recipients = ",".join([
'alexanderpatel@college.harvard.edu',
'dholland@sauclovia.org',
'ming@g.harvard.edu',
'ericlu01@college.harvard.edu',
'goldstein.marik@gmail.com',
'crystaljmhu@gmail.com',
])

# get e-mail message config
parser = argparse.ArgumentParser(description='use sendmail to send a file')
parser.add_argument('-f', '--file', type=str, help='file name', required=True)

args = parser.parse_args()

# construct e-mail
fp = open(args.file, 'rb')
msg = MIMEText(fp.read())
fp.close()
msg['Subject'] = 'PRINCESS nightly build (%s)' % (now)
msg['From'] = from_address
msg['To'] = recipients

# send e-mail with sendmail
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(msg.as_string())