Skip to content

Commit bfdf388

Browse files
chore: sync actions from gh-aw@v0.65.3 (#60)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b5ca536 commit bfdf388

File tree

1 file changed

+9
-104
lines changed

1 file changed

+9
-104
lines changed

setup-cli/install.sh

Lines changed: 9 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
# Script to download and install gh-aw binary for the current OS and architecture
44
# Supports: Linux, macOS (Darwin), FreeBSD, Windows (Git Bash/MSYS/Cygwin)
5-
# Usage: ./install-gh-aw.sh [version] [options]
6-
# If no version is specified, it will use "stable" (resolved from .github/aw/releases.json)
7-
# Version aliases (e.g. "stable", "latest") are resolved via .github/aw/releases.json before download.
5+
# If no version is specified, it will use "latest"
86
# Note: Checksum validation is currently skipped by default (will be enabled in future releases)
97
#
8+
# Usage: ./install.sh [version] [options]
9+
#
1010
# Examples:
11-
# ./install-gh-aw.sh # Install stable version
12-
# ./install-gh-aw.sh latest # Install latest version
13-
# ./install-gh-aw.sh v1.0.0 # Install specific version
14-
# ./install-gh-aw.sh --skip-checksum # Skip checksum validation
11+
# ./install.sh # Install latest version
12+
# ./install.sh v1.0.0 # Install specific version
13+
# ./install.sh --skip-checksum # Skip checksum validation
1514
#
1615
# Options:
1716
# --skip-checksum Skip checksum verification
@@ -83,12 +82,6 @@ if ! command -v curl &> /dev/null; then
8382
exit 1
8483
fi
8584

86-
# Check if jq is available (optional, we'll use grep/sed as fallback)
87-
HAS_JQ=false
88-
if command -v jq &> /dev/null; then
89-
HAS_JQ=true
90-
fi
91-
9285
# Check if sha256sum or shasum is available (for checksum verification)
9386
HAS_CHECKSUM_TOOL=false
9487
CHECKSUM_CMD=""
@@ -170,105 +163,17 @@ print_info "Detected OS: $OS -> $OS_NAME"
170163
print_info "Detected architecture: $ARCH -> $ARCH_NAME"
171164
print_info "Platform: $PLATFORM"
172165

173-
# Function to fetch release data with fallback for invalid token and retry logic
174-
fetch_release_data() {
175-
local url=$1
176-
local max_retries=3
177-
local retry_delay=2
178-
local use_auth=false
179-
180-
# Try with authentication if GH_TOKEN is set
181-
if [ -n "$GH_TOKEN" ]; then
182-
use_auth=true
183-
fi
184-
185-
# Retry loop
186-
for attempt in $(seq 1 $max_retries); do
187-
local curl_args=("-s" "-f")
188-
189-
# Add auth header if using authentication
190-
if [ "$use_auth" = true ]; then
191-
curl_args+=("-H" "Authorization: Bearer $GH_TOKEN")
192-
fi
193-
194-
print_info "Fetching release data (attempt $attempt/$max_retries)..." >&2
195-
196-
# Make the API call
197-
local response
198-
response=$(curl "${curl_args[@]}" "$url" 2>/dev/null)
199-
local exit_code=$?
200-
201-
# Success
202-
if [ $exit_code -eq 0 ] && [ -n "$response" ]; then
203-
echo "$response"
204-
return 0
205-
fi
206-
207-
# If this was the first attempt with auth and it failed, try without auth
208-
if [ "$attempt" -eq 1 ] && [ "$use_auth" = true ]; then
209-
print_warning "API call with GH_TOKEN failed. Retrying without authentication..." >&2
210-
print_warning "Your GH_TOKEN may be incompatible (typically SSO) with this request." >&2
211-
use_auth=false
212-
# Don't count this as a retry attempt, just switch auth mode
213-
continue
214-
fi
215-
216-
# If we haven't exhausted retries, wait and try again
217-
if [ "$attempt" -lt "$max_retries" ]; then
218-
print_warning "Fetch attempt $attempt failed (exit code: $exit_code). Retrying in ${retry_delay}s..." >&2
219-
sleep $retry_delay
220-
retry_delay=$((retry_delay * 2))
221-
else
222-
print_error "Failed to fetch release data after $max_retries attempts" >&2
223-
fi
224-
done
225-
226-
return 1
227-
}
228-
229-
# Get version (use provided version or default to "stable")
166+
# Get version (use provided version or default to "latest")
230167
# VERSION is already set from argument parsing
231168
REPO="github/gh-aw"
232169

233170
if [ -z "$VERSION" ]; then
234-
print_info "No version specified, using 'stable'..."
235-
VERSION="stable"
171+
print_info "No version specified, using 'latest'..."
172+
VERSION="latest"
236173
else
237174
print_info "Using specified version: $VERSION"
238175
fi
239176

240-
# Resolve version aliases from releases.json
241-
RELEASES_JSON_URL="https://raw.githubusercontent.com/$REPO/main/.github/aw/releases.json"
242-
print_info "Resolving version alias '$VERSION' from $RELEASES_JSON_URL..."
243-
244-
releases_json=""
245-
releases_json=$(curl -s -f "$RELEASES_JSON_URL" 2>/dev/null) || true
246-
247-
if [ -n "$releases_json" ]; then
248-
resolved_version=""
249-
if [ "$HAS_JQ" = true ]; then
250-
resolved_version=$(echo "$releases_json" | jq -r ".aliases[\"$VERSION\"] // empty" 2>/dev/null) || {
251-
print_info "jq failed to parse releases.json; alias resolution skipped"
252-
}
253-
else
254-
# Fallback: extract alias value using grep/sed
255-
# Escape regex special characters in VERSION to avoid unintended matches
256-
version_escaped=$(printf '%s' "$VERSION" | sed 's/[.[\*^$]/\\&/g')
257-
resolved_version=$(echo "$releases_json" | grep -o "\"${version_escaped}\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" | sed 's/.*:[[:space:]]*"\([^"]*\)"/\1/' | head -1) || true
258-
fi
259-
260-
if [ -n "$resolved_version" ] && [ "$resolved_version" != "$VERSION" ]; then
261-
print_info "Resolved alias '$VERSION' -> '$resolved_version'"
262-
VERSION="$resolved_version"
263-
elif [ -n "$resolved_version" ]; then
264-
print_warning "Version '$VERSION' is an alias for itself in releases.json (no change); this may indicate a misconfiguration"
265-
else
266-
print_info "No alias found for '$VERSION', using it as-is"
267-
fi
268-
else
269-
print_warning "Could not fetch releases.json; proceeding with version '$VERSION' as-is"
270-
fi
271-
272177
# Try gh extension install if requested (and gh is available)
273178
if [ "$TRY_GH_INSTALL" = true ] && command -v gh &> /dev/null; then
274179
print_info "Attempting to install gh-aw using 'gh extension install'..."

0 commit comments

Comments
 (0)