Skip to content

Commit c6d1fe2

Browse files
lpcoxCopilot
andcommitted
fix: use gh CLI and Bearer auth for setup action latest version fetch
The 'Test Action (Latest Version)' CI job fails with HTTP 403 when fetching the latest release via the GitHub API. The root cause is that the action uses 'Authorization: token' header format, which can be rejected on internal repositories. Fix: - Use gh CLI (pre-installed on runners) as primary method for resolving the latest release — it handles auth natively - Fall back to curl with the modern 'Authorization: Bearer' format and proper Accept/API-Version headers - Both approaches use the GITHUB_TOKEN already available in the env Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2aac716 commit c6d1fe2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

action.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ runs:
5454
BINARY_NAME="awf-linux-x64"
5555
INSTALL_DIR="${RUNNER_TEMP}/awf-bin"
5656
57-
# Build auth header for GitHub API to avoid rate limits
57+
# Build auth headers for GitHub API (Bearer is the recommended format for GITHUB_TOKEN)
5858
AUTH_HEADER=()
5959
if [ -n "${GITHUB_TOKEN:-}" ]; then
60-
AUTH_HEADER=(-H "Authorization: token ${GITHUB_TOKEN}")
60+
AUTH_HEADER=(-H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28")
6161
fi
6262
6363
# Create install directory
@@ -66,11 +66,18 @@ runs:
6666
# Determine version
6767
if [ "$INPUT_VERSION" = "latest" ] || [ -z "$INPUT_VERSION" ]; then
6868
echo "Fetching latest release version..."
69-
# Use jq if available, fallback to grep/sed
70-
if command -v jq &> /dev/null; then
71-
VERSION=$(curl -fsSL "${AUTH_HEADER[@]}" "https://api.github.com/repos/${REPO}/releases/latest" | jq -r '.tag_name')
72-
else
73-
VERSION=$(curl -fsSL "${AUTH_HEADER[@]}" "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
69+
VERSION=""
70+
# Try gh CLI first (pre-installed on GitHub Actions runners, handles auth natively)
71+
if command -v gh &> /dev/null && [ -n "${GITHUB_TOKEN:-}" ]; then
72+
VERSION=$(gh api "repos/${REPO}/releases/latest" --jq '.tag_name' 2>/dev/null || true)
73+
fi
74+
# Fall back to curl with GitHub API
75+
if [ -z "${VERSION:-}" ] || [ "$VERSION" = "null" ]; then
76+
if command -v jq &> /dev/null; then
77+
VERSION=$(curl -fsSL "${AUTH_HEADER[@]}" "https://api.github.com/repos/${REPO}/releases/latest" | jq -r '.tag_name')
78+
else
79+
VERSION=$(curl -fsSL "${AUTH_HEADER[@]}" "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
80+
fi
7481
fi
7582
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
7683
echo "::error::Failed to fetch latest version from GitHub API"

0 commit comments

Comments
 (0)