Skip to content

Commit 533876b

Browse files
lpcoxCopilotCopilot
authored
fix: use gh CLI and Bearer auth for setup action latest version fetch (#1921)
* 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> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 2aac716 commit 533876b

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

action.yml

Lines changed: 18 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,22 @@ 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+
if ! VERSION=$(curl -fsSL "${AUTH_HEADER[@]}" "https://api.github.com/repos/${REPO}/releases/latest" | jq -r '.tag_name'); then
78+
VERSION=""
79+
fi
80+
else
81+
if ! VERSION=$(curl -fsSL "${AUTH_HEADER[@]}" "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'); then
82+
VERSION=""
83+
fi
84+
fi
7485
fi
7586
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
7687
echo "::error::Failed to fetch latest version from GitHub API"

0 commit comments

Comments
 (0)