|
40 | 40 | echo "Detected Platform: $OS/$ARCH" |
41 | 41 |
|
42 | 42 | # Get latest release tag |
43 | | -# GitHub's /releases/latest endpoint only returns non-prereleases. |
44 | | -# We fetch the release list and use a robust way to extract the tag name, |
45 | | -# handling both pretty-printed and minified JSON. |
| 43 | +# We prefer git ls-remote to avoid GitHub API rate limits (403 errors). |
| 44 | +# If git is not available, we fallback to the API. |
46 | 45 | echo "Fetching release metadata..." |
47 | 46 |
|
48 | | -# Use a portable temporary file (Termux doesn't have /tmp) |
49 | | -TMP_ERR=$(mktemp) |
50 | | -TAG_DATA=$(curl -fsSL -H "User-Agent: vibeauracle-installer" "https://api.github.com/repos/$REPO/releases" 2>"$TMP_ERR" || true) |
51 | | - |
52 | | -if [ -z "$TAG_DATA" ]; then |
53 | | - echo "Error: Failed to fetch releases from GitHub API." |
54 | | - if [ -f "$TMP_ERR" ]; then |
55 | | - cat "$TMP_ERR" |
56 | | - rm "$TMP_ERR" |
| 47 | +LATEST_TAG="" |
| 48 | +if command -v git >/dev/null 2>&1; then |
| 49 | + # Try to get the latest tag (preferring 'latest' rolling tag or newest semver) |
| 50 | + ALL_TAGS=$(git ls-remote --tags "https://github.com/$REPO.git" | cut -d/ -f3) |
| 51 | + if echo "$ALL_TAGS" | grep -q "^latest$"; then |
| 52 | + LATEST_TAG="latest" |
| 53 | + else |
| 54 | + LATEST_TAG=$(echo "$ALL_TAGS" | grep -E "^v[0-9]" | sort -V | tail -n 1) |
57 | 55 | fi |
58 | | - exit 1 |
59 | 56 | fi |
60 | | -rm "$TMP_ERR" |
61 | 57 |
|
62 | | -LATEST_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"[^"]+"' | head -n 1 | cut -d'"' -f4) |
| 58 | +if [ -z "$LATEST_TAG" ]; then |
| 59 | + # Fallback to API if git failed or wasn't found |
| 60 | + TMP_ERR=$(mktemp) |
| 61 | + TAG_DATA=$(curl -fsSL -H "User-Agent: vibeauracle-installer" "https://api.github.com/repos/$REPO/releases" 2>"$TMP_ERR" || true) |
| 62 | + |
| 63 | + if [ -n "$TAG_DATA" ]; then |
| 64 | + LATEST_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"[^"]+"' | head -n 1 | cut -d'"' -f4) |
| 65 | + |
| 66 | + # If we found tags but it wasn't the 'latest' tag specifically, |
| 67 | + # try to see if 'latest' exists in the list for stability |
| 68 | + if [[ "$LATEST_TAG" != "latest" ]]; then |
| 69 | + STABLE_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"latest"' | head -n 1 | cut -d'"' -f4) |
| 70 | + if [ -n "$STABLE_TAG" ]; then |
| 71 | + LATEST_TAG="$STABLE_TAG" |
| 72 | + fi |
| 73 | + fi |
| 74 | + fi |
63 | 75 |
|
64 | | -# If we found tags but it wasn't the 'latest' tag specifically, |
65 | | -# try to see if 'latest' exists in the list for stability |
66 | | -if [[ "$LATEST_TAG" != "latest" ]]; then |
67 | | - STABLE_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"latest"' | head -n 1 | cut -d'"' -f4) |
68 | | - if [ -n "$STABLE_TAG" ]; then |
69 | | - LATEST_TAG="$STABLE_TAG" |
| 76 | + if [ -z "$LATEST_TAG" ]; then |
| 77 | + echo "Error: Failed to fetch releases from GitHub." |
| 78 | + if [ -f "$TMP_ERR" ] && [ -s "$TMP_ERR" ]; then |
| 79 | + cat "$TMP_ERR" |
| 80 | + fi |
| 81 | + rm -f "$TMP_ERR" |
| 82 | + exit 1 |
70 | 83 | fi |
| 84 | + rm -f "$TMP_ERR" |
71 | 85 | fi |
72 | 86 |
|
73 | | -if [ -z "$LATEST_TAG" ]; then |
74 | | - echo "Error: Could not determine latest version. Please check $GITHUB_URL/releases" |
75 | | - exit 1 |
76 | | -fi |
| 87 | +echo "Resolved version: $LATEST_TAG" |
77 | 88 |
|
78 | 89 | DOWNLOAD_URL="$GITHUB_URL/releases/download/$LATEST_TAG/$BINARY_NAME" |
79 | 90 |
|
|
0 commit comments