♻️ refactor(ci): 将 GIT_CONFIG 环境变量改为内联 -c 认证

- 删除三个 workflow env 段的 GIT_CONFIG_COUNT/KEY/VALUE 变量
- 在需要认证的 git 命令上内联 -c credential.helper/interactive
- prepare fetch、stats 两处 push、release push 各自内联
- 保留 ACCESS_TOKEN,helper 运行时取用
This commit is contained in:
csh
2026-07-20 16:39:08 +08:00
parent 2dcf9f7da4
commit ac8a781656
3 changed files with 19 additions and 25 deletions
+4 -8
View File
@@ -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 "❌ 推送失败"
+5 -8
View File
@@ -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/*'
+10 -9
View File
@@ -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