Skip to content

Commit

Permalink
Merge pull request #209 from jesseshieh/js/version-error
Browse files Browse the repository at this point in the history
Friendly error message for unsupported or incorrectly formatted elixir
  • Loading branch information
jesseshieh authored Aug 25, 2021
2 parents 85352c1 + 3dbc976 commit 42e1f8d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions elixir_buildpack.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
erlang_version=20.1
elixir_version=1.5.3
always_rebuild=false
runtime_path=/app
release=false
27 changes: 26 additions & 1 deletion lib/canonical_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
8 changes: 6 additions & 2 deletions lib/misc_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 42e1f8d

Please sign in to comment.