From 3dbc97629841c87f17443abe444b7020ec429f92 Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 25 Aug 2021 10:52:31 -0400 Subject: [PATCH] Friendly error message for unsupported or incorrectly formatted elixir versions. Require config file now that elixir and erlang versions are required to be explicit. Fix elixir version required check. Remove default elixir and erlang versions now that they are required. Better formatting so it is clear if the version is empty. --- bin/compile | 1 + elixir_buildpack.config | 2 -- lib/canonical_version.sh | 27 ++++++++++++++++++++++++++- lib/misc_funcs.sh | 8 ++++++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/bin/compile b/bin/compile index 9eef6930..221003d8 100755 --- a/bin/compile +++ b/bin/compile @@ -33,6 +33,7 @@ export_mix_home export_hex_home load_config check_erlang_version "$erlang_version" +check_elixir_version "$elixir_version" check_stack clean_cache diff --git a/elixir_buildpack.config b/elixir_buildpack.config index 47df718d..01da48ab 100644 --- a/elixir_buildpack.config +++ b/elixir_buildpack.config @@ -1,5 +1,3 @@ -erlang_version=20.1 -elixir_version=1.5.3 always_rebuild=false runtime_path=/app release=false diff --git a/lib/canonical_version.sh b/lib/canonical_version.sh index 7e9f254f..ad069396 100755 --- a/lib/canonical_version.sh +++ b/lib/canonical_version.sh @@ -9,6 +9,11 @@ erlang_builds_url() { echo $erlang_builds_url } +fetch_elixir_versions() { + url="https://repo.hex.pm/builds/elixir/builds.txt" + curl -s "$url" | awk '/^v[0-9.]+[- ]/ { print $1 }' +} + fetch_erlang_versions() { if [ "$STACK" = "heroku-20" ]; then url="https://repo.hex.pm/builds/otp/ubuntu-20.04/builds.txt" @@ -32,12 +37,32 @@ exact_erlang_version_available() { echo $found } +exact_elixir_version_available() { + version=$1 + available_versions=$2 + found=1 + while read -r line; do + if [ "$line" = "$version" ]; then + found=0 + fi + done <<< "$available_versions" + echo $found +} + check_erlang_version() { version=$1 exists=$(exact_erlang_version_available "$version" "$(fetch_erlang_versions)") if [ $exists -ne 0 ]; then - output_line "Sorry, Erlang $version isn't supported yet. For a list of supported versions, please see https://github.com/HashNuke/heroku-buildpack-elixir#version-support" + output_line "Sorry, Erlang '$version' isn't supported yet or isn't formatted correctly. For a list of supported versions, please see https://github.com/HashNuke/heroku-buildpack-elixir#version-support" exit 1 fi } +check_elixir_version() { + version=$1 + exists=$(exact_elixir_version_available "$version" "$(fetch_elixir_versions)") + if [ $exists -ne 0 ]; then + output_line "Sorry, Elixir '$version' isn't supported yet or isn't formatted correctly. For a list of supported versions, please see https://github.com/HashNuke/heroku-buildpack-elixir#version-support" + exit 1 + fi +} diff --git a/lib/misc_funcs.sh b/lib/misc_funcs.sh index 122ebffb..2e5f95ce 100644 --- a/lib/misc_funcs.sh +++ b/lib/misc_funcs.sh @@ -38,7 +38,11 @@ function assert_elixir_version_set() { # 0 when found # 1 when not found # 2 when file does not exist + + set +e + # this command is allowed to return a non-zero exit code since that is how we check if the elixir version is set. grep -q -e "^elixir_version=" $custom_config_file 2>/dev/null + set -e if [ $? -ne 0 ]; then # For now, just print a warning. In the future, we will fail and require an explicit @@ -61,8 +65,8 @@ function load_config() { then source $custom_config_file else - output_line "WARNING: elixir_buildpack.config wasn't found in the app" - output_line "Using default config from Elixir buildpack" + output_line "Sorry, an elixir_buildpack.config is required. Please see https://github.com/HashNuke/heroku-buildpack-elixir#configuration" + exit 1 fi assert_elixir_version_set $custom_config_file