2019-04-04 11:33:38 +03:00
|
|
|
|
#!/usr/bin/env bash
|
2022-01-03 19:36:51 +03:00
|
|
|
|
# Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
2019-07-05 14:18:12 +03:00
|
|
|
|
set -euo pipefail
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
2020-05-14 10:06:34 +03:00
|
|
|
|
eval "$("$(dirname "$0")/dev-env/bin/dade-assist")"
|
2019-04-10 15:22:35 +03:00
|
|
|
|
|
2019-04-04 11:33:38 +03:00
|
|
|
|
execution_log_postfix=${1:-}
|
|
|
|
|
|
|
|
|
|
export LC_ALL=en_US.UTF-8
|
|
|
|
|
|
2019-04-16 18:43:29 +03:00
|
|
|
|
ARTIFACT_DIRS="${BUILD_ARTIFACTSTAGINGDIRECTORY:-$PWD}"
|
2021-07-07 12:37:43 +03:00
|
|
|
|
mkdir -p "${ARTIFACT_DIRS}/logs"
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
2020-02-14 17:08:24 +03:00
|
|
|
|
tag_filter=""
|
2021-07-08 14:23:53 +03:00
|
|
|
|
if [[ "$(uname)" == "Darwin" ]]; then
|
2020-02-26 17:52:08 +03:00
|
|
|
|
tag_filter="-dont-run-on-darwin,-scaladoc,-pdfdocs"
|
2020-02-14 17:08:24 +03:00
|
|
|
|
fi
|
|
|
|
|
|
2020-07-07 21:53:23 +03:00
|
|
|
|
# Occasionally we end up with a stale sandbox process for a hardcoded
|
|
|
|
|
# port number. Not quite sure how we end up with a stale process
|
|
|
|
|
# but it happens sufficiently rarely that just killing it here is
|
|
|
|
|
# a cheaper solution than having to reset the node.
|
|
|
|
|
# Note that lsof returns a non-zero exit code if there is no match.
|
|
|
|
|
SANDBOX_PID="$(lsof -ti tcp:6865 || true)"
|
|
|
|
|
if [ -n "$SANDBOX_PID" ]; then
|
2021-03-30 22:21:42 +03:00
|
|
|
|
echo $SANDBOX_PID | xargs kill
|
2020-07-07 21:53:23 +03:00
|
|
|
|
fi
|
|
|
|
|
|
2020-05-14 10:06:34 +03:00
|
|
|
|
# Bazel test only builds targets that are dependencies of a test suite so do a full build first.
|
2021-06-11 13:16:08 +03:00
|
|
|
|
bazel build //... \
|
|
|
|
|
--build_tag_filters "$tag_filter" \
|
|
|
|
|
--profile build-profile.json \
|
|
|
|
|
--experimental_profile_include_target_label \
|
|
|
|
|
--build_event_json_file build-events.json \
|
2021-07-07 12:37:43 +03:00
|
|
|
|
--build_event_publish_all_actions \
|
2021-10-28 11:55:35 +03:00
|
|
|
|
--experimental_execution_log_file "$ARTIFACT_DIRS/logs/build_execution${execution_log_postfix}.log"
|
2020-05-14 10:06:34 +03:00
|
|
|
|
|
|
|
|
|
# Set up a shared PostgreSQL instance.
|
|
|
|
|
export POSTGRESQL_ROOT_DIR="${TMPDIR:-/tmp}/daml/postgresql"
|
|
|
|
|
export POSTGRESQL_DATA_DIR="${POSTGRESQL_ROOT_DIR}/data"
|
|
|
|
|
export POSTGRESQL_LOG_FILE="${POSTGRESQL_ROOT_DIR}/postgresql.log"
|
|
|
|
|
export POSTGRESQL_HOST='localhost'
|
|
|
|
|
export POSTGRESQL_PORT=54321
|
|
|
|
|
export POSTGRESQL_USERNAME='test'
|
|
|
|
|
export POSTGRESQL_PASSWORD=''
|
|
|
|
|
function start_postgresql() {
|
|
|
|
|
mkdir -p "$POSTGRESQL_DATA_DIR"
|
|
|
|
|
bazel run -- @postgresql_dev_env//:initdb --auth=trust --encoding=UNICODE --locale=en_US.UTF-8 --username="$POSTGRESQL_USERNAME" "$POSTGRESQL_DATA_DIR"
|
2020-05-26 13:25:54 +03:00
|
|
|
|
eval "echo \"$(cat ci/postgresql.conf)\"" > "$POSTGRESQL_DATA_DIR/postgresql.conf"
|
2020-05-14 10:06:34 +03:00
|
|
|
|
bazel run -- @postgresql_dev_env//:pg_ctl -w --pgdata="$POSTGRESQL_DATA_DIR" --log="$POSTGRESQL_LOG_FILE" start || {
|
|
|
|
|
if [[ -f "$POSTGRESQL_LOG_FILE" ]]; then
|
|
|
|
|
echo >&2 'PostgreSQL logs:'
|
|
|
|
|
cat >&2 "$POSTGRESQL_LOG_FILE"
|
|
|
|
|
fi
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function stop_postgresql() {
|
|
|
|
|
if [[ -e "$POSTGRESQL_DATA_DIR" ]]; then
|
|
|
|
|
bazel run -- @postgresql_dev_env//:pg_ctl -w --pgdata="$POSTGRESQL_DATA_DIR" --mode=immediate stop || :
|
|
|
|
|
rm -rf "$POSTGRESQL_ROOT_DIR"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
trap stop_postgresql EXIT
|
|
|
|
|
stop_postgresql # in case it's running from a previous build
|
|
|
|
|
start_postgresql
|
|
|
|
|
|
|
|
|
|
# Run the tests.
|
|
|
|
|
bazel test //... \
|
|
|
|
|
--build_tag_filters "$tag_filter" \
|
|
|
|
|
--test_tag_filters "$tag_filter" \
|
|
|
|
|
--test_env "POSTGRESQL_HOST=${POSTGRESQL_HOST}" \
|
|
|
|
|
--test_env "POSTGRESQL_PORT=${POSTGRESQL_PORT}" \
|
|
|
|
|
--test_env "POSTGRESQL_USERNAME=${POSTGRESQL_USERNAME}" \
|
|
|
|
|
--test_env "POSTGRESQL_PASSWORD=${POSTGRESQL_PASSWORD}" \
|
2021-06-11 13:16:08 +03:00
|
|
|
|
--profile test-profile.json \
|
|
|
|
|
--experimental_profile_include_target_label \
|
|
|
|
|
--build_event_json_file test-events.json \
|
|
|
|
|
--build_event_publish_all_actions \
|
2021-10-28 11:55:35 +03:00
|
|
|
|
--experimental_execution_log_file "$ARTIFACT_DIRS/logs/test_execution${execution_log_postfix}.log"
|
2020-05-14 10:06:34 +03:00
|
|
|
|
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# Make sure that Bazel query works.
|
2020-05-14 10:06:34 +03:00
|
|
|
|
bazel query 'deps(//...)' >/dev/null
|
|
|
|
|
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# Check that we can load damlc in ghci
|
2020-01-09 16:49:38 +03:00
|
|
|
|
# Disabled on darwin since it sometimes seem to hang and this only
|
|
|
|
|
# tests our dev setup rather than our code so issues are not critical.
|
|
|
|
|
if [[ "$(uname)" != "Darwin" ]]; then
|
2020-05-14 10:06:34 +03:00
|
|
|
|
da-ghci --data yes //compiler/damlc:damlc -e ':main --help'
|
2020-01-09 16:49:38 +03:00
|
|
|
|
fi
|
2020-05-14 10:06:34 +03:00
|
|
|
|
|
2022-05-12 11:53:10 +03:00
|
|
|
|
# Test that hls at least builds, we don’t run it since it
|
2021-02-01 18:30:53 +03:00
|
|
|
|
# adds 2-5 minutes to each CI run with relatively little benefit. If
|
|
|
|
|
# you want to test it manually on upgrades, run
|
2022-05-12 11:53:10 +03:00
|
|
|
|
# da-hls compiler/damlc/exe/Main.hs.
|
|
|
|
|
da-hls --help
|