Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -eou pipefail |
| 4 | set -x |
| 5 | |
| 6 | util_ensure_available() { |
| 7 | local bin=$1 |
| 8 | if ! which ${bin} |
| 9 | then |
| 10 | echo Please install ${bin} |
| 11 | return 1 |
| 12 | fi |
| 13 | return 0 |
| 14 | } |
| 15 | |
| 16 | jenkins_get_job_config() { |
| 17 | local host="$1" |
| 18 | local job="$2" |
| 19 | local config="$(mktemp --suffix=.xml config.XXXXXX)" |
| 20 | local url="https://${host}/job/${job}/config.xml" |
| 21 | wget --output-document="${config}" "${url}" |
| 22 | echo ${config} |
| 23 | } |
| 24 | |
| 25 | jenkins_get_job_repos() { |
| 26 | local config="$1" |
| 27 | if [ -n "${REPO}" ] |
| 28 | then |
| 29 | echo "${REPO}" |
| 30 | return 0 |
| 31 | fi |
| 32 | # xmllint is rubbish, so we need sed(1) to separate the results |
| 33 | xmllint --xpath '//com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject/pattern' "${config}" | sed -e 's/<pattern>//g' -e 's/<\/pattern>/\n/g' |
| 34 | } |
| 35 | |
| 36 | : "${JENKINS_HOST:=openpower.xyz}" |
| 37 | : "${JENKINS_JOB:=openbmc-repository-ci}" |
| 38 | |
| 39 | util_ensure_available wget |
| 40 | util_ensure_available xmllint |
| 41 | util_ensure_available git |
| 42 | |
| 43 | CONFIG= |
| 44 | REPO= |
| 45 | |
| 46 | while [[ $# -gt 0 ]] |
| 47 | do |
| 48 | key="$1" |
| 49 | case "${key}" in |
| 50 | -c|--config) |
| 51 | CONFIG="$2" |
| 52 | shift 2 |
| 53 | ;; |
| 54 | -r|--repo|--repository) |
| 55 | REPO="$2" |
| 56 | shift 2 |
| 57 | ;; |
| 58 | -h|--help) |
| 59 | echo USAGE: DISTRO=DOCKERBASE $0 --config config.xml |
| 60 | echo |
| 61 | echo DOCKERBASE is the Docker Hub tag of the base image against which to |
| 62 | echo build and test the repositories described in config.xml. Individual |
| 63 | echo repositories can be tested against DOCKERBASE with the --repository |
| 64 | echo option \(in place of --config\). |
| 65 | |
| 66 | *) |
| 67 | (>&2 echo Unrecognised argument \'$1\') |
| 68 | shift |
| 69 | ;; |
| 70 | esac |
| 71 | done |
| 72 | |
| 73 | if [ -z "${CONFIG}" ] |
| 74 | then |
| 75 | CONFIG="$(jenkins_get_job_config "${JENKINS_HOST}" "${JENKINS_JOB}")" |
| 76 | fi |
| 77 | |
| 78 | export UNIT_TEST_PKG= |
| 79 | export WORKSPACE= |
| 80 | |
| 81 | git_clone_repo() { |
| 82 | local prj_package="$1" |
| 83 | local package="$(basename "${prj_package}")" |
| 84 | local workspace="$2" |
| 85 | if [ -d "${prj_package}" ] |
| 86 | then |
| 87 | git clone "${prj_package}" "${workspace}"/"${package}" |
| 88 | return |
| 89 | fi |
| 90 | git clone https://gerrit.openbmc-project.xyz/openbmc/"${package}" "${workspace}"/"${package}" |
| 91 | } |
| 92 | |
| 93 | jenkins_get_job_repos "${CONFIG}" | while read GERRIT_PROJECT |
| 94 | do |
| 95 | UNIT_TEST_PKG=$(basename ${GERRIT_PROJECT}) |
| 96 | WORKSPACE="$(mktemp -d --tmpdir openbmc-build-scripts.XXXXXX)" |
| 97 | git clone . "${WORKSPACE}"/openbmc-build-scripts |
| 98 | git_clone_repo "${GERRIT_PROJECT}" "${WORKSPACE}" |
| 99 | ./run-unit-test-docker.sh |
| 100 | rm -rf "${WORKSPACE}" |
| 101 | done |