Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
push:
branches:
- main
pull_request:

jobs:
plugin_test:
name: asdf plugin test
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
version:
- latest
# Test an old version that uses .zip on Linux (pre-1.0.92)
- "1.0.91"
runs-on: ${{ matrix.os }}
steps:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@6a442392015fbbdd8b48696d41e0051b2698b2e4 # v2
with:
command: opencode --version
version: ${{ matrix.version }}
25 changes: 21 additions & 4 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ TMPDIR=${TMPDIR:-/tmp}
[ -n "$ASDF_INSTALL_VERSION" ] || (>&2 echo 'Missing ASDF_INSTALL_VERSION' && exit 1)
[ -n "$ASDF_INSTALL_PATH" ] || (>&2 echo 'Missing ASDF_INSTALL_PATH' && exit 1)

# Compare two semantic versions using portable sort
# Returns 0 if version1 >= version2, 1 otherwise
version_gte() {
local version1=$1
local version2=$2
# Use portable version sorting (same logic as sort_versions in list-all)
local sorted_first
sorted_first=$(printf '%s\n%s\n' "$version1" "$version2" | \
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | \
awk 'NR==1 {print $2}')
[ "$sorted_first" = "$version2" ]
}

install_opencode() {
local version=$2
local install_path=$3
local bin_install_path="$install_path/bin"
local download_url="$(get_download_url $version)"

local platform="$(get_platform)"

mkdir -p "${install_path}"
mkdir -p "${bin_install_path}"
local bin_path="${bin_install_path}/opencode"
echo "downloading opencode ${download_url}"
if [ "$platform" = "linux" ]; then
if [[ "$download_url" == *.tar.gz ]]; then
curl -sL "$download_url" | tar -xz -C "${install_path}"
else
curl -L -s "$download_url" | funzip > "${install_path}/opencode"
Expand Down Expand Up @@ -52,9 +64,14 @@ get_download_url() {
local platform="$(get_platform)"
local arch="$(get_arch)"
local ext="zip"

# Linux switched from .zip to .tar.gz starting with v1.0.92
if [ "$platform" = "linux" ]; then
ext="tar.gz"
if version_gte "$version" "1.0.92"; then
ext="tar.gz"
fi
fi

echo "https://github.com/sst/opencode/releases/download/v${version}/opencode-${platform}-${arch}.${ext}"
}

Expand Down
2 changes: 1 addition & 1 deletion bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ while [ -n "${next_link}" ]; do
cmd_out=$(eval "${cmd}" 2>&1)

# Get versions
versions=$(echo "${cmd_out}" | grep "\"tag_name\":" | sed 's/^ *"tag_name"\: *"v\?\(.*\)", *$/\1/')
versions=$(echo "${cmd_out}" | grep tag_name | cut -d'"' -f4 | sed 's/^v//')
all_versions="${versions}\n${all_versions}"

# Get next link
Expand Down