blob: c95ed6ee1f02c8ea45d3f25352af94a42d4a883f [file] [log] [blame]
Leopold Schabel052af2d2019-11-06 02:21:53 +00001#!/bin/bash
Leopold Schabel383d4bb2019-11-14 22:53:58 +01002# This helper scripts executes all Bazel tests in our CI environment.
3# https://phab.monogon.dev/harbormaster/plan/2/
Leopold Schabel052af2d2019-11-06 02:21:53 +00004set -euo pipefail
5
Leopold Schabel822341a2020-02-03 21:51:47 +01006DOCKERFILE_HASH=$(sha1sum build/Dockerfile | cut -c -8)
7
Leopold Schabel052af2d2019-11-06 02:21:53 +00008BUILD_ID=$1;
9BUILD_PHID=$2;
10shift; shift;
11
Leopold Schabel822341a2020-02-03 21:51:47 +010012TAG=nexantic-version-${DOCKERFILE_HASH}
Leopold Schabel052af2d2019-11-06 02:21:53 +000013POD=nexantic-build-${BUILD_ID}
14
Leopold Schabel16267052019-11-06 14:43:21 +000015# We keep one Bazel build cache per working copy to avoid concurrency issues
16# (we cannot run multiple Bazel servers on a given _bazel_root)
17function getWorkingCopyID {
18 local pattern='/var/drydock/workingcopy-([0-9]+)/'
19 [[ "$(pwd)" =~ $pattern ]]
20 echo ${BASH_REMATCH[1]}
21}
22
23CACHE_VOLUME=bazel-cache-$(getWorkingCopyID)
24
Leopold Schabel822341a2020-02-03 21:51:47 +010025# We do our own image caching since the podman build step cache does
26# not work across different repository checkouts and is also easily
27# invalidated by multiple in-flight revisions with different Dockerfiles.
28if ! podman image inspect "$TAG" >/dev/null; then
29 echo "Could not find $TAG, building..."
30 podman build -t ${TAG} build
31fi
Leopold Schabel052af2d2019-11-06 02:21:53 +000032
33# Keep this in sync with create_container.sh:
34
35function cleanup {
36 rc=$?
37 ! podman pod rm $POD --force
Leopold Schabel052af2d2019-11-06 02:21:53 +000038 exit $rc
39}
40
41trap cleanup EXIT
42
Leopold Schabel16267052019-11-06 14:43:21 +000043! podman volume create --opt o=nodev,exec ${CACHE_VOLUME}
Leopold Schabel052af2d2019-11-06 02:21:53 +000044
45podman pod create --name ${POD}
46
47podman run -d \
48 --pod ${POD} \
49 --ulimit nofile=262144:262144 \
50 --name=${POD}-cockroach \
51 cockroachdb/cockroach:v19.1.5 start --insecure
52
53podman run \
54 -v $(pwd):/work \
Leopold Schabel5b87d7b2019-11-06 14:56:30 +000055 -v ${CACHE_VOLUME}:/user/.cache/bazel/_bazel_root \
Leopold Schabel052af2d2019-11-06 02:21:53 +000056 --device /dev/kvm \
57 --privileged \
58 --pod ${POD} \
59 --name=${POD}-bazel \
60 ${TAG} \
Leopold Schabel383d4bb2019-11-14 22:53:58 +010061 bazel test //...
Leopold Schabel052af2d2019-11-06 02:21:53 +000062
Leopold Schabel052af2d2019-11-06 02:21:53 +000063function conduit() {
64 # Get Phabricator host from Git origin
65 local pattern='ssh://(.+?):([0-9]+)'
66 [[ "$(git remote get-url origin)" =~ $pattern ]];
67 local host=${BASH_REMATCH[1]}
68 local port=${BASH_REMATCH[2]}
69
70 ssh "$host" -p "$port" conduit $@
71}
72
73# Report build results if we made it here successfully
74conduit harbormaster.sendmessage <<EOF
75{"params": "{\"buildTargetPHID\": \"${BUILD_PHID}\", \"type\": \"pass\"}"}
76EOF