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