This commit is contained in:
@@ -56,21 +56,29 @@ jobs:
|
||||
cd "$GITHUB_WORKSPACE"
|
||||
git init .
|
||||
|
||||
# 优先使用 secrets.token (USER_TOKEN),因为 secrets.GITHUB_TOKEN 在某些 Gitea 配置下可能权限受限
|
||||
# 优先使用 secrets.token (USER_TOKEN)
|
||||
AUTH_TOKEN="$TOKEN"
|
||||
USE_BASIC_AUTH="false"
|
||||
|
||||
if [ -n "$USER_TOKEN" ]; then
|
||||
AUTH_TOKEN="$USER_TOKEN"
|
||||
echo "Using secrets.token for authentication."
|
||||
USE_BASIC_AUTH="true"
|
||||
echo "Using secrets.token for authentication (Basic Auth)."
|
||||
elif [ -n "$TOKEN" ]; then
|
||||
echo "Using secrets.GITHUB_TOKEN for authentication."
|
||||
echo "Using secrets.GITHUB_TOKEN for authentication (Bearer Header)."
|
||||
else
|
||||
echo "Warning: No token found. Attempting unauthenticated fetch (will fail for private repos)."
|
||||
fi
|
||||
|
||||
if [ -z "$AUTH_TOKEN" ]; then
|
||||
git fetch --depth=1 "$SERVER/$REPO.git" "$REF"
|
||||
elif [ "$USE_BASIC_AUTH" = "true" ]; then
|
||||
# 使用 Basic Auth: https://token:x-oauth-basic@gitea.com/user/repo.git
|
||||
# 去掉 SERVER 中的 https:// 或 http:// 前缀以构建正确的 URL
|
||||
CLEAN_SERVER=$(echo "$SERVER" | sed -E 's/^\s*.*:\/\///g')
|
||||
git fetch --depth=1 "https://$AUTH_TOKEN:x-oauth-basic@$CLEAN_SERVER/$REPO.git" "$REF"
|
||||
else
|
||||
# 使用 Bearer Token 进行认证
|
||||
# 使用 Bearer Token 进行认证 (GITHUB_TOKEN)
|
||||
git -c http.extraHeader="Authorization: Bearer $AUTH_TOKEN" fetch --depth=1 "$SERVER/$REPO.git" "$REF"
|
||||
fi
|
||||
git checkout FETCH_HEAD
|
||||
|
||||
Reference in New Issue
Block a user