Skip to content

Commit

Permalink
binaries are renamed after 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Düvel committed Jul 6, 2024
1 parent 345a297 commit 122f8e4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
shellcheck 0.7.2
shfmt 3.3.0
bats 1.11.0
29 changes: 28 additions & 1 deletion lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,38 @@ list_all_versions() {
list_github_tags
}

amd64_or_arm64() {
if [ "$(uname -m)" = "x86_64" ]; then
echo "amd64"
else
uname -m
fi
}

arch() {
local version=$1
local major=$(echo "$version" | cut -d'.' -f1)
local minor=$(echo "$version" | cut -d'.' -f2)
if [ "$major" -gt 0 ]; then
amd64_or_arm64
elif [ "$major" -eq 0 ] && [ "$minor" -ge 8 ]; then
amd64_or_arm64
else
echo "x86_64"
fi
}

url() {
local version
version="$1"
echo "$GH_REPO/releases/download/v${version}/k2tf_${version}_$(uname)_$(arch $version).tar.gz"
}

download_release() {
local version filename url
version="$1"
filename="$2"
url="$GH_REPO/releases/download/v${version}/k2tf_${version}_$(uname)_x86_64.tar.gz"
url="$(url "$version")"
echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
}
Expand Down
18 changes: 18 additions & 0 deletions lib/utils.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bats

load 'utils.bash'

@test "url function should return correct URL for version < 0.8.0" {
version="0.7.0"
result=$(url "$version")
expected="https://github.com/sl1pm4t/k2tf/releases/download/v0.7.0/k2tf_0.7.0_$(uname)_x86_64.tar.gz"
[ "$result" == "$expected" ]
}
@test "url function should return correct URL for version > 0.7.0" {
version="0.8.0"
result=$(url "$version")
expected="https://github.com/sl1pm4t/k2tf/releases/download/v0.8.0/k2tf_0.8.0_$(uname)_$(uname -m).tar.gz"
[ "$result" == "$expected" ]
}


0 comments on commit 122f8e4

Please sign in to comment.