blob: c6a5f2133d3630b122d8905dbbc937819b983472 [file] [log] [blame]
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +10301#!/bin/bash
2
3set -eou pipefail
4set -x
5
6util_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
16jenkins_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
25jenkins_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
39util_ensure_available wget
40util_ensure_available xmllint
41util_ensure_available git
42
43CONFIG=
44REPO=
45
46while [[ $# -gt 0 ]]
47do
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
71done
72
73if [ -z "${CONFIG}" ]
74then
75 CONFIG="$(jenkins_get_job_config "${JENKINS_HOST}" "${JENKINS_JOB}")"
76fi
77
78export UNIT_TEST_PKG=
79export WORKSPACE=
80
81git_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
93jenkins_get_job_repos "${CONFIG}" | while read GERRIT_PROJECT
94do
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}"
101done