Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zimagen committed Dec 18, 2023
0 parents commit 8264b84
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
27 changes: 27 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Main Workflow

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
# schedule:
# - cron: "0 0 * * 5"

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v2
with:
command: sd --help
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Genki Yajima <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# asdf-sd

[![Main Workflow](https://github.com/zimagen/asdf-sd/actions/workflows/workflow.yml/badge.svg)](https://github.com/zimagen/asdf-sd/actions/workflows/workflow.yml)

[`sd`][util] plugin for [asdf](https://github.com/asdf-vm/asdf) version manager.

## Install

```
asdf plugin-add sd https://github.com/zimagen/asdf-sd.git
asdf install sd latest
```

## Use

Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of sd.

[util]: https://github.com/chmln/sd
111 changes: 111 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env bash

set -e
set -o pipefail
# set -x

ASDF_INSTALL_TYPE=${ASDF_INSTALL_TYPE:-version}
[ -n "$ASDF_INSTALL_VERSION" ] || (>&2 echo 'Missing ASDF_INSTALL_VERSION' && exit 1)
[ -n "$ASDF_INSTALL_PATH" ] || (>&2 echo 'Missing ASDF_INSTALL_PATH' && exit 1)

install_plugin() {
local install_type=$1
local version=$2
local install_path=$3
local download_url="$(get_download_url $install_type $version)"
local tmp_download_file=$(mktemp)

local bin_install_path="$install_path/bin"
mkdir -p "${bin_install_path}"

echo "Downloading sd from $download_url"
curl -L -s "$download_url" -o "$tmp_download_file"
pushd $bin_install_path > /dev/null
tar zxf "$tmp_download_file" || exit 1
mv sd-*/sd ./
popd > /dev/null
}

get_platform() {
local unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) echo "linux";;
Darwin*) echo "mac";;
CYGWIN*) echo "win";;
MINGW*) echo "win";;
*) echo "unknown"
esac
if [ "$unameOut" == "CYGWIN*" ] || [ "$unameOut" == "MINGW*" ]; then
echo "Windows is not supported" >&2
exit 1
fi
}

get_arch() {
local arch=$(uname -m)
case $arch in
amd64 | x86_64)
echo "x86_64"
;;
arm64 | aarch64)
echo "arm64"
;;
arm)
echo "arm"
;;
*)
echo "i386 is not supported" >&2
exit 1
esac
}

get_download_url() {
local install_type=$1
local tag=$2
local version=$2

local platform=$(get_platform)
local arch=$(get_arch)
local extra=""

# platform and arch mapping
case $platform in
linux)
platform="unknown-linux"
;;
mac)
platform="apple-darwin"
;;
win)
platform="pc-windows"
;;
esac

case $arch in
x86_64)
arch="x86_64"
;;
arm64 | aarch64)
arch="aarch64"
;;
arm)
arch="arm"
;;
*)
arch="i386"
esac

# in case the version is in some other format such as FOOBAR.X.X.X
if [[ "$tag" =~ ^[0-9] ]]; then
tag="v${tag}"
fi

local file_extension="tar.gz"
if [ "$platform" == "pc-windows" ]; then
file_extension="zip"
fi

echo "https://github.com/chmln/sd/releases/download/${tag}/sd-${tag}-${arch}-${platform}.${file_extension}"
}

install_plugin "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
21 changes: 21 additions & 0 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -eo pipefail

repo=chmln/sd

cmd="curl --silent --location"
releases_path="https://api.github.com/repos/$repo/releases"

if [ -n "$GITHUB_API_TOKEN" ]; then
cmd="$cmd --header 'Authorization: token $GITHUB_API_TOKEN'"
fi

sort_versions() {
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 '{print $2}'
}

versions=$(eval "$cmd $releases_path" | grep -oE "tag_name\":\s?\".*\"," | sed 's/tag_name\": *\"//;s/\",//' | sed 's/^[v]//' | sort_versions | xargs)

echo "$versions"

0 comments on commit 8264b84

Please sign in to comment.