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 | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 9 | runTests=false |
| 10 | useCache=false |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame] | 11 | |
Thomas Vachuska | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 12 | while getopts b:ct?h o; do |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame] | 13 | case "$o" in |
| 14 | b) branch=$OPTARG;; |
Thomas Vachuska | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 15 | c) useCache=true;; |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame] | 16 | t) runTests=true;; |
Thomas Vachuska | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 17 | *) echo "usage: cell-build [-b branch] [-ct] [commitHash]" >&2; exit 1;; |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame] | 18 | esac |
| 19 | done |
| 20 | |
| 21 | let OPC=$OPTIND-1 |
| 22 | shift $OPC |
| 23 | |
Thomas Vachuska | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 24 | ! git status &>/dev/null && echo "Not in a git workspace. Exiting..." && exit $? |
| 25 | |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 26 | # Check arguments and environment |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame] | 27 | branch=${branch:-origin/master} |
| 28 | baseCommit=${1:-$(git log | grep $branch | head -n1 | cut -d\ -f2)} |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 29 | |
| 30 | # Create a patch file |
Thomas Vachuska | 19bd0c3 | 2018-08-06 15:13:12 -0700 | [diff] [blame] | 31 | git diff $baseCommit > /tmp/$baseCommit.patch |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 32 | |
| 33 | # Copy patch file to the remote build machine |
| 34 | scp /tmp/$baseCommit.patch $ONOS_USER@$OCN:/tmp |
| 35 | |
| 36 | ssh -t -t $ONOS_USER@$OCN " |
| 37 | source ~/.bash_aliases |
| 38 | cd \$ONOS_ROOT |
| 39 | |
Thomas Vachuska | 6be3068 | 2018-08-06 14:37:43 -0700 | [diff] [blame] | 40 | # Clean-up the workspace and stash away any changes. |
| 41 | git clean -f |
| 42 | git stash |
| 43 | |
Thomas Vachuska | bf6739d | 2018-08-06 20:09:53 -0700 | [diff] [blame] | 44 | # 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 Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 46 | if [ "\$remoteCommit" != "$baseCommit" ]; then |
| 47 | git checkout master |
Thomas Vachuska | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 48 | git pull --no-stat |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 49 | git checkout $baseCommit |
| 50 | fi |
| 51 | |
Thomas Vachuska | bf6739d | 2018-08-06 20:09:53 -0700 | [diff] [blame] | 52 | # Apply the patch if necessary |
| 53 | [ -s /tmp/$baseCommit.patch ] && git apply /tmp/$baseCommit.patch |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 54 | |
Thomas Vachuska | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 55 | # Promote the common bazelrc file to enable running against the cells cache |
| 56 | [ $useCache = true ] && cp ~/.bazelrc .bazelrc |
| 57 | |
Thomas Vachuska | 19bd0c3 | 2018-08-06 15:13:12 -0700 | [diff] [blame] | 58 | # Run the build (neutralizing known environment mutations in SSH sessions) |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame] | 59 | set -e |
Thomas Vachuska | 6be3068 | 2018-08-06 14:37:43 -0700 | [diff] [blame] | 60 | SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 bazel build onos |
Thomas Vachuska | c661c20 | 2018-08-08 14:42:10 -0700 | [diff] [blame^] | 61 | [ $runTests = true ] && \ |
Thomas Vachuska | 7432938 | 2018-08-07 14:09:11 -0700 | [diff] [blame] | 62 | bazel query 'tests(//...)' | SHLVL=1 SSH_CLIENT=0 SSH_CONNECTION=0 xargs bazel test |
Thomas Vachuska | 21112ad | 2018-08-06 14:28:10 -0700 | [diff] [blame] | 63 | " |