Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 1 | #!/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 Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame^] | 9 | runTests="" |
| 10 | |
| 11 | while 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 |
| 17 | done |
| 18 | |
| 19 | let OPC=$OPTIND-1 |
| 20 | shift $OPC |
| 21 | |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 22 | # Check arguments and environment |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame^] | 23 | branch=${branch:-origin/master} |
| 24 | baseCommit=${1:-$(git log | grep $branch | head -n1 | cut -d\ -f2)} |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 25 | |
| 26 | # Create a patch file |
Thomas Vachuska | 19bd0c3 | 2018-08-06 15:13:12 -0700 | [diff] [blame] | 27 | git diff $baseCommit > /tmp/$baseCommit.patch |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 28 | |
| 29 | # Copy patch file to the remote build machine |
| 30 | scp /tmp/$baseCommit.patch $ONOS_USER@$OCN:/tmp |
| 31 | |
| 32 | ssh -t -t $ONOS_USER@$OCN " |
| 33 | source ~/.bash_aliases |
| 34 | cd \$ONOS_ROOT |
| 35 | |
Thomas Vachuska | 6be3068 | 2018-08-06 14:37:43 -0700 | [diff] [blame] | 36 | # Clean-up the workspace and stash away any changes. |
| 37 | git clean -f |
| 38 | git stash |
| 39 | |
Thomas Vachuska | bf6739d | 2018-08-06 20:09:53 -0700 | [diff] [blame] | 40 | # 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 Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 42 | if [ "\$remoteCommit" != "$baseCommit" ]; then |
| 43 | git checkout master |
| 44 | git pull |
| 45 | git checkout $baseCommit |
| 46 | fi |
| 47 | |
Thomas Vachuska | bf6739d | 2018-08-06 20:09:53 -0700 | [diff] [blame] | 48 | # Apply the patch if necessary |
| 49 | [ -s /tmp/$baseCommit.patch ] && git apply /tmp/$baseCommit.patch |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 50 | |
Thomas Vachuska | 19bd0c3 | 2018-08-06 15:13:12 -0700 | [diff] [blame] | 51 | # Run the build (neutralizing known environment mutations in SSH sessions) |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame^] | 52 | set -e |
Thomas Vachuska | 6be3068 | 2018-08-06 14:37:43 -0700 | [diff] [blame] | 53 | SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 bazel build onos |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame^] | 54 | if [ $runTests = true ]; then |
| 55 | bazel query 'tests(//...)' | SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 xargs bazel test |
| 56 | fi |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 57 | " |