From ee848f2bca1a61ce3baaa0a2bb565796f5f0f0a9 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Sat, 29 Mar 2025 03:21:39 +0200 Subject: [PATCH 01/11] use --no-header flag only in latest asdf API (go builds) v-dev builds are seen as latest (> 0.16.0) --- bin/latest-stable | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index 2eb67b5..5a61c77 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -12,7 +12,12 @@ ASDF_ELIXIR_LATEST_VERSION=$(./list-all | tr " " "\n" | grep -Ev "^0|^main|^mast # gets current erlang version without headers # changes spaces to new line # takes second line (Name Version Source Installed) -ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p) +if printf '0.16.0\n%s\n' $ASDF_VERSION | sort -CV; then + # use --no-header flag only in latest asdf API (go builds) + ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p) +else + ASDF_ELIXIR_LATEST_OTP=$(asdf current erlang | tr -s " ." "\n" | sed -n 2p) +fi # Note: asdf latest does not allows latest stable version to start with number # therefore installing from source by git ref is not supported, see: From 83902f9d7bb0ce43b011e5793dcca080791f0579 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Sat, 29 Mar 2025 03:33:04 +0200 Subject: [PATCH 02/11] Use double quotes to fix CI check --- bin/latest-stable | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index 5a61c77..cda50d3 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -12,7 +12,7 @@ ASDF_ELIXIR_LATEST_VERSION=$(./list-all | tr " " "\n" | grep -Ev "^0|^main|^mast # gets current erlang version without headers # changes spaces to new line # takes second line (Name Version Source Installed) -if printf '0.16.0\n%s\n' $ASDF_VERSION | sort -CV; then +if printf "0.16.0\n%s\n" `asdf version` | sort -CV; then # use --no-header flag only in latest asdf API (go builds) ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p) else From 9d8589e3fa719604501ad6776e4c44885a085935 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Sat, 29 Mar 2025 03:34:48 +0200 Subject: [PATCH 03/11] =?UTF-8?q?Use=20$(=E2=80=A6)=20notation=20instead?= =?UTF-8?q?=20of=20backticks=20to=20fix=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/latest-stable | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index cda50d3..dda451c 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -12,7 +12,7 @@ ASDF_ELIXIR_LATEST_VERSION=$(./list-all | tr " " "\n" | grep -Ev "^0|^main|^mast # gets current erlang version without headers # changes spaces to new line # takes second line (Name Version Source Installed) -if printf "0.16.0\n%s\n" `asdf version` | sort -CV; then +if printf "0.16.0\n%s\n" $(asdf version) | sort -CV; then # use --no-header flag only in latest asdf API (go builds) ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p) else From e5cd03c68bca21f0044e4cbfd376677a7c812251 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Sat, 29 Mar 2025 03:36:28 +0200 Subject: [PATCH 04/11] =?UTF-8?q?Wrap=20$(=E2=80=A6)=20with=20double=20quo?= =?UTF-8?q?tes=20to=20fix=20CI=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/latest-stable | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index dda451c..042bcf3 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -12,7 +12,7 @@ ASDF_ELIXIR_LATEST_VERSION=$(./list-all | tr " " "\n" | grep -Ev "^0|^main|^mast # gets current erlang version without headers # changes spaces to new line # takes second line (Name Version Source Installed) -if printf "0.16.0\n%s\n" $(asdf version) | sort -CV; then +if printf "0.16.0\n%s\n" "$(asdf version)" | sort -CV; then # use --no-header flag only in latest asdf API (go builds) ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p) else From b329da954f33e4464754191cc52a92f9b3001b2c Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Sat, 29 Mar 2025 14:09:56 +0200 Subject: [PATCH 05/11] Removes v prefix from the asdf version command output This should fix issue with versions like `v0.15.0-31e8c93` while still working for `v-dev` as `-dev` is still seen as the newer than `0.16.0` version. --- bin/latest-stable | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index 042bcf3..ddb4431 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -9,10 +9,11 @@ # finally take last one ASDF_ELIXIR_LATEST_VERSION=$(./list-all | tr " " "\n" | grep -Ev "^0|^main|^master|otp|rc|^$" | tail -n 1) +ASDF_VERSION="$(asdf version)" # gets current erlang version without headers # changes spaces to new line # takes second line (Name Version Source Installed) -if printf "0.16.0\n%s\n" "$(asdf version)" | sort -CV; then +if printf "0.16.0\n%s\n" "${ASDF_VERSION#v}" | sort -CV; then # use --no-header flag only in latest asdf API (go builds) ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p) else From 6d0265d0ff62de71cbfc5a68580e7748b7e5cf64 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Wed, 16 Apr 2025 14:36:17 +0300 Subject: [PATCH 06/11] Replace sort -V usage I've created a function which checks if the version is greater than or equal to the version where API have changed (1.16.0) Based on the @Stratus3D comment I have also replaced the echo command with a printf. Finally I made a small cleanup by ensuring that all variables start with "ASDF_ELIXIR_" prefix and removed a duplicated code for getting major version number for Erlang version --- bin/latest-stable | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/bin/latest-stable b/bin/latest-stable index ddb4431..18a601e 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -1,5 +1,29 @@ #!/usr/bin/env bash +version_gte_api_change() { + # Split the versions by dot character into arrays + IFS='.' read -r -a input_version_array <<< "$1" + IFS='.' read -r -a api_change_version_array <<< "1.16.0" + + # Support for 3 numbers in semantic versioning + for i in {0..2}; do + # suport for shorter versions by padding with 0 + [[ -z ${input_version_array[i]} ]] && input_version_array[i]=0 + + if (( input_version_array[i] > api_change_version_array[i] )); then + # input version is higher + return 0 + elif (( input_version_array[i] < api_change_version_array[i] )); then + # input version is lower + return 1 + fi + # else next loop + done + + # versions are equal + return 0 +} + # calling a script to list all elixir releases # reject releases before 1.0.0 (starting with 0) # reject main and master branches @@ -9,18 +33,16 @@ # finally take last one ASDF_ELIXIR_LATEST_VERSION=$(./list-all | tr " " "\n" | grep -Ev "^0|^main|^master|otp|rc|^$" | tail -n 1) -ASDF_VERSION="$(asdf version)" -# gets current erlang version without headers -# changes spaces to new line -# takes second line (Name Version Source Installed) -if printf "0.16.0\n%s\n" "${ASDF_VERSION#v}" | sort -CV; then +# support for v-dev and different asdf API versions +ASDF_ELIXIR_ASDF_VERSION="$(asdf version)" +if [ "$ASDF_ELIXIR_ASDF_VERSION" = "v-dev" ] || version_gte_api_change "${ASDF_ELIXIR_ASDF_VERSION#v}"; then # use --no-header flag only in latest asdf API (go builds) - ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p) + ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang) else - ASDF_ELIXIR_LATEST_OTP=$(asdf current erlang | tr -s " ." "\n" | sed -n 2p) + ASDF_ELIXIR_LATEST_OTP=$(asdf current erlang) fi # Note: asdf latest does not allows latest stable version to start with number # therefore installing from source by git ref is not supported, see: # https://github.com/asdf-vm/asdf/blob/v0.16.5/internal/versions/versions.go#L276 -echo "$ASDF_ELIXIR_LATEST_VERSION-otp-$ASDF_ELIXIR_LATEST_OTP" +printf "$ASDF_ELIXIR_LATEST_VERSION-otp-%s\n" `printf "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p` From ae32786a1d4f418ec9360ddfbe51557f5c07af9f Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Wed, 16 Apr 2025 14:42:18 +0300 Subject: [PATCH 07/11] Apply suggestions from the format check --- bin/latest-stable | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/latest-stable b/bin/latest-stable index 826b084..738e96e 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -2,18 +2,18 @@ version_gte_api_change() { # Split the versions by dot character into arrays - IFS='.' read -r -a input_version_array <<< "$1" - IFS='.' read -r -a api_change_version_array <<< "1.16.0" + IFS='.' read -r -a input_version_array <<<"$1" + IFS='.' read -r -a api_change_version_array <<<"1.16.0" # Support for 3 numbers in semantic versioning for i in {0..2}; do # suport for shorter versions by padding with 0 [[ -z ${input_version_array[i]} ]] && input_version_array[i]=0 - if (( input_version_array[i] > api_change_version_array[i] )); then + if ((input_version_array[i] > api_change_version_array[i])); then # input version is higher return 0 - elif (( input_version_array[i] < api_change_version_array[i] )); then + elif ((input_version_array[i] < api_change_version_array[i])); then # input version is lower return 1 fi @@ -48,4 +48,4 @@ fi # Note: asdf latest does not allows latest stable version to start with number # therefore installing from source by git ref is not supported, see: # https://github.com/asdf-vm/asdf/blob/v0.16.5/internal/versions/versions.go#L276 -printf "$ASDF_ELIXIR_LATEST_VERSION-otp-%s\n" `printf "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p` +printf "$ASDF_ELIXIR_LATEST_VERSION-otp-%s\n" $(printf "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p) From ce311a063f9400db800110fa11da6c5e192df405 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Wed, 16 Apr 2025 14:45:59 +0300 Subject: [PATCH 08/11] Apply suggestions from lint check --- bin/latest-stable | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index 738e96e..c6458e7 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -48,4 +48,4 @@ fi # Note: asdf latest does not allows latest stable version to start with number # therefore installing from source by git ref is not supported, see: # https://github.com/asdf-vm/asdf/blob/v0.16.5/internal/versions/versions.go#L276 -printf "$ASDF_ELIXIR_LATEST_VERSION-otp-%s\n" $(printf "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p) +printf "$ASDF_ELIXIR_LATEST_VERSION-otp-%s\n" "$(printf "%s" "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p)" From 2f0bd9c799e86c313b1c292d1e57af8654a852f6 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Wed, 16 Apr 2025 15:01:27 +0300 Subject: [PATCH 09/11] Quick test if apt-get update fix failing workflow An attempt to fix 404 error messages when fetching packages --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f5ddc63..05af8ac 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,7 +29,7 @@ jobs: steps: - name: Install system packages on Ubuntu if: ${{ runner.os == 'Linux' }} - run: sudo apt-get install curl erlang + run: sudo apt-get update && sudo apt-get install curl erlang - name: Install system packages on macOS if: ${{ runner.os == 'macOS' }} From 4ca758d2e6ab5b1169923bf6661c1e09bce26fd9 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Wed, 16 Apr 2025 17:53:18 +0300 Subject: [PATCH 10/11] Move variable to standalone printf command argument --- bin/latest-stable | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index c6458e7..47329b3 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -48,4 +48,4 @@ fi # Note: asdf latest does not allows latest stable version to start with number # therefore installing from source by git ref is not supported, see: # https://github.com/asdf-vm/asdf/blob/v0.16.5/internal/versions/versions.go#L276 -printf "$ASDF_ELIXIR_LATEST_VERSION-otp-%s\n" "$(printf "%s" "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p)" +printf "%s-otp-%s\n" "$ASDF_ELIXIR_LATEST_VERSION" "$(printf "%s" "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p)" From a02efd0c8570a69d3a0e0afce8b25660a9887c17 Mon Sep 17 00:00:00 2001 From: Tomasz Marek Sulima Date: Wed, 16 Apr 2025 17:55:43 +0300 Subject: [PATCH 11/11] Fix incorrect value of the version API changed from 1.16.0 to 0.16.0 --- bin/latest-stable | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/latest-stable b/bin/latest-stable index 47329b3..7ac46d5 100755 --- a/bin/latest-stable +++ b/bin/latest-stable @@ -3,7 +3,7 @@ version_gte_api_change() { # Split the versions by dot character into arrays IFS='.' read -r -a input_version_array <<<"$1" - IFS='.' read -r -a api_change_version_array <<<"1.16.0" + IFS='.' read -r -a api_change_version_array <<<"0.16.0" # Support for 3 numbers in semantic versioning for i in {0..2}; do