blob: 3e35eb7fe5be4d2c2016cf0b35f0d1b13b6bb405 [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
9# Check arguments and environment
10baseCommit=${1:-$(git log | grep origin/master | head -n1 | cut -d\ -f2)}
11
12# Create a patch file
Thomas Vachuska19bd0c32018-08-06 15:13:12 -070013git diff $baseCommit > /tmp/$baseCommit.patch
Thomas Vachuska21112ad2018-08-06 14:28:10 -070014
15# Copy patch file to the remote build machine
16scp /tmp/$baseCommit.patch $ONOS_USER@$OCN:/tmp
17
18ssh -t -t $ONOS_USER@$OCN "
19 source ~/.bash_aliases
20 cd \$ONOS_ROOT
21
22 # Make sure the remote build machine is on the same commit hash as the local one
23 remoteCommit=\$(git log -n 1 | head -n1 | cut -d\ -f2)
24
Thomas Vachuska6be30682018-08-06 14:37:43 -070025 # Clean-up the workspace and stash away any changes.
26 git clean -f
27 git stash
28
Thomas Vachuska21112ad2018-08-06 14:28:10 -070029 if [ "\$remoteCommit" != "$baseCommit" ]; then
30 git checkout master
31 git pull
32 git checkout $baseCommit
33 fi
34
35 # Apply the patch
Thomas Vachuska19bd0c32018-08-06 15:13:12 -070036 git apply /tmp/$baseCommit.patch
Thomas Vachuska21112ad2018-08-06 14:28:10 -070037
Thomas Vachuska19bd0c32018-08-06 15:13:12 -070038 # Run the build (neutralizing known environment mutations in SSH sessions)
Thomas Vachuska6be30682018-08-06 14:37:43 -070039 SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 bazel build onos
Thomas Vachuska21112ad2018-08-06 14:28:10 -070040"