diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..034a19b --- /dev/null +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/bin/install b/bin/install index c01c2b9..f695848 100755 --- a/bin/install +++ b/bin/install @@ -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" @@ -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}" } diff --git a/bin/list-all b/bin/list-all index 1e79d01..1f43850 100755 --- a/bin/list-all +++ b/bin/list-all @@ -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