blob: 17f40b8d9bf86cd58b88228f21c0d9c34192fb86 [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\).
Andrew Jeffery53314872018-04-30 11:45:30 +093065 exit 0
66 ;;
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103067 *)
68 (>&2 echo Unrecognised argument \'$1\')
69 shift
70 ;;
71 esac
72done
73
74if [ -z "${CONFIG}" ]
75then
76 CONFIG="$(jenkins_get_job_config "${JENKINS_HOST}" "${JENKINS_JOB}")"
77fi
78
79export UNIT_TEST_PKG=
80export WORKSPACE=
81
82git_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
94jenkins_get_job_repos "${CONFIG}" | while read GERRIT_PROJECT
95do
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}"
102done