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