blob: 85b4467a523ac55f45832aeb76d5d8f535fbcf8a [file] [log] [blame]
Thomas Vachuska21112ad2018-08-06 14:28:10 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Tool to perform a cell-based remote bazel build using a borrowed test cell.
4# -----------------------------------------------------------------------------
5
6# Check environment
7[ -z "$OCN" ] && echo "Cell environment not established" && exit 1
8
Thomas Vachuska74329382018-08-07 14:09:11 -07009runTests=""
10
11while getopts b:t?h o; do
12 case "$o" in
13 b) branch=$OPTARG;;
14 t) runTests=true;;
15 *) echo "usage: cell-build [-b branch] [-t] [commitHash]" >&2; exit 1;;
16 esac
17done
18
19let OPC=$OPTIND-1
20shift $OPC
21
Thomas Vachuska21112ad2018-08-06 14:28:10 -070022# Check arguments and environment
Thomas Vachuska74329382018-08-07 14:09:11 -070023branch=${branch:-origin/master}
24baseCommit=${1:-$(git log | grep $branch | head -n1 | cut -d\ -f2)}
Thomas Vachuska21112ad2018-08-06 14:28:10 -070025
26# Create a patch file
Thomas Vachuska19bd0c32018-08-06 15:13:12 -070027git diff $baseCommit > /tmp/$baseCommit.patch
Thomas Vachuska21112ad2018-08-06 14:28:10 -070028
29# Copy patch file to the remote build machine
30scp /tmp/$baseCommit.patch $ONOS_USER@$OCN:/tmp
31
32ssh -t -t $ONOS_USER@$OCN "
33 source ~/.bash_aliases
34 cd \$ONOS_ROOT
35
Thomas Vachuska6be30682018-08-06 14:37:43 -070036 # Clean-up the workspace and stash away any changes.
37 git clean -f
38 git stash
39
Thomas Vachuskabf6739d2018-08-06 20:09:53 -070040 # Make sure the remote build machine is on the same commit hash as the local one
41 remoteCommit=\$(git log -n 1 | head -n1 | cut -d\ -f2)
Thomas Vachuska21112ad2018-08-06 14:28:10 -070042 if [ "\$remoteCommit" != "$baseCommit" ]; then
43 git checkout master
44 git pull
45 git checkout $baseCommit
46 fi
47
Thomas Vachuskabf6739d2018-08-06 20:09:53 -070048 # Apply the patch if necessary
49 [ -s /tmp/$baseCommit.patch ] && git apply /tmp/$baseCommit.patch
Thomas Vachuska21112ad2018-08-06 14:28:10 -070050
Thomas Vachuska19bd0c32018-08-06 15:13:12 -070051 # Run the build (neutralizing known environment mutations in SSH sessions)
Thomas Vachuska74329382018-08-07 14:09:11 -070052 set -e
Thomas Vachuska6be30682018-08-06 14:37:43 -070053 SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 bazel build onos
Thomas Vachuska74329382018-08-07 14:09:11 -070054 if [ $runTests = true ]; then
55 bazel query 'tests(//...)' | SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 xargs bazel test
56 fi
Thomas Vachuska21112ad2018-08-06 14:28:10 -070057"