blob: a7a44bdcedc3128041adcb21aa4d5ac9437888ba [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
Patrick Williams384d7412020-11-06 16:15:41 -06008 if ! which "${bin}"
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +10309 then
Patrick Williams384d7412020-11-06 16:15:41 -060010 echo "Please install ${bin}"
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103011 return 1
12 fi
13 return 0
14}
15
16jenkins_get_job_config() {
17 local host="$1"
18 local job="$2"
Patrick Williams384d7412020-11-06 16:15:41 -060019 local config
20 config="$(mktemp --suffix=.xml config.XXXXXX)"
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103021 local url="https://${host}/job/${job}/config.xml"
22 wget --output-document="${config}" "${url}"
Patrick Williams384d7412020-11-06 16:15:41 -060023 echo "${config}"
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103024}
25
26jenkins_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'
35}
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
49 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)
Patrick Williams384d7412020-11-06 16:15:41 -060060 echo "USAGE: DISTRO=DOCKERBASE $0 --config config.xml"
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103061 echo
Patrick Williams384d7412020-11-06 16:15:41 -060062 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\)."
Andrew Jeffery53314872018-04-30 11:45:30 +093066 exit 0
67 ;;
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103068 *)
Patrick Williams384d7412020-11-06 16:15:41 -060069 (>&2 echo Unrecognised argument \'"$1"\')
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103070 shift
71 ;;
72 esac
73done
74
75if [ -z "${CONFIG}" ]
76then
77 CONFIG="$(jenkins_get_job_config "${JENKINS_HOST}" "${JENKINS_JOB}")"
78fi
79
80export UNIT_TEST_PKG=
81export WORKSPACE=
82
83git_clone_repo() {
84 local prj_package="$1"
Patrick Williams384d7412020-11-06 16:15:41 -060085 local package
86 package="$(basename "${prj_package}")"
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103087 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-project.xyz/openbmc/"${package}" "${workspace}"/"${package}"
94}
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 Williams384d7412020-11-06 16:15:41 -060098 UNIT_TEST_PKG=$(basename "${GERRIT_PROJECT}")
Andrew Jeffery4e5c1ca2018-03-08 13:48:04 +103099 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}"
104done