Skip to content

Commit

Permalink
Merge pull request #158 from jesseshieh/master
Browse files Browse the repository at this point in the history
Friendly error message when erlang version is not supported
  • Loading branch information
HashNuke authored Oct 19, 2019
2 parents 07c23c5 + 220b59a commit f5cf427
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ We only create a new tag/release when we've made breaking changes. So consider a
* Build scripts to build erlang are at <https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds>
* Sample app to test is available at <https://github.com/HashNuke/heroku-buildpack-elixir-test>

## Testing

To run tests
```
git clone https://github.com/HashNuke/heroku-buildpack-elixir
export BUILDPACK="$(pwd)/heroku-buildpack-elixir"
git clone https://github.com/jesseshieh/heroku-buildpack-testrunner
git clone https://github.com/jesseshieh/shunit2
export SHUNIT_HOME="$(pwd)/shunit2"
cd heroku-buildpack-testrunner
bin/run $BUILDPACK
```

See more info at https://github.com/jesseshieh/heroku-buildpack-testrunner/blob/master/README.md

## Credits

Expand Down
2 changes: 2 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ source ${build_pack_path}/lib/misc_funcs.sh
source ${build_pack_path}/lib/erlang_funcs.sh
source ${build_pack_path}/lib/elixir_funcs.sh
source ${build_pack_path}/lib/app_funcs.sh
source ${build_pack_path}/lib/canonical_version.sh

mkdir $(platform_tools_path)

load_config
check_erlang_version "$erlang_version"
export_env_vars
export_mix_env

Expand Down
28 changes: 28 additions & 0 deletions lib/canonical_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

fetch_erlang_versions() {
url="https://raw.githubusercontent.com/HashNuke/heroku-buildpack-elixir-otp-builds/master/otp-versions"
curl -s "$url"
}

exact_erlang_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"
exit 1
fi
}

22 changes: 22 additions & 0 deletions test/canonical_version_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

. ${BUILDPACK_TEST_RUNNER_HOME}/lib/test_utils.sh
. ${BUILDPACK_HOME}/lib/canonical_version.sh

VERSIONS=$(fetch_erlang_versions)

testExactErlangVersionAvailable() {
assertEquals 0 $(exact_erlang_version_available "22.0.3" "$VERSIONS")
}

testExactErlangVersionUnavailable() {
assertEquals 1 $(exact_erlang_version_available "22.0.1" "$VERSIONS")
}

testExactErlangVersionMajorOnly() {
assertEquals 1 $(exact_erlang_version_available "21" "$VERSIONS")
}

testExactErlangVersionMajorMinorOnly() {
assertEquals 0 $(exact_erlang_version_available "21.0" "$VERSIONS")
}

0 comments on commit f5cf427

Please sign in to comment.