Skip to content

Commit 066e6d7

Browse files
committed
feat: support ubuntu-22.04 install
1 parent 44e9948 commit 066e6d7

File tree

3 files changed

+85
-8
lines changed

3 files changed

+85
-8
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ on:
88

99
jobs:
1010
plugin_test:
11-
name: asdf plugin test
12-
runs-on:
13-
- macos-latest
11+
name: asdf plugin test (${{ matrix.os }})
12+
strategy:
13+
matrix:
14+
os:
15+
- macos-latest
16+
- ubuntu-22.04
17+
runs-on: ${{ matrix.os }}
1418
steps:
1519
- name: asdf_plugin_test
1620
uses: asdf-vm/actions/plugin-test@v3

bin/download

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,26 @@ source "${plugin_dir}/lib/utils.bash"
1010

1111
mkdir -p "$ASDF_DOWNLOAD_PATH"
1212

13-
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.zip"
13+
platform="$(get_platform)"
14+
15+
case "$platform" in
16+
macos)
17+
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.zip"
18+
;;
19+
ubuntu-22.04)
20+
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.xz"
21+
;;
22+
esac
1423

1524
download_release "$ASDF_INSTALL_VERSION" "$release_file"
1625

17-
unzip "$release_file" -d "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file"
26+
case "$platform" in
27+
macos)
28+
unzip "$release_file" -d "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file"
29+
;;
30+
ubuntu-22.04)
31+
tar -xJf "$release_file" -C "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file"
32+
;;
33+
esac
1834

1935
rm "$release_file"

lib/utils.bash

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@ GH_REPO="https://github.com/krzysztofzablocki/Sourcery"
66
TOOL_NAME="sourcery"
77
TOOL_TEST="sourcery --version"
88

9+
# Detect platform and return download details
10+
# Returns: "macos" | "ubuntu-22.04" or fails
11+
get_platform() {
12+
local kernel
13+
kernel="$(uname -s)"
14+
15+
case "$kernel" in
16+
Darwin)
17+
echo "macos"
18+
;;
19+
Linux)
20+
# Check if Ubuntu 22.04
21+
if [ -f /etc/os-release ]; then
22+
# shellcheck source=/dev/null
23+
source /etc/os-release
24+
if [ "$ID" = "ubuntu" ] && [ "$VERSION_ID" = "22.04" ]; then
25+
echo "ubuntu-22.04"
26+
return
27+
fi
28+
fi
29+
fail "Unsupported Linux distribution. Only Ubuntu 22.04 is supported."
30+
;;
31+
*)
32+
fail "Unsupported OS: $kernel"
33+
;;
34+
esac
35+
}
36+
937
fail() {
1038
echo -e "asdf-$TOOL_NAME: $*"
1139
exit 1
@@ -39,12 +67,41 @@ ignore_invalid_versions() {
3967
cut -d ' ' -f 6-
4068
}
4169

70+
# Fetch Ubuntu asset URL from GitHub API
71+
# Pattern: finds asset matching *ubuntu*22.04*{arch}*.tar.xz
72+
get_ubuntu_asset_url() {
73+
local version="$1"
74+
local api_url asset_url arch
75+
76+
arch="$(uname -m)"
77+
api_url="https://api.github.com/repos/krzysztofzablocki/Sourcery/releases/tags/${version}"
78+
79+
asset_url=$(curl "${curl_opts[@]}" "$api_url" 2>/dev/null | \
80+
grep -o "\"browser_download_url\": *\"[^\"]*ubuntu[^\"]*22\\.04[^\"]*${arch}[^\"]*\\.tar\\.xz\"" | \
81+
head -1 | \
82+
sed 's/"browser_download_url": *"\([^"]*\)"/\1/')
83+
84+
if [ -z "$asset_url" ]; then
85+
fail "Could not find Ubuntu 22.04 $arch asset for version $version"
86+
fi
87+
88+
echo "$asset_url"
89+
}
90+
4291
download_release() {
43-
local version filename url
92+
local version filename url platform
4493
version="$1"
4594
filename="$2"
46-
47-
url="$GH_REPO/releases/download/${version}/sourcery-${version}.zip"
95+
platform="$(get_platform)"
96+
97+
case "$platform" in
98+
macos)
99+
url="$GH_REPO/releases/download/${version}/sourcery-${version}.zip"
100+
;;
101+
ubuntu-22.04)
102+
url="$(get_ubuntu_asset_url "$version")"
103+
;;
104+
esac
48105

49106
echo "* Downloading $TOOL_NAME release $version..."
50107
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"

0 commit comments

Comments
 (0)