@@ -53,9 +53,27 @@ _select-buildpack() {
53
53
unprivileged " $buildpack /bin/detect" " $build_path " & > /dev/null && valid_buildpacks+=(" $buildpack " )
54
54
done
55
55
if [[ ${# valid_buildpacks[@]} -gt 1 ]]; then
56
- title " Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used."
57
- # shellcheck disable=SC2001
58
- echo " Detected buildpacks: $( sed -e " s:/tmp/buildpacks/[0-9][0-9]_buildpack-::g" <<< " ${valid_buildpacks[@]}" ) " | indent
56
+ if [[ " ${BUILDPACK_DETECT_OUTPUT} " == " json" ]]; then
57
+ buildpack_list=" ["
58
+ for bp in " ${valid_buildpacks[@]} " ; do
59
+ # Strip leading number and "buildpack-" prefix
60
+ buildpack_id=$( basename " $bp " )
61
+ buildpack_id=" ${buildpack_id#* _buildpack-} "
62
+ buildpack_name=$( unprivileged " $bp /bin/detect" " $build_path " )
63
+ buildpack_list+=" {\" name\" : \" $buildpack_name \" , \" id\" : \" $buildpack_id \" },"
64
+ done
65
+ buildpack_list=" ${buildpack_list% ,} ]"
66
+
67
+ jq -n \
68
+ --arg message " Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used." \
69
+ --argjson buildpacks " $buildpack_list " \
70
+ ' {message: $message, buildpacks: $buildpacks}'
71
+ exit 0
72
+ else
73
+ title " Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used."
74
+ # shellcheck disable=SC2001
75
+ echo " Detected buildpacks: $( sed -e " s:/tmp/buildpacks/[0-9][0-9]_buildpack-::g" <<< " ${valid_buildpacks[@]}" ) " | indent
76
+ fi
59
77
fi
60
78
if [[ ${# valid_buildpacks[@]} -gt 0 ]]; then
61
79
selected_path=" ${valid_buildpacks[0]} "
0 commit comments