diff --git a/.editorconfig b/.editorconfig index 8439b05fe..05e406bc4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,11 +7,9 @@ end_of_line = lf insert_final_newline = true charset = utf-8 trim_trailing_whitespace = true +indent_style = space +indent_size = 2 [*.go] indent_style = tab indent_size = 4 - -[contrib/post-install] -indent_size = 2 -indent_style = space diff --git a/.gitignore b/.gitignore index eff4fa885..15aef64c8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build include/cedarish.txt include/buildpacks.txt bindata.go +.idea/ diff --git a/README.md b/README.md index ae057619f..6630b5c3b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ $ herokuish Available commands: buildpack Use and install buildpacks build Build an application using installed buildpacks + detect Detect buildpack to use for an application install Install buildpack from Git URL and optional committish list List installed buildpacks test Build and run tests for an application using installed buildpacks diff --git a/include/buildpack.bash b/include/buildpack.bash index 6368085f6..01e043845 100644 --- a/include/buildpack.bash +++ b/include/buildpack.bash @@ -70,6 +70,14 @@ _select-buildpack() { fi } +buildpack-detect() { + declare desc="Detect suitable buildpack for an application" + ensure-paths + [[ "$USER" ]] || randomize-unprivileged + buildpack-setup >/dev/null + _select-buildpack +} + buildpack-build() { declare desc="Build an application using installed buildpacks" ensure-paths diff --git a/include/herokuish.bash b/include/herokuish.bash index f8bc06bdd..4e19af7c7 100644 --- a/include/herokuish.bash +++ b/include/herokuish.bash @@ -133,6 +133,7 @@ main() { cmd-export buildpack-install cmd-export buildpack-list cmd-export buildpack-test + cmd-export buildpack-detect cmd-export-ns slug "Manage application slugs" cmd-export slug-import diff --git a/tests/functional/tests.sh b/tests/functional/tests.sh index a61b2a582..18413d4ac 100644 --- a/tests/functional/tests.sh +++ b/tests/functional/tests.sh @@ -48,3 +48,48 @@ T_generate-slug() { herokuish slug generate tar tzf /tmp/slug.tgz" } + +T_buildpack-detect-default() { + herokuish-test "buildpack-detect-default" " + set -e + unset BUILDPACK_URL + export buildpack_path=/tmp/buildpacks + export build_path=/tmp/app + export unprivileged_user=\$(whoami) + export unprivileged_group=\$(id -gn) + + rm -rf \$buildpack_path && mkdir -p \$buildpack_path + + mkdir -p \$buildpack_path/00_buildpack-ruby/bin + { + echo '#!/usr/bin/env bash' + echo 'echo Ruby' + echo 'exit 0' + } > \$buildpack_path/00_buildpack-ruby/bin/detect + chmod +x \$buildpack_path/00_buildpack-ruby/bin/detect + + herokuish buildpack detect | grep 'Ruby app detected' + " +} + +T_buildpack-detect-fail() { + herokuish-test "buildpack-detect-fail" " + set -e + unset BUILDPACK_URL + export buildpack_path=/tmp/buildpacks + export build_path=/tmp/app + export unprivileged_user=\$(whoami) + export unprivileged_group=\$(id -gn) + + rm -rf \$buildpack_path && mkdir -p \$buildpack_path + + mkdir -p \$buildpack_path/00_buildpack-fail/bin + { + echo '#!/usr/bin/env bash' + echo 'exit 1' + } > \$buildpack_path/00_buildpack-fail/bin/detect + chmod +x \$buildpack_path/00_buildpack-fail/bin/detect + + herokuish buildpack detect 2>&1 | grep 'Unable to select a buildpack' + " +}