<commit_before>#!/bin/bash

set -e

function finish {
  echo "disk space at end of build:"
  df -h
}
trap finish EXIT

echo "disk space at beginning of build:"
df -h

# shellcheck source=ci/setup_cache.sh
. "$(dirname "$0")"/setup_cache.sh

read -ra BAZEL_BUILD_EXTRA_OPTIONS <<< "${BAZEL_BUILD_EXTRA_OPTIONS:-}"
read -ra BAZEL_EXTRA_TEST_OPTIONS <<< "${BAZEL_EXTRA_TEST_OPTIONS:-}"

BUILD_CONFIG="$(dirname "$(realpath "$0")")"/osx-build-config

# TODO(zuercher): remove --flaky_test_attempts when https://github.com/envoyproxy/envoy/issues/2428
# is resolved.
BAZEL_BUILD_OPTIONS=(
    "--curses=no"
    --show_task_finish
    --verbose_failures
    "--action_env=PATH=/usr/local/bin:/opt/local/bin:/usr/bin:/bin"
    "--test_output=all"
    "--flaky_test_attempts=integration@2"
    "--override_repository=envoy_build_config=${BUILD_CONFIG}"
    "${BAZEL_BUILD_EXTRA_OPTIONS[@]}"
    "${BAZEL_EXTRA_TEST_OPTIONS[@]}")

# Build envoy and run tests as separate steps so that failure output
# is somewhat more deterministic (rather than interleaving the build
# and test steps).

if [[ $# -gt 0 ]]; then
  TEST_TARGETS=$*
else
  TEST_TARGETS='//test/integration/...'
fi

if [[ "$TEST_TARGETS" == "//test/..." || "$TEST_TARGETS" == "//test/integration/..." ]]; then
  bazel build "${BAZEL_BUILD_OPTIONS[@]}" //source/exe:envoy-static
fi
bazel test "${BAZEL_BUILD_OPTIONS[@]}" "${TEST_TARGETS}"

# Additionally run macOS specific test suites
bazel test "${BAZEL_BUILD_OPTIONS[@]}" //test/common/network:apple_dns_impl_test<commit_msg>ci: limit macOS build to available CPUs (#16904)<commit_after>#!/bin/bash

set -e

function finish {
  echo "disk space at end of build:"
  df -h
}
trap finish EXIT

echo "disk space at beginning of build:"
df -h

# shellcheck source=ci/setup_cache.sh
. "$(dirname "$0")"/setup_cache.sh

read -ra BAZEL_BUILD_EXTRA_OPTIONS <<< "${BAZEL_BUILD_EXTRA_OPTIONS:-}"
read -ra BAZEL_EXTRA_TEST_OPTIONS <<< "${BAZEL_EXTRA_TEST_OPTIONS:-}"

BUILD_CONFIG="$(dirname "$(realpath "$0")")"/osx-build-config

# TODO(zuercher): remove --flaky_test_attempts when https://github.com/envoyproxy/envoy/issues/2428
# is resolved.
BAZEL_BUILD_OPTIONS=(
    "--curses=no"
    --show_task_finish
    --verbose_failures
    "--action_env=PATH=/usr/local/bin:/opt/local/bin:/usr/bin:/bin"
    "--test_output=all"
    "--flaky_test_attempts=integration@2"
    "--override_repository=envoy_build_config=${BUILD_CONFIG}"
    "${BAZEL_BUILD_EXTRA_OPTIONS[@]}"
    "${BAZEL_EXTRA_TEST_OPTIONS[@]}")

NCPU=$(sysctl -n hw.ncpu)
if [[ $NCPU -gt 0 ]]; then
    echo "limiting build to $NCPU jobs, based on CPU count"
    BAZEL_BUILD_OPTIONS+=("--jobs=$NCPU")
fi

# Build envoy and run tests as separate steps so that failure output
# is somewhat more deterministic (rather than interleaving the build
# and test steps).

if [[ $# -gt 0 ]]; then
  TEST_TARGETS=$*
else
  TEST_TARGETS='//test/integration/...'
fi

if [[ "$TEST_TARGETS" == "//test/..." || "$TEST_TARGETS" == "//test/integration/..." ]]; then
  bazel build "${BAZEL_BUILD_OPTIONS[@]}" //source/exe:envoy-static
fi
bazel test "${BAZEL_BUILD_OPTIONS[@]}" "${TEST_TARGETS}"

# Additionally run macOS specific test suites
bazel test "${BAZEL_BUILD_OPTIONS[@]}" //test/common/network:apple_dns_impl_test
{'fraction_non_alphanumeric': 0.16605279312461632, 'fraction_numerical': 0.006752608962553714, 'mean_word_length': 4.561433447098976, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4288492', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1173, 'n_words': 256}