Skip to content

Commit 5901eba

Browse files
committed
✨ Update plugin.bash, change hook type
1 parent 9b3c1ae commit 5901eba

3 files changed

Lines changed: 67 additions & 23 deletions

File tree

hooks/command

Lines changed: 0 additions & 21 deletions
This file was deleted.

hooks/post-command

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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}"

lib/plugin.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
PLUGIN_PREFIX="YOUR_PLUGIN_NAME"
4+
PLUGIN_PREFIX="BAZEL_BEP_ANNOTATOR"
55

66
# Reads either a value or a list from the given env prefix
77
function prefix_read_list() {
@@ -59,4 +59,4 @@ function plugin_read_config() {
5959
local var="BUILDKITE_PLUGIN_${PLUGIN_PREFIX}_${1}"
6060
local default="${2:-}"
6161
echo "${!var:-$default}"
62-
}
62+
}

0 commit comments

Comments
 (0)