From ac8a7816567344f48d97e86cd2c7a9ed2a43bcd1 Mon Sep 17 00:00:00 2001 From: csh Date: Mon, 20 Jul 2026 16:39:08 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20refactor(ci):=20=E5=B0=86=20GIT=5FC?= =?UTF-8?q?ONFIG=20=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=86=85=E8=81=94=20-c=20=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除三个 workflow env 段的 GIT_CONFIG_COUNT/KEY/VALUE 变量 - 在需要认证的 git 命令上内联 -c credential.helper/interactive - prepare fetch、stats 两处 push、release push 各自内联 - 保留 ACCESS_TOKEN,helper 运行时取用 --- .gitea/workflows/changelog_and_release.yml | 12 ++++-------- .gitea/workflows/prepare.yml | 13 +++++-------- .gitea/workflows/update_stats_badge.yml | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.gitea/workflows/changelog_and_release.yml b/.gitea/workflows/changelog_and_release.yml index 55c5572..348ce87 100644 --- a/.gitea/workflows/changelog_and_release.yml +++ b/.gitea/workflows/changelog_and_release.yml @@ -30,13 +30,6 @@ env: # - GIT_TOKEN: 用于 git push # - API_TOKEN: 用于 API 调用 ACCESS_TOKEN: ${{ secrets.WORKFLOW }} - GIT_CONFIG_COUNT: "3" - GIT_CONFIG_KEY_0: "credential.helper" - GIT_CONFIG_VALUE_0: "" - GIT_CONFIG_KEY_1: "credential.helper" - GIT_CONFIG_VALUE_1: '!f() { test "$1" = get || exit 0; printf "%s\n" username=oauth2; printf "%s\n" "password=${ACCESS_TOKEN}"; }; f' - GIT_CONFIG_KEY_2: "credential.interactive" - GIT_CONFIG_VALUE_2: "never" # ===== 工作区配置 ===== WORKSPACE_ROOT: "/data/workspace" @@ -906,7 +899,10 @@ jobs: git commit -m "${{ env.COMMIT_MSG }}" echo "📤 推送到远程 ${{ env.MAIN_BRANCH }} 分支..." - if git -C "${{ env.REPO_DIR }}" push origin "${{ env.MAIN_BRANCH }}"; then + if git -c credential.helper= \ + -c 'credential.helper=!f() { test "$1" = get || exit 0; printf "%s\n" username=oauth2; printf "%s\n" "password=${ACCESS_TOKEN}"; }; f' \ + -c credential.interactive=never \ + -C "${{ env.REPO_DIR }}" push origin "${{ env.MAIN_BRANCH }}"; then echo "✅ 推送成功" else echo "❌ 推送失败" diff --git a/.gitea/workflows/prepare.yml b/.gitea/workflows/prepare.yml index b5b1d92..c15134e 100644 --- a/.gitea/workflows/prepare.yml +++ b/.gitea/workflows/prepare.yml @@ -10,13 +10,6 @@ concurrency: env: ACCESS_TOKEN: ${{ secrets.WORKFLOW }} - GIT_CONFIG_COUNT: "3" - GIT_CONFIG_KEY_0: "credential.helper" - GIT_CONFIG_VALUE_0: "" - GIT_CONFIG_KEY_1: "credential.helper" - GIT_CONFIG_VALUE_1: '!f() { test "$1" = get || exit 0; printf "%s\n" username=oauth2; printf "%s\n" "password=${ACCESS_TOKEN}"; }; f' - GIT_CONFIG_KEY_2: "credential.interactive" - GIT_CONFIG_VALUE_2: "never" WORKSPACE_ROOT: "/data/workspace" jobs: @@ -155,7 +148,11 @@ jobs: git --git-dir="$REPOSITORY_DIR" remote add origin "$REMOTE_URL" fi - git --git-dir="$REPOSITORY_DIR" fetch \ + git \ + -c credential.helper= \ + -c 'credential.helper=!f() { test "$1" = get || exit 0; printf "%s\n" username=oauth2; printf "%s\n" "password=${ACCESS_TOKEN}"; }; f' \ + -c credential.interactive=never \ + --git-dir="$REPOSITORY_DIR" fetch \ --prune --prune-tags --tags --force origin \ '+refs/heads/*:refs/remotes/origin/*' diff --git a/.gitea/workflows/update_stats_badge.yml b/.gitea/workflows/update_stats_badge.yml index c05b388..051cb9e 100644 --- a/.gitea/workflows/update_stats_badge.yml +++ b/.gitea/workflows/update_stats_badge.yml @@ -17,13 +17,6 @@ env: # ===== Token 配置 ===== # 请在 Settings -> Secrets 中配置 WORKFLOW secret ACCESS_TOKEN: ${{ secrets.WORKFLOW }} - GIT_CONFIG_COUNT: "3" - GIT_CONFIG_KEY_0: "credential.helper" - GIT_CONFIG_VALUE_0: "" - GIT_CONFIG_KEY_1: "credential.helper" - GIT_CONFIG_VALUE_1: '!f() { test "$1" = get || exit 0; printf "%s\n" username=oauth2; printf "%s\n" "password=${ACCESS_TOKEN}"; }; f' - GIT_CONFIG_KEY_2: "credential.interactive" - GIT_CONFIG_VALUE_2: "never" # ===== 工作区配置 ===== WORKSPACE_ROOT: "/data/workspace" @@ -287,7 +280,11 @@ jobs: git commit -m ":bar_chart: chore(stats): 初始化统计分支" # 推送到远程 - git -C "${{ env.REPO_DIR }}" push origin "${{ env.BADGE_BRANCH }}" + git -C "${{ env.REPO_DIR }}" \ + -c credential.helper= \ + -c 'credential.helper=!f() { test "$1" = get || exit 0; printf "%s\n" username=oauth2; printf "%s\n" "password=${ACCESS_TOKEN}"; }; f' \ + -c credential.interactive=never \ + push origin "${{ env.BADGE_BRANCH }}" echo "✅ 统计分支创建完成" echo "======================================" @@ -522,7 +519,11 @@ jobs: echo "📤 推送到远程 ${{ env.BADGE_BRANCH }} 分支..." # 推送到远程(使用 TOKEN) - if git -C "${{ env.REPO_DIR }}" push origin "${{ env.BADGE_BRANCH }}"; then + if git -C "${{ env.REPO_DIR }}" \ + -c credential.helper= \ + -c 'credential.helper=!f() { test "$1" = get || exit 0; printf "%s\n" username=oauth2; printf "%s\n" "password=${ACCESS_TOKEN}"; }; f' \ + -c credential.interactive=never \ + push origin "${{ env.BADGE_BRANCH }}"; then echo "✅ 推送成功" echo "changed=true" >> $GITHUB_OUTPUT else