feat: add sui script

This commit is contained in:
Zitao Xiong
2024-03-30 17:31:47 +08:00
parent 78b1dd233a
commit aa585daf88
5 changed files with 56 additions and 18 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
tmp*

View File

@@ -1,6 +1,6 @@
<div align="center">
# asdf-sui [![Build](https://github.com/caoer/asdf-sui/actions/workflows/build.yml/badge.svg)](https://github.com/caoer/asdf-sui/actions/workflows/build.yml) [![Lint](https://github.com/caoer/asdf-sui/actions/workflows/lint.yml/badge.svg)](https://github.com/caoer/asdf-sui/actions/workflows/lint.yml)
# asdf-sui [![Build](https://github.com/placeholder-soft/asdf-sui/actions/workflows/build.yml/badge.svg)](https://github.com/placeholder-soft/asdf-sui/actions/workflows/build.yml) [![Lint](https://github.com/placeholder-soft/asdf-sui/actions/workflows/lint.yml/badge.svg)](https://github.com/placeholder-soft/asdf-sui/actions/workflows/lint.yml)
[sui](https://github.com/placeholder-soft/asdf-sui) plugin for the [asdf version manager](https://asdf-vm.com).
@@ -15,10 +15,7 @@
# Dependencies
**TODO: adapt this section**
- `bash`, `curl`, `tar`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.
# Install
@@ -27,7 +24,7 @@ Plugin:
```shell
asdf plugin add sui
# or
asdf plugin add sui https://github.com/caoer/asdf-sui.git
asdf plugin add sui https://github.com/placeholder-soft/asdf-sui.git
```
sui:
@@ -53,8 +50,8 @@ install & manage versions.
Contributions of any kind welcome! See the [contributing guide](contributing.md).
[Thanks goes to these contributors](https://github.com/caoer/asdf-sui/graphs/contributors)!
[Thanks goes to these contributors](https://github.com/placeholder-soft/asdf-sui/graphs/contributors)!
# License
See [LICENSE](LICENSE) © [Zitao Xiong](https://github.com/caoer/)
See [LICENSE](LICENSE) © [Zitao Xiong](https://github.com/placeholder-soft/)

View File

@@ -10,8 +10,7 @@ source "${plugin_dir}/lib/utils.bash"
mkdir -p "$ASDF_DOWNLOAD_PATH"
# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tgz"
# Download tar.gz file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"
@@ -19,5 +18,32 @@ download_release "$ASDF_INSTALL_VERSION" "$release_file"
# Extract contents of tar.gz file into the download directory
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
os="$(os_name)"
arch="$(arch_name)"
try_mv() {
if [ -f "$1" ]; then
mv "$1" "$2"
else
# echo "File $1 does not exist"
fi
}
extract_path="$ASDF_DOWNLOAD_PATH"
mkdir -p $extract_path
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-bridge-$os-$arch $extract_path/sui-bridge
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-data-ingestion-$os-$arch $extract_path/sui-data-ingestion
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-faucet-$os-$arch $extract_path/sui-faucet
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-$os-$arch $extract_path/sui
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-node-$os-$arch $extract_path/sui-node
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-test-validator-$os-$arch $extract_path/sui-test-validator
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-tool-$os-$arch $extract_path/sui-tool
try_mv $ASDF_DOWNLOAD_PATH/target/release/sui-indexer-$os-$arch $extract_path/sui-indexer
try_mv $ASDF_DOWNLOAD_PATH/external-crates/move/target/release/move-analyzer-$os-$arch $extract_path/move-analyzer
# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
rm -rf "$ASDF_DOWNLOAD_PATH/external-crates"
rm -rf "$ASDF_DOWNLOAD_PATH/target"

View File

@@ -5,8 +5,7 @@ Testing Locally:
```shell
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]
# TODO: adapt this
asdf plugin test sui https://github.com/caoer/asdf-sui.git "sui --version"
asdf plugin test sui https://github.com/placeholdersoft/asdf-sui.git "sui --version"
```
Tests are automatically run in GitHub Actions on push and PR.

View File

@@ -2,8 +2,7 @@
set -euo pipefail
# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for sui.
GH_REPO="https://github.com/placeholder-soft/asdf-sui"
GH_REPO="https://github.com/MystenLabs/sui"
TOOL_NAME="sui"
TOOL_TEST="sui --version"
@@ -31,18 +30,35 @@ list_github_tags() {
}
list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if sui has other means of determining installable versions.
list_github_tags
}
os_name() {
case "$(uname -s)" in
Darwin) echo "macos" ;;
Linux) echo "ubuntu" ;;
*) echo "windows" ;;
esac
}
# arm64, x86_64
arch_name() {
case "$(uname -m)" in
arm64) echo "arm64" ;;
x86_64) echo "x86_64" ;;
*) echo "unknown" ;;
esac
}
download_release() {
local version filename url
version="$1"
filename="$2"
local os_name arch_name
os_name="$(os_name)"
arch_name="$(arch_name)"
# TODO: Adapt the release URL convention for sui
url="$GH_REPO/archive/v${version}.tar.gz"
url="$GH_REPO/releases/download/${version}/sui-${version}-${os_name}-${arch_name}.tgz"
echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
@@ -61,7 +77,6 @@ install_version() {
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
# TODO: Assert sui executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."