Skip to content

Commit d80b925

Browse files
authored
use --no-header flag only in latest asdf API (go builds) in latest-stable script (#142)
* use --no-header flag only in latest asdf API (go builds) * Use double quotes to fix CI check * Use $(…) notation instead of backticks to fix CI * Wrap $(…) with double quotes to fix CI check * Removes v prefix from the asdf version command output * Replace sort -V usage * Quick test if apt-get update fix failing workflow * Move variable to standalone printf command argument * Fix incorrect value of the version API changed from 1.16.0 to 0.16.0
1 parent fb53c45 commit d80b925

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

Diff for: .github/workflows/workflow.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
steps:
3030
- name: Install system packages on Ubuntu
3131
if: ${{ runner.os == 'Linux' }}
32-
run: sudo apt-get install curl erlang
32+
run: sudo apt-get update && sudo apt-get install curl erlang
3333

3434
- name: Install system packages on macOS
3535
if: ${{ runner.os == 'macOS' }}

Diff for: bin/latest-stable

+35-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
#!/usr/bin/env bash
22

3+
version_gte_api_change() {
4+
# Split the versions by dot character into arrays
5+
IFS='.' read -r -a input_version_array <<<"$1"
6+
IFS='.' read -r -a api_change_version_array <<<"0.16.0"
7+
8+
# Support for 3 numbers in semantic versioning
9+
for i in {0..2}; do
10+
# suport for shorter versions by padding with 0
11+
[[ -z ${input_version_array[i]} ]] && input_version_array[i]=0
12+
13+
if ((input_version_array[i] > api_change_version_array[i])); then
14+
# input version is higher
15+
return 0
16+
elif ((input_version_array[i] < api_change_version_array[i])); then
17+
# input version is lower
18+
return 1
19+
fi
20+
# else next loop
21+
done
22+
23+
# versions are equal
24+
return 0
25+
}
26+
327
# get the directory of the current script
4-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
28+
ASDF_ELIXIR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
529

630
# calling a script to list all elixir releases
731
# reject releases before 1.0.0 (starting with 0)
@@ -10,14 +34,18 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1034
# reject release candidates
1135
# reject empty line
1236
# finally take last one
13-
ASDF_ELIXIR_LATEST_VERSION=$("$SCRIPT_DIR"/list-all | tr " " "\n" | grep -Ev "^0|^main|^master|otp|rc|^$" | tail -n 1)
37+
ASDF_ELIXIR_LATEST_VERSION=$("$ASDF_ELIXIR_SCRIPT_DIR"/list-all | tr " " "\n" | grep -Ev "^0|^main|^master|otp|rc|^$" | tail -n 1)
1438

15-
# gets current erlang version without headers
16-
# changes spaces to new line
17-
# takes second line (Name Version Source Installed)
18-
ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang | tr -s " ." "\n" | sed -n 2p)
39+
# support for v-dev and different asdf API versions
40+
ASDF_ELIXIR_ASDF_VERSION="$(asdf version)"
41+
if [ "$ASDF_ELIXIR_ASDF_VERSION" = "v-dev" ] || version_gte_api_change "${ASDF_ELIXIR_ASDF_VERSION#v}"; then
42+
# use --no-header flag only in latest asdf API (go builds)
43+
ASDF_ELIXIR_LATEST_OTP=$(asdf current --no-header erlang)
44+
else
45+
ASDF_ELIXIR_LATEST_OTP=$(asdf current erlang)
46+
fi
1947

2048
# Note: asdf latest does not allows latest stable version to start with number
2149
# therefore installing from source by git ref is not supported, see:
2250
# https://github.com/asdf-vm/asdf/blob/v0.16.5/internal/versions/versions.go#L276
23-
echo "$ASDF_ELIXIR_LATEST_VERSION-otp-$ASDF_ELIXIR_LATEST_OTP"
51+
printf "%s-otp-%s\n" "$ASDF_ELIXIR_LATEST_VERSION" "$(printf "%s" "$ASDF_ELIXIR_LATEST_OTP" | tr -s " ." "\n" | sed -n 2p)"

0 commit comments

Comments
 (0)