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\). |
Andrew Jeffery | 5331487 | 2018-04-30 11:45:30 +0930 | [diff] [blame] | 65 | exit 0 |
| 66 | ;; |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 67 | *) |
| 68 | (>&2 echo Unrecognised argument \'$1\') |
| 69 | shift |
| 70 | ;; |
| 71 | esac |
| 72 | done |
| 73 | |
| 74 | if [ -z "${CONFIG}" ] |
| 75 | then |
| 76 | CONFIG="$(jenkins_get_job_config "${JENKINS_HOST}" "${JENKINS_JOB}")" |
| 77 | fi |
| 78 | |
| 79 | export UNIT_TEST_PKG= |
| 80 | export WORKSPACE= |
| 81 | |
| 82 | git_clone_repo() { |
| 83 | local prj_package="$1" |
| 84 | local package="$(basename "${prj_package}")" |
| 85 | local workspace="$2" |
| 86 | if [ -d "${prj_package}" ] |
| 87 | then |
| 88 | git clone "${prj_package}" "${workspace}"/"${package}" |
| 89 | return |
| 90 | fi |
| 91 | git clone https://gerrit.openbmc-project.xyz/openbmc/"${package}" "${workspace}"/"${package}" |
| 92 | } |
| 93 | |
| 94 | jenkins_get_job_repos "${CONFIG}" | while read GERRIT_PROJECT |
| 95 | do |
| 96 | UNIT_TEST_PKG=$(basename ${GERRIT_PROJECT}) |
| 97 | WORKSPACE="$(mktemp -d --tmpdir openbmc-build-scripts.XXXXXX)" |
| 98 | git clone . "${WORKSPACE}"/openbmc-build-scripts |
| 99 | git_clone_repo "${GERRIT_PROJECT}" "${WORKSPACE}" |
| 100 | ./run-unit-test-docker.sh |
| 101 | rm -rf "${WORKSPACE}" |
| 102 | done |