blob: fc88ee430f58a50c3f82bf3a43c4ec21f23b0306 [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 Vachuskac661c202018-08-08 14:42:10 -07009runTests=false
10useCache=false
Thomas Vachuska88d396e2018-08-08 15:00:21 -070011noBuild=false
Thomas Vachuska74329382018-08-07 14:09:11 -070012
Thomas Vachuska88d396e2018-08-08 15:00:21 -070013while getopts b:cnt?h o; do
Thomas Vachuska74329382018-08-07 14:09:11 -070014 case "$o" in
15 b) branch=$OPTARG;;
Thomas Vachuskac661c202018-08-08 14:42:10 -070016 c) useCache=true;;
Thomas Vachuska88d396e2018-08-08 15:00:21 -070017 n) noBuild=true;;
Thomas Vachuska74329382018-08-07 14:09:11 -070018 t) runTests=true;;
Thomas Vachuska88d396e2018-08-08 15:00:21 -070019 *) echo "usage: cell-build [-b branch] [-cnt] [commitHash]" >&2; exit 1;;
Thomas Vachuska74329382018-08-07 14:09:11 -070020 esac
21done
22
23let OPC=$OPTIND-1
24shift $OPC
25
Thomas Vachuskac661c202018-08-08 14:42:10 -070026! git status &>/dev/null && echo "Not in a git workspace. Exiting..." && exit $?
27
Thomas Vachuska21112ad2018-08-06 14:28:10 -070028# Check arguments and environment
Thomas Vachuska74329382018-08-07 14:09:11 -070029branch=${branch:-origin/master}
30baseCommit=${1:-$(git log | grep $branch | head -n1 | cut -d\ -f2)}
Thomas Vachuska21112ad2018-08-06 14:28:10 -070031
32# Create a patch file
Thomas Vachuska19bd0c32018-08-06 15:13:12 -070033git diff $baseCommit > /tmp/$baseCommit.patch
Thomas Vachuska21112ad2018-08-06 14:28:10 -070034
35# Copy patch file to the remote build machine
36scp /tmp/$baseCommit.patch $ONOS_USER@$OCN:/tmp
37
38ssh -t -t $ONOS_USER@$OCN "
39 source ~/.bash_aliases
40 cd \$ONOS_ROOT
41
Thomas Vachuska6be30682018-08-06 14:37:43 -070042 # Clean-up the workspace and stash away any changes.
43 git clean -f
44 git stash
45
Thomas Vachuskabf6739d2018-08-06 20:09:53 -070046 # Make sure the remote build machine is on the same commit hash as the local one
47 remoteCommit=\$(git log -n 1 | head -n1 | cut -d\ -f2)
Thomas Vachuska21112ad2018-08-06 14:28:10 -070048 if [ "\$remoteCommit" != "$baseCommit" ]; then
49 git checkout master
Thomas Vachuskac661c202018-08-08 14:42:10 -070050 git pull --no-stat
Thomas Vachuska21112ad2018-08-06 14:28:10 -070051 git checkout $baseCommit
52 fi
53
Thomas Vachuskabf6739d2018-08-06 20:09:53 -070054 # Apply the patch if necessary
55 [ -s /tmp/$baseCommit.patch ] && git apply /tmp/$baseCommit.patch
Thomas Vachuska21112ad2018-08-06 14:28:10 -070056
Thomas Vachuskac661c202018-08-08 14:42:10 -070057 # Promote the common bazelrc file to enable running against the cells cache
58 [ $useCache = true ] && cp ~/.bazelrc .bazelrc
59
Thomas Vachuska19bd0c32018-08-06 15:13:12 -070060 # Run the build (neutralizing known environment mutations in SSH sessions)
Thomas Vachuska74329382018-08-07 14:09:11 -070061 set -e
Thomas Vachuska88d396e2018-08-08 15:00:21 -070062 [ $noBuild = false ] && SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 bazel build onos
63 [ $runTests = true ] && bazel query 'tests(//...)' | SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 xargs bazel test
Thomas Vachuska21112ad2018-08-06 14:28:10 -070064"