#!/bin/bash

set -e

# check author has added themselves to CONTRIBUTORS
echo "--- Checking CONTRIBUTORS"
.buildkite/linux/check_contributors

echo "--- Building"
BAZEL="bazel --output_user_root=/state/bazel --output_base=/state/bazel/anki"
BUILDARGS="--config=ci --experimental_convenience_symlinks=ignore --disk_cache=/state/bazel/disk --repository_cache=/state/bazel/repo"

# move existing node_modules into tree
test -e /state/node_modules && mv /state/node_modules ts/

$BAZEL build $BUILDARGS ...

echo "+++ Running tests"
$BAZEL test $BUILDARGS ...

echo "--- Building wheels"
$BAZEL build dist

echo "--- Cleanup"
# if tests succeed, back up node_modules folder
mv ts/node_modules /state/
