ci.sh (2804B)
1 #!/bin/bash 2 set -exvuo pipefail 3 4 # Use podman, fails if it isn't found in PATH 5 OCI_RUNTIME=$(which podman) 6 REPO_NAME=$(basename "${PWD}") 7 JOB_NAME="${1}" 8 JOB_CONTAINER=$((grep CONTAINER_NAME contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "localhost/${REPO_NAME}") 9 JOB_ARCH=$((grep CONTAINER_ARCH contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "${2:-amd64}") 10 CONTAINER_BUILD=$((grep CONTAINER_BUILD contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "True") 11 12 echo "${JOB_CONTAINER}" 13 14 if [ "${CONTAINER_BUILD}" = "True" ] ; then 15 "${OCI_RUNTIME}" build \ 16 --arch "${JOB_ARCH}" \ 17 -t "${JOB_CONTAINER}" \ 18 -f contrib/ci/Containerfile . 19 fi 20 21 # An Android emulator needs /dev/kvm, and a container only gets it if the host 22 # passes the device *and* the user this maps to may open it. Passed only when 23 # both hold, so a worker without KVM keeps running every other job: podman 24 # fails the run outright if asked for a device that is not there. 25 # 26 # `--group-add keep-groups` is what carries the host user's `kvm` membership 27 # into a rootless container; without it the device shows up as nobody:nogroup 28 # and is unusable even though the host user has access. 29 KVM_ARGS=() 30 if [ -r /dev/kvm ] && [ -w /dev/kvm ]; then 31 KVM_ARGS=(--device /dev/kvm --group-add keep-groups) 32 fi 33 34 mkdir -p "${PWD}/inputs" 35 mkdir -p "${PWD}/artifacts" 36 mkdir -p "${PWD}/cache/.gradle" 37 # Robolectric fetches its `android-all-instrumented` runtime -- about 380 MB 38 # across the API levels the tests pin with @Config(sdk=...) -- at *test* time, 39 # through its own Maven fetcher rather than through Gradle. /root/.gradle 40 # therefore does not cache it, and with nowhere else to keep it every run 41 # re-downloaded the lot from Maven Central until Maven Central answered 429 42 # with `retry-after: 86380`, a daily per-IP quota. Every Robolectric test 43 # then fails with 44 # 45 # Failed to fetch maven artifact org.robolectric:android-all-instrumented:... 46 # 47 # which names no HTTP status and reads like a broken dependency rather than a 48 # throttled download. A persistent local Maven repository turns that into one 49 # download per worker instead of one per run. 50 mkdir -p "${PWD}/cache/.m2" 51 52 "${OCI_RUNTIME}" run \ 53 --rm \ 54 -ti \ 55 --arch "${JOB_ARCH}" \ 56 ${KVM_ARGS[@]+"${KVM_ARGS[@]}"} \ 57 --env CI_COMMIT_REF="$(git rev-parse HEAD)" \ 58 --env PUBLISH="${PUBLISH:-1}" \ 59 --volume "${PWD}":/workdir \ 60 --volume "${PWD}/cache/.gradle":/root/.gradle \ 61 --volume "${PWD}/cache/.m2":/root/.m2 \ 62 --volume "${PWD}/inputs:/inputs:ro" \ 63 --volume "${PWD}/artifacts:/artifacts" \ 64 --workdir /workdir \ 65 --network host \ 66 "${JOB_CONTAINER}" \ 67 contrib/ci/jobs/"${JOB_NAME}"/job.sh 68 69 top_dir=$(dirname "${BASH_SOURCE[0]}") 70 71 #"${top_dir}"/build.sh