mirror of
https://github.com/cheikh2shift/godex.git
synced 2026-10-19 01:29:53 -05:00
Enhance version detection in install script to use API and fallback to HTML parsing
This commit is contained in:
1 parent
f7f4ac3858
commit
dc3d980d29
2 files changed
+32
-20
No files matched your search
@@ -40,28 +40,21 @@ jobs:
|
||||
install-windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Get latest release tag
|
||||
id: get_tag
|
||||
run: |
|
||||
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/cheikh2shift/godex/releases/latest"
|
||||
echo "TAG=$($response.tag_name)" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
shell: pwsh
|
||||
|
||||
- name: Download Windows binary
|
||||
run: |
|
||||
Write-Host "Tag: ${{ steps.get_tag.outputs.TAG }}"
|
||||
curl.exe -sSL -o godex-windows-amd64.exe "https://github.com/cheikh2shift/godex/releases/download/${{ steps.get_tag.outputs.TAG }}/godex-windows-amd64.exe"
|
||||
Get-Item godex-windows-amd64.exe | Select-Object Name, Length
|
||||
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/cheikh2shift/godex/releases/latest"
|
||||
$version = ($response.tag_name) -replace '^v',''
|
||||
Write-Host "Downloading version v$version"
|
||||
curl.exe -sSL -o godex-windows-amd64.exe "https://github.com/cheikh2shift/godex/releases/download/v${version}/godex-windows-amd64.exe"
|
||||
shell: pwsh
|
||||
|
||||
- name: Verify installation
|
||||
run: |
|
||||
$bytes = Get-Content godex-windows-amd64.exe -TotalCount 2 -Encoding Byte
|
||||
if ($bytes[0] -eq 77 -and $bytes[1] -eq 90) {
|
||||
$header = [System.IO.File]::ReadAllBytes("godex-windows-amd64.exe")[0..1]
|
||||
if ($header[0] -eq 77 -and $header[1] -eq 90) {
|
||||
Write-Host "Valid PE executable"
|
||||
./godex-windows-amd64.exe --version
|
||||
} else {
|
||||
Write-Host "Invalid file - first bytes: $($bytes[0]) $($bytes[1])"
|
||||
Get-Content godex-windows-amd64.exe -TotalCount 5
|
||||
Write-Host "Invalid file - first bytes: $($header[0]) $($header[1])"
|
||||
}
|
||||
shell: pwsh
|
||||
+25
-6
@@ -6,6 +6,29 @@ REPO="cheikh2shift/godex"
|
||||
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
|
||||
BINARY_NAME="godex"
|
||||
|
||||
# Detect version from API
|
||||
get_version() {
|
||||
# Try API first, fall back to parsing HTML
|
||||
curl -sL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null | grep '"tag_name"' | sed 's/.*"v\([^"]*\)".*/\1/'
|
||||
}
|
||||
|
||||
# VERSION can be passed as arg, env var, or auto-detected
|
||||
if [ -n "$1" ]; then
|
||||
LATEST_TAG="$1"
|
||||
elif [ -n "$VERSION" ]; then
|
||||
LATEST_TAG="$VERSION"
|
||||
else
|
||||
LATEST_TAG=$(get_version)
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
# Fallback: parse release page
|
||||
LATEST_TAG=$(curl -sL "https://github.com/${REPO}/releases" 2>/dev/null | grep -o 'releases/tag/[^"]*' | head -1 | sed 's/.*tag\///')
|
||||
fi
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
echo "Failed to get latest release version"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect OS and architecture
|
||||
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||
ARCH="$(uname -m)"
|
||||
@@ -52,16 +75,12 @@ if [ "$OS" = "windows" ]; then
|
||||
SHA_FILENAME="${FILENAME}.sha256"
|
||||
fi
|
||||
|
||||
# Get latest tag
|
||||
LATEST_TAG=$(curl -sL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed 's/.*"v\([^"]*\)".*/\1/')
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
echo "Failed to get latest release version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
URL="https://github.com/${REPO}/releases/download/v${LATEST_TAG}/${FILENAME}"
|
||||
SHA_URL="https://github.com/${REPO}/releases/download/v${LATEST_TAG}/${SHA_FILENAME}"
|
||||
|
||||
echo "Using version v${LATEST_TAG}"
|
||||
|
||||
echo "Downloading ${FILENAME}..."
|
||||
curl -sSL -o "${FILENAME}" "$URL"
|
||||
|
||||
|
||||
Reference in new issue
Block a user