refactor(build): Get rebar3 version from escript header comments

The command rebar3 --version loads rebar config and prints logs
This commit is contained in:
Zaiming Shi 2020-11-30 19:48:31 +01:00
parent 4e755d80db
commit cafa547996
1 changed files with 5 additions and 1 deletions

View File

@ -5,12 +5,16 @@ set -euo pipefail
VERSION="$1" VERSION="$1"
DOWNLOAD_URL='https://github.com/emqx/rebar3/releases/download' DOWNLOAD_URL='https://github.com/emqx/rebar3/releases/download'
download() { download() {
curl -L "${DOWNLOAD_URL}/${VERSION}/rebar3" -o ./rebar3 curl -L "${DOWNLOAD_URL}/${VERSION}/rebar3" -o ./rebar3
} }
# get the version number from the second line of the escript
# because command `rebar3 -v` tries to load rebar.config
# which is slow and may print some logs
version() { version() {
./rebar3 -v | grep -v '===' | grep 'rebar.*Erlang' | awk '{print $2}' head -n 2 ./rebar3 | tail -n 1 | tr ' ' '\n' | grep -E '^.+-emqx-.+'
} }
if [ -f 'rebar3' ] && [ "$(version)" == "$VERSION" ]; then if [ -f 'rebar3' ] && [ "$(version)" == "$VERSION" ]; then