diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c5dc4792..dd1aa786 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,7 +16,7 @@ before: builds: - env: - CGO_ENABLED=0 - main: ./internal/numscript/numscript.go + main: ./cmd/numscript/main.go goos: - linux - windows diff --git a/README.md b/README.md index 76747bc1..c0314f65 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,18 @@ The language server features include: - Detect document symbols - Go to definition -### Build locally -If you have the golang toolchain installed locally, you can run `go install ./internal/numscript/numscript.go` to build the cli from source, which you'll be able to run by executing the `numscript` command -Otherwise, you can download it from this repo's [releases](https://github.com/formancehq/numscript/releases) +### Installation + +You can install the `numscript` cli with one of the following ways: + +**Using curl** + +```sh +curl -sSf https://raw.githubusercontent.com/formancehq/numscript/main/install.sh | bash +``` + +**Using golang toolchain** + +```sh +go install github.com/formancehq/numscript/cmd/numscript@latest +``` diff --git a/internal/numscript/numscript.go b/cmd/numscript/main.go similarity index 100% rename from internal/numscript/numscript.go rename to cmd/numscript/main.go diff --git a/install.sh b/install.sh new file mode 100644 index 00000000..a9b69ef3 --- /dev/null +++ b/install.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +set -e + +echo "👉 Detecting platform..." + +# Detect OS +OS="$(uname -s)" +case "$OS" in + Linux*) PLATFORM="Linux";; + Darwin*) PLATFORM="Darwin";; + MINGW*|MSYS*|CYGWIN*|Windows_NT) PLATFORM="Windows";; + *) echo "❌ Unsupported OS: $OS"; exit 1;; +esac + +# Detect architecture +ARCH="$(uname -m)" +case "$ARCH" in + x86_64) ARCH="x86_64";; + amd64) ARCH="x86_64";; # Just in case + arm64|aarch64) ARCH="arm64";; + *) echo "❌ Unsupported architecture: $ARCH"; exit 1;; +esac + +echo "✅ Platform: $PLATFORM" +echo "✅ Architecture: $ARCH" + + +# https://github.com/formancehq/numscript/releases/download/v0.0.18/numscript_.0.0.18_Darwin_arm64.tar.gz +# Get latest release tag +LATEST_TAG=$(curl -sI https://github.com/formancehq/numscript/releases/latest | grep -i location | awk -F '/' '{print $NF}' | tr -d '\r') + +echo "📦 Latest tag: $LATEST_TAG" + +# Determine file extension +if [ "$PLATFORM" = "Windows" ]; then + EXT="zip" +else + EXT="tar.gz" +fi + +# Build file name and URL +FILENAME="numscript_.${LATEST_TAG#v}_${PLATFORM}_${ARCH}.${EXT}" +URL="https://github.com/formancehq/numscript/releases/download/$LATEST_TAG/$FILENAME" + +echo "⬇️ Downloading: $URL" +curl -L -o "$FILENAME" "$URL" + +# Extract and install +if [ "$PLATFORM" = "Windows" ]; then + unzip "$FILENAME" + BIN="numscript.exe" +else + tar -xf "$FILENAME" numscript + BIN="numscript" +fi + + +INSTALL_PATH="$HOME/.local/bin" +mkdir -p "$INSTALL_PATH" + +mv "$BIN" "$INSTALL_PATH" +chmod +x "$INSTALL_PATH/$BIN" + +rm "$FILENAME" + +echo "✅ Installed $BIN to $INSTALL_PATH" +echo "🎉 Done!"