diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 4464c02..95a6c91 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -63,10 +63,10 @@ jobs: cp LICENSE packages/safe-chain/ cp -r docs packages/safe-chain/ - # - name: Publish to npm - # run: | - # echo "Publishing version ${{ steps.get_version.outputs.tag }} to NPM" - # npm publish --workspace=packages/safe-chain --access public --provenance + - name: Publish to npm + run: | + echo "Publishing version ${{ steps.get_version.outputs.tag }} to NPM" + npm publish --workspace=packages/safe-chain --access public --provenance - name: Download all binary artifacts uses: actions/download-artifact@v4 diff --git a/install-scripts/install-safe-chain.ps1 b/install-scripts/install-safe-chain.ps1 index 3400bfc..230bb11 100644 --- a/install-scripts/install-safe-chain.ps1 +++ b/install-scripts/install-safe-chain.ps1 @@ -7,7 +7,7 @@ param( [switch]$includepython ) -$Version = "v0.0.7-binaries-beta" +$Version = $env:SAFE_CHAIN_VERSION # Will be fetched from latest release if not set $InstallDir = Join-Path $env:USERPROFILE ".safe-chain\bin" $RepoUrl = "https://github.com/AikidoSec/safe-chain" @@ -31,6 +31,25 @@ function Write-Error-Custom { exit 1 } +# Fetch latest release version tag from GitHub +function Get-LatestVersion { + Write-Info "Fetching latest release version..." + + try { + $response = Invoke-RestMethod -Uri "https://api.github.com/repos/AikidoSec/safe-chain/releases/latest" -UseBasicParsing + $latestVersion = $response.tag_name + + if ([string]::IsNullOrWhiteSpace($latestVersion)) { + Write-Error-Custom "Failed to fetch latest version from GitHub API. Please set SAFE_CHAIN_VERSION environment variable." + } + + return $latestVersion + } + catch { + Write-Error-Custom "Failed to fetch latest version from GitHub API: $($_.Exception.Message). Please set SAFE_CHAIN_VERSION environment variable." + } +} + # Detect architecture function Get-Architecture { $arch = $env:PROCESSOR_ARCHITECTURE @@ -92,6 +111,11 @@ function Remove-VoltaInstallation { # Main installation function Install-SafeChain { + # Fetch latest version if VERSION is not set + if ([string]::IsNullOrWhiteSpace($script:Version)) { + $script:Version = Get-LatestVersion + } + # Build installation message $installMsg = "Installing safe-chain $Version" if ($includepython) { diff --git a/install-scripts/install-safe-chain.sh b/install-scripts/install-safe-chain.sh index 9b34e0c..0fbbf34 100755 --- a/install-scripts/install-safe-chain.sh +++ b/install-scripts/install-safe-chain.sh @@ -7,7 +7,7 @@ set -e # Exit on error # Configuration -VERSION="${SAFE_CHAIN_VERSION:-v0.0.7-binaries-beta}" +VERSION="${SAFE_CHAIN_VERSION:-}" # Will be fetched from latest release if not set INSTALL_DIR="${HOME}/.safe-chain/bin" REPO_URL="https://github.com/AikidoSec/safe-chain" @@ -54,6 +54,26 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } +# Fetch latest release version tag from GitHub +fetch_latest_version() { + info "Fetching latest release version..." + + # Try using GitHub API to get the latest release tag + if command_exists curl; then + latest_version=$(curl -fsSL "https://api.github.com/repos/AikidoSec/safe-chain/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') + elif command_exists wget; then + latest_version=$(wget -qO- "https://api.github.com/repos/AikidoSec/safe-chain/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') + else + error "Neither curl nor wget found. Please install one of them or set SAFE_CHAIN_VERSION environment variable." + fi + + if [ -z "$latest_version" ]; then + error "Failed to fetch latest version from GitHub API. Please set SAFE_CHAIN_VERSION environment variable." + fi + + echo "$latest_version" +} + # Download file download() { url="$1" @@ -135,6 +155,11 @@ main() { # Parse command-line arguments parse_arguments "$@" + # Fetch latest version if VERSION is not set + if [ -z "$VERSION" ]; then + VERSION=$(fetch_latest_version) + fi + # Build installation message INSTALL_MSG="Installing safe-chain ${VERSION}" if [ "$INCLUDE_PYTHON" = "true" ]; then