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 |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 8 | if ! which "${bin}" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 9 | then |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 10 | echo "Please install ${bin}" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 11 | return 1 |
| 12 | fi |
| 13 | return 0 |
| 14 | } |
| 15 | |
| 16 | jenkins_get_job_config() { |
| 17 | local host="$1" |
| 18 | local job="$2" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 19 | local config |
| 20 | config="$(mktemp --suffix=.xml config.XXXXXX)" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 21 | local url="https://${host}/job/${job}/config.xml" |
| 22 | wget --output-document="${config}" "${url}" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 23 | echo "${config}" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | 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' |
| 35 | } |
| 36 | |
| 37 | : "${JENKINS_HOST:=openpower.xyz}" |
| 38 | : "${JENKINS_JOB:=openbmc-repository-ci}" |
| 39 | |
| 40 | util_ensure_available wget |
| 41 | util_ensure_available xmllint |
| 42 | util_ensure_available git |
| 43 | |
| 44 | CONFIG= |
| 45 | REPO= |
| 46 | |
| 47 | while [[ $# -gt 0 ]] |
| 48 | do |
| 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 Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 60 | echo "USAGE: DISTRO=DOCKERBASE $0 --config config.xml" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 61 | echo |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 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\)." |
Andrew Jeffery | 5331487 | 2018-04-30 11:45:30 +0930 | [diff] [blame] | 66 | exit 0 |
| 67 | ;; |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 68 | *) |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 69 | (>&2 echo Unrecognised argument \'"$1"\') |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 70 | shift |
| 71 | ;; |
| 72 | esac |
| 73 | done |
| 74 | |
| 75 | if [ -z "${CONFIG}" ] |
| 76 | then |
| 77 | CONFIG="$(jenkins_get_job_config "${JENKINS_HOST}" "${JENKINS_JOB}")" |
| 78 | fi |
| 79 | |
| 80 | export UNIT_TEST_PKG= |
| 81 | export WORKSPACE= |
| 82 | |
| 83 | git_clone_repo() { |
| 84 | local prj_package="$1" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 85 | local package |
| 86 | package="$(basename "${prj_package}")" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 87 | local workspace="$2" |
| 88 | if [ -d "${prj_package}" ] |
| 89 | then |
| 90 | git clone "${prj_package}" "${workspace}"/"${package}" |
| 91 | return |
| 92 | fi |
Andrew Geissler | 3705241 | 2022-05-20 15:28:26 -0400 | [diff] [blame] | 93 | git clone https://gerrit.openbmc.org/openbmc/"${package}" "${workspace}"/"${package}" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 94 | } |
| 95 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 96 | jenkins_get_job_repos "${CONFIG}" | while read -r GERRIT_PROJECT |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 97 | do |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 98 | UNIT_TEST_PKG=$(basename "${GERRIT_PROJECT}") |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 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}" |
| 104 | done |