Make scripts release-proof again

This commit is contained in:
Sander Declerck 2025-12-03 11:58:33 +01:00
parent a578ee7213
commit ac6567ba59
No known key found for this signature in database
3 changed files with 55 additions and 6 deletions

View file

@ -63,10 +63,10 @@ jobs:
cp LICENSE packages/safe-chain/ cp LICENSE packages/safe-chain/
cp -r docs packages/safe-chain/ cp -r docs packages/safe-chain/
# - name: Publish to npm - name: Publish to npm
# run: | run: |
# echo "Publishing version ${{ steps.get_version.outputs.tag }} to NPM" echo "Publishing version ${{ steps.get_version.outputs.tag }} to NPM"
# npm publish --workspace=packages/safe-chain --access public --provenance npm publish --workspace=packages/safe-chain --access public --provenance
- name: Download all binary artifacts - name: Download all binary artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4

View file

@ -7,7 +7,7 @@ param(
[switch]$includepython [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" $InstallDir = Join-Path $env:USERPROFILE ".safe-chain\bin"
$RepoUrl = "https://github.com/AikidoSec/safe-chain" $RepoUrl = "https://github.com/AikidoSec/safe-chain"
@ -31,6 +31,25 @@ function Write-Error-Custom {
exit 1 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 # Detect architecture
function Get-Architecture { function Get-Architecture {
$arch = $env:PROCESSOR_ARCHITECTURE $arch = $env:PROCESSOR_ARCHITECTURE
@ -92,6 +111,11 @@ function Remove-VoltaInstallation {
# Main installation # Main installation
function Install-SafeChain { function Install-SafeChain {
# Fetch latest version if VERSION is not set
if ([string]::IsNullOrWhiteSpace($script:Version)) {
$script:Version = Get-LatestVersion
}
# Build installation message # Build installation message
$installMsg = "Installing safe-chain $Version" $installMsg = "Installing safe-chain $Version"
if ($includepython) { if ($includepython) {

View file

@ -7,7 +7,7 @@
set -e # Exit on error set -e # Exit on error
# Configuration # 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" INSTALL_DIR="${HOME}/.safe-chain/bin"
REPO_URL="https://github.com/AikidoSec/safe-chain" REPO_URL="https://github.com/AikidoSec/safe-chain"
@ -54,6 +54,26 @@ command_exists() {
command -v "$1" >/dev/null 2>&1 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 file
download() { download() {
url="$1" url="$1"
@ -135,6 +155,11 @@ main() {
# Parse command-line arguments # Parse command-line arguments
parse_arguments "$@" parse_arguments "$@"
# Fetch latest version if VERSION is not set
if [ -z "$VERSION" ]; then
VERSION=$(fetch_latest_version)
fi
# Build installation message # Build installation message
INSTALL_MSG="Installing safe-chain ${VERSION}" INSTALL_MSG="Installing safe-chain ${VERSION}"
if [ "$INCLUDE_PYTHON" = "true" ]; then if [ "$INCLUDE_PYTHON" = "true" ]; then