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