|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" |
| 5 | + |
| 6 | +# shellcheck source=lib/plugin.bash |
| 7 | +. "$DIR/../lib/plugin.bash" |
| 8 | +# shellcheck source=lib/bazel-bep.bash |
| 9 | +. "$DIR/../lib/bazel-bep.bash" |
| 10 | + |
| 11 | +# Get plugin configuration |
| 12 | +BEP_FILE=$(plugin_read_config BEP_FILE "") |
| 13 | +BAZEL_COMMAND=$(plugin_read_config BAZEL_COMMAND "") |
| 14 | + |
| 15 | +# Check if we should skip if no BEP file found |
| 16 | +SKIP_IF_NO_BEP=$(plugin_read_config SKIP_IF_NO_BEP "false") |
| 17 | + |
| 18 | +# Check for automatic BEP file detection based on Bazel command |
| 19 | +if [[ -z "${BEP_FILE}" && -n "${BAZEL_COMMAND}" ]]; then |
| 20 | + # Try to extract the BEP file from the command if it was specified |
| 21 | + if [[ "${BAZEL_COMMAND}" =~ --build_event_json_file=([^ ]+) ]]; then |
| 22 | + BEP_FILE="${BASH_REMATCH[1]}" |
| 23 | + echo "Detected BEP file from Bazel command: ${BEP_FILE}" |
| 24 | + else |
| 25 | + # No BEP file specified in command, need to check if skip is enabled |
| 26 | + if [[ "${SKIP_IF_NO_BEP}" == "true" ]]; then |
| 27 | + echo "No BEP file found and skip_if_no_bep is true, skipping annotation" |
| 28 | + exit 0 |
| 29 | + fi |
| 30 | + echo "Warning: No BEP file specified and couldn't detect one from Bazel command" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | +fi |
| 34 | + |
| 35 | +# If we still don't have a BEP file, check if it exists at common locations |
| 36 | +if [[ -z "${BEP_FILE}" ]]; then |
| 37 | + # Try some common locations |
| 38 | + COMMON_LOCATIONS=( |
| 39 | + "${BUILDKITE_BUILD_CHECKOUT_PATH:-$PWD}/bazel-events.json" |
| 40 | + "${BUILDKITE_BUILD_CHECKOUT_PATH:-$PWD}/bazel-bep.json" |
| 41 | + "${BUILDKITE_BUILD_CHECKOUT_PATH:-$PWD}/bep.json" |
| 42 | + ) |
| 43 | + |
| 44 | + for location in "${COMMON_LOCATIONS[@]}"; do |
| 45 | + if [[ -f "$location" ]]; then |
| 46 | + BEP_FILE="$location" |
| 47 | + echo "Found BEP file at common location: ${BEP_FILE}" |
| 48 | + break |
| 49 | + fi |
| 50 | + done |
| 51 | +fi |
| 52 | + |
| 53 | +# Exit if no BEP file found after all attempts |
| 54 | +if [[ -z "${BEP_FILE}" || ! -f "${BEP_FILE}" ]]; then |
| 55 | + if [[ "${SKIP_IF_NO_BEP}" == "true" ]]; then |
| 56 | + echo "No valid BEP file found and skip_if_no_bep is true, skipping annotation" |
| 57 | + exit 0 |
| 58 | + else |
| 59 | + echo "Error: No valid BEP file found" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +fi |
| 63 | + |
| 64 | +# Process the BEP file and create the annotation |
| 65 | +process_bep "${BEP_FILE}" "${BAZEL_COMMAND}" |
0 commit comments