Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ecd9933c0f | |||
| 71e34a57f1 | |||
| a0fa32bdba | |||
| 61d2189f21 | |||
| 24d5caef5a | |||
| 415ddc7110 |
@@ -47,16 +47,40 @@ jobs:
|
||||
REPO: ${{ github.repository }}
|
||||
REF: ${{ github.ref }}
|
||||
SHA: ${{ github.sha }}
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
TOKEN: ${{ gitea.token }}
|
||||
USER_TOKEN: ${{ secrets.token }}
|
||||
run: |
|
||||
git config --global init.defaultBranch main
|
||||
if [ -f "$GITHUB_WORKSPACE/Dockerfile" ]; then exit 0; fi
|
||||
mkdir -p "$GITHUB_WORKSPACE"
|
||||
cd "$GITHUB_WORKSPACE"
|
||||
git init .
|
||||
if [ -z "$TOKEN" ]; then
|
||||
git fetch --depth=1 "$SERVER/$REPO.git" "$REF"
|
||||
|
||||
# 优先使用 gitea.token (TOKEN)
|
||||
AUTH_TOKEN="$TOKEN"
|
||||
USE_BASIC_AUTH="false"
|
||||
|
||||
if [ -n "$TOKEN" ]; then
|
||||
echo "Using gitea.token for authentication (Basic Auth)."
|
||||
USE_BASIC_AUTH="true"
|
||||
elif [ -n "$USER_TOKEN" ]; then
|
||||
AUTH_TOKEN="$USER_TOKEN"
|
||||
USE_BASIC_AUTH="true"
|
||||
echo "Using secrets.token for authentication (Basic Auth)."
|
||||
else
|
||||
git -c http.extraHeader="Authorization: Bearer $TOKEN" fetch --depth=1 "$SERVER/$REPO.git" "$REF"
|
||||
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
|
||||
# 使用 Gitea 支持的 Basic Auth: https://x-access-token:token@gitea.domain/user/repo.git
|
||||
# 去掉 SERVER 中的 https:// 或 http:// 前缀以构建正确的 URL
|
||||
CLEAN_SERVER=$(echo "$SERVER" | sed -E 's/^\s*.*:\/\///g')
|
||||
git fetch --depth=1 "https://x-access-token:$AUTH_TOKEN@$CLEAN_SERVER/$REPO.git" "$REF"
|
||||
else
|
||||
# 使用 Bearer Token 进行认证
|
||||
git -c http.extraHeader="Authorization: Bearer $AUTH_TOKEN" fetch --depth=1 "$SERVER/$REPO.git" "$REF"
|
||||
fi
|
||||
git checkout FETCH_HEAD
|
||||
- name: Derive version
|
||||
|
||||
Reference in New Issue
Block a user