Zack Williams | 3403ff4 | 2019-08-13 18:30:42 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2019-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # make-test.sh - run one or more make targets |
| 18 | set -eu -o pipefail |
| 19 | |
pierventre | 65d85a2 | 2020-07-21 20:30:20 +0200 | [diff] [blame] | 20 | # performs docker login if the job defines $DOCKERHUB_USERNAME and |
| 21 | # $DOCKERHUB_PASSWORD variables |
| 22 | DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-} |
| 23 | DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-} |
| 24 | if [[ ! -z "$DOCKERHUB_USERNAME" && ! -z "$DOCKERHUB_PASSWORD" ]]; then |
| 25 | echo $DOCKERHUB_PASSWORD | docker login --username ${DOCKERHUB_USERNAME} --password-stdin |
| 26 | fi |
| 27 | |
Zack Williams | 3403ff4 | 2019-08-13 18:30:42 -0700 | [diff] [blame] | 28 | # when not running under Jenkins, use current dir as workspace, a blank project |
| 29 | # name |
| 30 | WORKSPACE=${WORKSPACE:-.} |
| 31 | GERRIT_PROJECT=${GERRIT_PROJECT:-} |
| 32 | |
| 33 | # Fixes to for golang projects to support GOPATH |
| 34 | # If $DEST_GOPATH is not an empty string: |
| 35 | # - set create GOPATH, and destination directory within in |
| 36 | # - set PATH to include $GOPATH/bin and the system go binaries |
| 37 | # - symlink from $WORKSPACE/$GERRIT_PROJECT to new location in $GOPATH |
| 38 | # - start tests in that directory |
| 39 | |
| 40 | DEST_GOPATH=${DEST_GOPATH:-} |
| 41 | if [ ! -z "$DEST_GOPATH" ]; then |
| 42 | export GOPATH=${GOPATH:-~/go} |
| 43 | mkdir -p "$GOPATH/src/$DEST_GOPATH" |
| 44 | export PATH=$PATH:/usr/lib/go-1.12/bin:/usr/local/go/bin:$GOPATH/bin |
| 45 | test_path="$GOPATH/src/$DEST_GOPATH/$GERRIT_PROJECT" |
| 46 | ln -r -s "$WORKSPACE/$GERRIT_PROJECT" "$test_path" |
| 47 | else |
| 48 | test_path="$WORKSPACE/$GERRIT_PROJECT" |
| 49 | fi |
| 50 | |
| 51 | # Use "test" as the default target, can be a space separated list |
| 52 | MAKE_TEST_TARGETS=${MAKE_TEST_TARGETS:-test} |
| 53 | |
| 54 | # Default to fail on the first test that fails |
| 55 | MAKE_TEST_KEEP_GOING=${MAKE_TEST_KEEP_GOING:-false} |
| 56 | |
| 57 | if [ ! -f "$test_path/Makefile" ]; then |
| 58 | echo "Makefile not found at $test_path!" |
| 59 | exit 1 |
| 60 | else |
| 61 | pushd "$test_path" |
| 62 | |
| 63 | # we want to split the make targets apart on spaces, so: |
| 64 | # shellcheck disable=SC2086 |
| 65 | if [ "$MAKE_TEST_KEEP_GOING" = "true" ]; then |
| 66 | make -k $MAKE_TEST_TARGETS |
| 67 | else |
| 68 | make $MAKE_TEST_TARGETS |
| 69 | fi |
| 70 | |
| 71 | popd |
| 72 | fi |
| 73 | |