From d929f952cf9c4e505f38d0aec3efbf5f32162818 Mon Sep 17 00:00:00 2001 From: MerCry Date: Tue, 24 Feb 2026 10:50:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=9D=E5=A7=8B=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=20=E9=80=82=E9=85=8Dgitea[AC-INIT]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/pr-check.yaml | 23 +++++++++++++++-------- scripts/check-openapi-diff.sh | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/pr-check.yaml b/.gitea/workflows/pr-check.yaml index f5fe2b3..0e66a5c 100644 --- a/.gitea/workflows/pr-check.yaml +++ b/.gitea/workflows/pr-check.yaml @@ -21,19 +21,26 @@ jobs: SERVER_URL="${GITHUB_SERVER_URL:-${GITEA_SERVER_URL:-}}" REPO_NAME="${GITHUB_REPOSITORY:-${GITEA_REPOSITORY:-}}" COMMIT_SHA="${GITHUB_SHA:-${GITEA_SHA:-}}" - - # Try to get URL from git remote if env vars are missing - if [ -z "$SERVER_URL" ] || [ -z "$REPO_NAME" ]; then - echo "Warning: Env vars missing, attempting to detect from remote..." - fi + + : "${SERVER_URL:?Could not determine SERVER_URL}" + : "${REPO_NAME:?Could not determine REPO_NAME}" + : "${COMMIT_SHA:?Could not determine COMMIT_SHA}" echo "Using SERVER_URL=$SERVER_URL" echo "Using REPO_NAME=$REPO_NAME" echo "Using COMMIT_SHA=$COMMIT_SHA" - git clone "$SERVER_URL/$REPO_NAME.git" . - git fetch origin main:main - git checkout "$COMMIT_SHA" + if [ -d ".git" ]; then + echo "Repo already initialized in workspace; using fetch" + git remote set-url origin "$SERVER_URL/$REPO_NAME.git" + else + git clone "$SERVER_URL/$REPO_NAME.git" . + fi + + # 关键:不要把 main fetch 到本地分支 main(会冲突) + git fetch origin main:refs/remotes/origin/main + git fetch --depth=1 origin "$COMMIT_SHA" + git checkout -f "$COMMIT_SHA" - name: 1. OpenAPI Contract Level Check env: diff --git a/scripts/check-openapi-diff.sh b/scripts/check-openapi-diff.sh index 3a01c99..b8de879 100644 --- a/scripts/check-openapi-diff.sh +++ b/scripts/check-openapi-diff.sh @@ -7,7 +7,7 @@ set -eu # 3. Fail if breaking changes are found without explicit developer acknowledgement. # Base branch to compare against -BASE_BRANCH="main" +BASE_BRANCH="refs/remotes/origin/main" die() { echo "ERROR: $*" >&2