From 70022bed8963ce8a7213ad3749f1702b1433a87a Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sun, 26 Jul 2026 13:06:35 +0800 Subject: [PATCH 1/3] fix(ci): #916 improve check-frontend-only: pagination + infra detection + fix empty-line bug --- .gitea/workflows/ci-pipeline.yml | 50 ++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/ci-pipeline.yml b/.gitea/workflows/ci-pipeline.yml index bf5dc6ad5..510f3250d 100755 --- a/.gitea/workflows/ci-pipeline.yml +++ b/.gitea/workflows/ci-pipeline.yml @@ -58,24 +58,56 @@ jobs: run: | set -eu PR_NUMBER=$(echo "$GITHUB_REF" | sed 's|refs/pull/||; s|/.*||') - API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?limit=300" - FILES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$API_URL" | python3 -c "import sys,json; [print(f['filename']) for f in json.load(sys.stdin)]") - FRONTEND_COUNT=$(echo "$FILES" | grep -c '^apps/web/' || true) - BACKEND_COUNT=$(echo "$FILES" | grep -cv '^apps/web/' || true) - TOTAL=$(echo "$FILES" | grep -cv '^$' || true) - echo "变更文件: ${TOTAL} 个 (前端: ${FRONTEND_COUNT}, 后端/公共: ${BACKEND_COUNT})" - if [ "$BACKEND_COUNT" = "0" ] && [ "$FRONTEND_COUNT" -gt "0" ]; then + + # 分页获取所有变更文件(修复>300文件时漏判) + ALL_FILES="" + PAGE=1 + while true; do + API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?limit=300&page=${PAGE}" + PAGE_FILES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$API_URL" | python3 -c "import sys,json; files=json.load(sys.stdin); [print(f['filename']) for f in files]; sys.exit(0 if len(files)==300 else 1)" 2>/dev/null) + HAS_MORE=$? + ALL_FILES="${ALL_FILES}${PAGE_FILES} +" + if [ "$HAS_MORE" != "0" ]; then + break + fi + PAGE=$((PAGE + 1)) + done + + FRONTEND_COUNT=$(echo "$ALL_FILES" | grep -c '^apps/web/' || true) + TOTAL=$(echo "$ALL_FILES" | grep -cv '^$' || true) + BACKEND_COUNT=$(( TOTAL - FRONTEND_COUNT )) + + # 基础设施文件:改了就强制全量CI(不跳过任何检查) + INFRA_COUNT=$(echo "$ALL_FILES" | grep -cE '^(infra/|Dockerfile|\.gitea/workflows/|scripts/ci/|docker/)' || true) + + echo "变更文件: ${TOTAL} 个 (前端: ${FRONTEND_COUNT}, 后端/公共: ${BACKEND_COUNT}, 基础设施: ${INFRA_COUNT})" + + # 判定是否纯前端/纯后端 + PURE_FRONTEND=false + PURE_BACKEND=false + if [ "$BACKEND_COUNT" = "0" ] && [ "$FRONTEND_COUNT" -gt "0" ] && [ "$INFRA_COUNT" = "0" ]; then + PURE_FRONTEND=true + elif [ "$FRONTEND_COUNT" = "0" ] && [ "$BACKEND_COUNT" -gt "0" ] && [ "$INFRA_COUNT" = "0" ]; then + PURE_BACKEND=true + fi + + if [ "$PURE_FRONTEND" = "true" ]; then echo "skip_backend=true" >> $GITHUB_OUTPUT echo "skip_frontend=false" >> $GITHUB_OUTPUT echo "✅ 纯前端改动,跳过后端检查" - elif [ "$FRONTEND_COUNT" = "0" ] && [ "$BACKEND_COUNT" -gt "0" ]; then + elif [ "$PURE_BACKEND" = "true" ]; then echo "skip_backend=false" >> $GITHUB_OUTPUT echo "skip_frontend=true" >> $GITHUB_OUTPUT echo "🔧 纯后端改动,跳过前端检查" else echo "skip_backend=false" >> $GITHUB_OUTPUT echo "skip_frontend=false" >> $GITHUB_OUTPUT - echo "🔧 包含全栈变更,运行完整CI" + if [ "$INFRA_COUNT" -gt "0" ]; then + echo "🏗️ 包含基础设施变更,强制运行完整CI" + else + echo "🔧 包含全栈变更,运行完整CI" + fi fi - name: Report CI trace -- 2.54.0 From 9705f4f449aac7656a794ec8b6f13fd45922622f Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sun, 26 Jul 2026 14:09:20 +0800 Subject: [PATCH 2/3] fix(ci): #916 fix YAML syntax error in check-frontend-only step The multi-line string concatenation had zero-indent closing quote which broke YAML parsing. Replace with $'\n' single-line concatenation. --- .gitea/workflows/ci-pipeline.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitea/workflows/ci-pipeline.yml b/.gitea/workflows/ci-pipeline.yml index d5511ec86..6294f54f6 100755 --- a/.gitea/workflows/ci-pipeline.yml +++ b/.gitea/workflows/ci-pipeline.yml @@ -66,8 +66,7 @@ jobs: API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?limit=300&page=${PAGE}" PAGE_FILES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$API_URL" | python3 -c "import sys,json; files=json.load(sys.stdin); [print(f['filename']) for f in files]; sys.exit(0 if len(files)==300 else 1)" 2>/dev/null) HAS_MORE=$? - ALL_FILES="${ALL_FILES}${PAGE_FILES} -" + ALL_FILES="${ALL_FILES}${PAGE_FILES}"$'\n' if [ "$HAS_MORE" != "0" ]; then break fi -- 2.54.0 From ba481f8ca70e1c2461dcd3efc458e38c3cd24d67 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sun, 26 Jul 2026 15:00:06 +0800 Subject: [PATCH 3/3] fix(ci): #916 fix set -e crash in pagination loop Python sys.exit(1) caused command substitution to fail under set -e. Replace exit-code-based pagination with wc -l line count check, and add || true guard to prevent early exit. --- .gitea/workflows/ci-pipeline.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci-pipeline.yml b/.gitea/workflows/ci-pipeline.yml index 6294f54f6..e834fb87d 100755 --- a/.gitea/workflows/ci-pipeline.yml +++ b/.gitea/workflows/ci-pipeline.yml @@ -64,8 +64,9 @@ jobs: PAGE=1 while true; do API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?limit=300&page=${PAGE}" - PAGE_FILES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$API_URL" | python3 -c "import sys,json; files=json.load(sys.stdin); [print(f['filename']) for f in files]; sys.exit(0 if len(files)==300 else 1)" 2>/dev/null) - HAS_MORE=$? + PAGE_FILES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$API_URL" | python3 -c "import sys,json; files=json.load(sys.stdin); [print(f['filename']) for f in files]; sys.exit(0 if len(files)==300 else 1)" 2>/dev/null || true) + PAGE_COUNT=$(echo "$PAGE_FILES" | wc -l) + if [ "$PAGE_COUNT" -lt 300 ]; then HAS_MORE=1; else HAS_MORE=0; fi ALL_FILES="${ALL_FILES}${PAGE_FILES}"$'\n' if [ "$HAS_MORE" != "0" ]; then break -- 2.54.0