Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -eou pipefail |
| 4 | set -x |
| 5 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 6 | function util_ensure_available() { |
| 7 | local bin=$1 |
| 8 | if ! which "${bin}" |
| 9 | then |
| 10 | echo "Please install ${bin}" |
| 11 | return 1 |
| 12 | fi |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 13 | return 0 |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | function 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 | |
| 26 | function 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 Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 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 |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 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) |
| 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 Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 73 | done |
| 74 | |
| 75 | if [ -z "${CONFIG}" ] |
| 76 | then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 77 | CONFIG="$(jenkins_get_job_config "${JENKINS_HOST}" "${JENKINS_JOB}")" |
Andrew Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 78 | fi |
| 79 | |
| 80 | export UNIT_TEST_PKG= |
| 81 | export WORKSPACE= |
| 82 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 83 | function 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 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 | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 98 | 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 Jeffery | 4e5c1ca | 2018-03-08 13:48:04 +1030 | [diff] [blame] | 104 | done |