blob: e3efd2782edbf4da3f0e8a0c4cf6a32326b21b20 [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
6BUILD_ID=$1;
7BUILD_PHID=$2;
8shift; shift;
9
10TAG=nexantic-build-${BUILD_ID}
11POD=nexantic-build-${BUILD_ID}
12
Leopold Schabel16267052019-11-06 14:43:21 +000013# We keep one Bazel build cache per working copy to avoid concurrency issues
14# (we cannot run multiple Bazel servers on a given _bazel_root)
15function getWorkingCopyID {
16 local pattern='/var/drydock/workingcopy-([0-9]+)/'
17 [[ "$(pwd)" =~ $pattern ]]
18 echo ${BASH_REMATCH[1]}
19}
20
21CACHE_VOLUME=bazel-cache-$(getWorkingCopyID)
22
Leopold Schabel052af2d2019-11-06 02:21:53 +000023# New image for each build - the Dockerfile might have changed.
24# Rely on the build step cache to avoid costly rebuilds.
25podman build -t ${TAG} build
26
27# Keep this in sync with create_container.sh:
28
29function cleanup {
30 rc=$?
31 ! podman pod rm $POD --force
32 ! podman rmi $TAG --force
33 exit $rc
34}
35
36trap cleanup EXIT
37
Leopold Schabel16267052019-11-06 14:43:21 +000038! podman volume create --opt o=nodev,exec ${CACHE_VOLUME}
Leopold Schabel052af2d2019-11-06 02:21:53 +000039
40podman pod create --name ${POD}
41
42podman run -d \
43 --pod ${POD} \
44 --ulimit nofile=262144:262144 \
45 --name=${POD}-cockroach \
46 cockroachdb/cockroach:v19.1.5 start --insecure
47
48podman run \
49 -v $(pwd):/work \
Leopold Schabel5b87d7b2019-11-06 14:56:30 +000050 -v ${CACHE_VOLUME}:/user/.cache/bazel/_bazel_root \
Leopold Schabel052af2d2019-11-06 02:21:53 +000051 --device /dev/kvm \
52 --privileged \
53 --pod ${POD} \
54 --name=${POD}-bazel \
55 ${TAG} \
Leopold Schabel383d4bb2019-11-14 22:53:58 +010056 bazel test //...
Leopold Schabel052af2d2019-11-06 02:21:53 +000057
Leopold Schabel052af2d2019-11-06 02:21:53 +000058function conduit() {
59 # Get Phabricator host from Git origin
60 local pattern='ssh://(.+?):([0-9]+)'
61 [[ "$(git remote get-url origin)" =~ $pattern ]];
62 local host=${BASH_REMATCH[1]}
63 local port=${BASH_REMATCH[2]}
64
65 ssh "$host" -p "$port" conduit $@
66}
67
68# Report build results if we made it here successfully
69conduit harbormaster.sendmessage <<EOF
70{"params": "{\"buildTargetPHID\": \"${BUILD_PHID}\", \"type\": \"pass\"}"}
71EOF