From 5833e71751f2af2caebbcc44c5d2b384a109a21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=AE=E9=9B=A8?= <47820304+PeterGuy326@users.noreply.github.com> Date: Fri, 26 Jun 2026 16:55:04 +0800 Subject: [PATCH] ci(mirror): localize README for the Gitee mirror (#513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Gitee mirror force-pushes main verbatim, so Chinese users saw a README whose top install commands point at raw.githubusercontent.com (hard to reach in China) and a coverage badge that fails to render (the relative .github/badges/coverage.svg can't be served by Gitee — gitee raw returns a signed, expiring URL with content-type text/plain). Add a Gitee-only post-process step: build a gitee-main branch on top of origin/main and rewrite README.md / README_zh.md before pushing — (1) raw.githubusercontent.com//main -> gitee.com//raw/main (2) the coverage badge -> a shields.io static badge whose percentage is read from the repo's coverage.svg and colored by threshold. GitHub's README is untouched; only the Gitee copy is rewritten. The branch is rebuilt from origin/main every run, so it stays a clean single-commit delta and never drifts. --- .github/workflows/mirror-to-gitee.yml | 39 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mirror-to-gitee.yml b/.github/workflows/mirror-to-gitee.yml index 022515cc..c28608f0 100644 --- a/.github/workflows/mirror-to-gitee.yml +++ b/.github/workflows/mirror-to-gitee.yml @@ -31,14 +31,45 @@ jobs: with: fetch-depth: 0 - - name: Push main + tags to Gitee + - name: Push main + tags to Gitee (with README localization) if: env.GITEE_TOKEN != '' run: | set -eu REMOTE="https://${GITEE_USER}:${GITEE_TOKEN}@gitee.com/${GITEE_REPO}.git" # 取到 main 与所有 tag(落到 origin/* 与本地 tags,避免推当前分支引用冲突) git fetch --force --tags origin 'refs/heads/main:refs/remotes/origin/main' - # 镜像对齐(force:Gitee 始终跟随 GitHub) - git push --force "$REMOTE" 'refs/remotes/origin/main:refs/heads/main' + + # Gitee 专属分支:在 origin/main 之上叠加一个 README 本地化 commit。 + # GitHub 那份 README 不变;只有推往 Gitee 的副本被改写。 + git checkout -B gitee-main origin/main + git config user.email "actions@github.com" + git config user.name "github-actions[bot]" + + # 1) 安装命令本地化:raw.githubusercontent → gitee raw(国内可达)。 + for f in README.md README_zh.md; do + [ -f "$f" ] || continue + sed -i "s#raw.githubusercontent.com/${GITEE_REPO}/main#gitee.com/${GITEE_REPO}/raw/main#g" "$f" + done + + # 2) coverage 徽章:仓库内相对路径 svg 在 Gitee 渲染不出来(gitee raw 对 svg + # 返回需签名、会过期的 URL,且 content-type 为 text/plain)。改成 shields.io + # 静态徽章——数值取自仓库 coverage.svg,颜色按覆盖率阈值。 + SVG=".github/badges/coverage.svg" + if [ -f "$SVG" ]; then + PCT="$(grep -oE '[0-9]+(\.[0-9]+)?%' "$SVG" | head -1)" + NUM="${PCT%\%}"; INT="${NUM%.*}" + if [ "${INT:-0}" -ge 80 ]; then C=brightgreen; elif [ "${INT:-0}" -ge 60 ]; then C=yellow; else C=red; fi + BADGE="https://img.shields.io/badge/coverage-${NUM}%25-${C}" + for f in README.md README_zh.md; do + [ -f "$f" ] || continue + sed -i "s#\.github/badges/coverage\.svg#${BADGE}#g" "$f" + done + fi + + git add README.md README_zh.md 2>/dev/null || true + git commit -m "docs(gitee): localize install commands + coverage badge for Gitee mirror" || true + + # 镜像对齐(force:Gitee 始终跟随 GitHub + Gitee 专属 README 本地化) + git push --force "$REMOTE" 'gitee-main:refs/heads/main' git push --force --tags "$REMOTE" - echo "✅ 已镜像 main + tags 到 Gitee ${GITEE_REPO}" + echo "✅ 已镜像 main(+Gitee README 本地化) + tags 到 Gitee ${GITEE_REPO}"