-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcircleci-bazel-test
More file actions
executable file
·91 lines (74 loc) · 2.55 KB
/
Copy pathcircleci-bazel-test
File metadata and controls
executable file
·91 lines (74 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
set -eux -o pipefail
# If there's no CIRCLE_PR_REPONAME, we're not in a PR, so do nothing.
if [[ -z "${CIRCLE_PR_REPONAME:-}" ]]; then
exit 0
fi
FLAVOUR=${CIRCLE_JOB//bazel-/}
REPO_NAME=$CIRCLE_PROJECT_REPONAME
REPO_DIR=$(echo "$REPO_NAME" | tr - _ | tr '[:upper:]' '[:lower:]')
BAZEL_ARGS=("$@")
if [[ "${#BAZEL_ARGS[@]}" -eq 0 ]]; then
BAZEL_ARGS=("//$REPO_DIR/...")
fi
# Show the pre-cleanup environment for debugging purposes.
env
# Only allow a few env vars to be passed through so we don't invalidate bazel
# build caches with changes in the action environment.
ALLOWED_ENV=(
PATH
HOSTNAME
TERM
HOME
NIXOS_VERSION
USER
)
readarray -t VARS < <(compgen -e)
for var in "${VARS[@]}"; do
if [[ ! " ${ALLOWED_ENV[@]} " =~ " $var " ]]; then
unset "$var"
fi
done
# Show the post-cleanup environment for debugging purposes.
env
# Find the patchelf binary.
for PATCHELF in /nix/store/*-patchelf-*/bin/patchelf; do
if [[ -x "$PATCHELF" ]]; then
break
fi
done
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
pushd /src/workspace
curl -L https://github.com/buchgr/bazel-remote/releases/download/v2.6.1/bazel-remote-2.6.1-linux-amd64 -o "$TMPDIR/bazel-remote"
# TODO(iphydf): Use bazel once the image is updated.
# bazel run @patchelf//:patchelf -- --set-interpreter /nix/store/*-glibc-*/lib64/ld-linux-x86-64.so.2 "$TMPDIR/bazel-remote"
"$PATCHELF" --set-interpreter /nix/store/*-glibc-*/lib64/ld-linux-x86-64.so.2 "$TMPDIR/bazel-remote"
chmod +x "$TMPDIR/bazel-remote"
popd
tar -C .. -xf <(curl -L "https://github.com/TokTok/toktok-stack/releases/download/nightly/$FLAVOUR.tar")
# Test whether it starts up at all.
"$TMPDIR/bazel-remote" --dir ../bazel-cache --max_size 1 --grpc_address="unix://$TMPDIR/grpc.sock" --idle_timeout 1s
# Then actually start it.
"$TMPDIR/bazel-remote" --dir ../bazel-cache --max_size 1 --grpc_address="unix://$TMPDIR/grpc.sock" >"$TMPDIR/bazel-remote.log" &
run_test() {
pushd /src/workspace
bazel test \
--remote_cache=grpc://localhost:9092 \
--remote_proxy="unix://$TMPDIR/grpc.sock" \
--config="$FLAVOUR" \
"${BAZEL_ARGS[@]}"
popd
}
# Baseline: run the tests in the toktok-stack image, before any changes.
run_test
/src/workspace/tools/inject-repo "$REPO_DIR"
# For each commit between master and the current branch, run the tests.
cd "/src/workspace/$REPO_DIR"
git remote add upstream "https://github.com/TokTok/$REPO_NAME"
git fetch upstream master
readarray -t COMMITS < <(git rev-list --reverse upstream/master..HEAD)
for commit in "${COMMITS[@]}"; do
git checkout "$commit"
run_test
done