Skip to content

Commit faaedaa

Browse files
committed
fix: Have download:false respect binary_folder
1 parent 5075fbe commit faaedaa

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,19 @@ steps:
449449
wait: true
450450
```
451451

452-
### `download_folder` (optional)
452+
### `binary_folder` (optional)
453453

454454
Default: `BUILDKITE_PLUGINS_PATH`
455455

456-
This is the filesystem folder where the Go binary will be download to.
456+
This is the filesystem folder where the Go binary will be kept.
457457

458458
## Example
459459
```yaml
460460
steps:
461461
- label: "Triggering pipelines"
462462
plugins:
463463
- monorepo-diff#v1.8.0:
464-
download_folder: "/var/buildkite-agent"
464+
binary_folder: "/var/buildkite-agent"
465465
watch:
466466
- path: "bar-service/"
467467
config:

hooks/command

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ err() {
1717
exit 1
1818
}
1919

20-
executable_dir="${BUILDKITE_PLUGIN_MONOREPO_DIFF_DOWNLOAD_FOLDER:-${BUILDKITE_PLUGINS_PATH}}"
20+
executable_dir="${BUILDKITE_PLUGIN_MONOREPO_DIFF_BINARY_FOLDER:-${BUILDKITE_PLUGINS_PATH}}"
2121

2222
# Default to current directory if not set
2323
if [[ -z "${executable_dir}" || ${BUILDKITE_PLUGIN_MONOREPO_DIFF_BUILDKITE_PLUGIN_TEST_MODE:-false} == "true" ]]; then
@@ -34,7 +34,7 @@ if [[ ! -w "${executable_dir}" ]]; then
3434
err "Directory not writable: ${executable_dir}"
3535
fi
3636

37-
executable="${executable_dir}/monorepo-diff-buildkite-plugin"
37+
executable="${executable_dir%/}/monorepo-diff-buildkite-plugin"
3838
executable_version_file="${executable}.version"
3939

4040
check_cmd() {
@@ -204,8 +204,17 @@ download_binary_and_run() {
204204
run_preinstalled_binary() {
205205
local _executable="monorepo-diff-buildkite-plugin"
206206

207-
if ! check_cmd "$_executable"; then
208-
err "Binary '$_executable' not found in PATH. Please install it or set download: true"
207+
# Check if BINARY_FOLDER is defined and use that path
208+
if [[ -n "${BUILDKITE_PLUGIN_MONOREPO_DIFF_BINARY_FOLDER:-}" ]]; then
209+
_executable="${BUILDKITE_PLUGIN_MONOREPO_DIFF_BINARY_FOLDER%/}/${_executable}"
210+
if ! check_cmd "$_executable"; then
211+
err "Binary not found or not executable in BINARY_FOLDER: $_executable"
212+
fi
213+
else
214+
# Fall back to PATH lookup
215+
if ! check_cmd "$_executable"; then
216+
err "Binary '$_executable' not found in PATH. Please install it or set download: true"
217+
fi
209218
fi
210219

211220
${_executable} "$@"

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ configuration:
1515
type: boolean
1616
env:
1717
type: array
18-
download_folder:
18+
binary_folder:
1919
type: string
2020
notify:
2121
type: [array]

tests/command.bats

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ setup() {
99
export BUILDKITE_PLUGIN_MONOREPO_DIFF_BUILDKITE_PLUGIN_TEST_MODE=true
1010
# Set a minimal plugin config (only used by Go binary, not the bash hook's download logic)
1111
export BUILDKITE_PLUGINS='[{"monorepo-diff": {}}]'
12+
export BUILDKITE_PLUGINS_PATH='/etc/buildkite-agent/plugins'
1213

1314
# Create a mock binary in the current directory for download mode tests
1415
cat > "$PWD/monorepo-diff-buildkite-plugin" << 'MOCKBIN'
@@ -104,8 +105,8 @@ teardown() {
104105
export BUILDKITE_PLUGINS='[{"github.com/buildkite-plugins/monorepo-diff-buildkite-plugin#v1.0.0": {}}]'
105106

106107
# Remove mock binary so it actually needs to download
107-
rm -f "$PWD/monorepo-diff-buildkite-plugin"
108-
rm -f "$PWD/monorepo-diff-buildkite-plugin.version"
108+
rm -f "$BUILDKITE_PLUGINS_PATH/monorepo-diff-buildkite-plugin"
109+
rm -f "$BUILDKITE_PLUGINS_PATH/monorepo-diff-buildkite-plugin.version"
109110

110111
# Stub curl: fail twice on download, then succeed and create executable
111112
stub curl \
@@ -129,9 +130,10 @@ teardown() {
129130
export BUILDKITE_PLUGIN_MONOREPO_DIFF_BUILDKITE_PLUGIN_TEST_MODE=false
130131
# Use pinned version to skip get_latest_version API call
131132
export BUILDKITE_PLUGINS='[{"github.com/buildkite-plugins/monorepo-diff-buildkite-plugin#v1.0.0": {}}]'
132-
133+
133134
# Remove mock binary so it actually needs to download
134-
rm -f "$PWD/monorepo-diff-buildkite-plugin"
135+
rm -f "$BUILDKITE_PLUGINS_PATH/monorepo-diff-buildkite-plugin"
136+
rm -f "$BUILDKITE_PLUGINS_PATH/monorepo-diff-buildkite-plugin.version"
135137

136138
# Stub curl to always fail on download
137139
stub curl \

0 commit comments

Comments
 (0)