🔧 统一 stats workflow 的 token 契约
This commit is contained in:
parent
a4d09c9063
commit
2b5eaf27c9
|
|
@ -10,7 +10,7 @@ on:
|
|||
# ==========================================
|
||||
env:
|
||||
# ===== Token 配置 =====
|
||||
# 建议在 Settings -> Secrets 中配置 STATS_TOKEN 以获得更好的权限控制
|
||||
# 请在 Settings -> Secrets 中配置 WORKFLOW secret
|
||||
ACCESS_TOKEN: ${{ secrets.WORKFLOW }}
|
||||
|
||||
# ===== 工作区配置 =====
|
||||
|
|
@ -98,18 +98,12 @@ jobs:
|
|||
|
||||
if [ -z "${{ env.ACCESS_TOKEN }}" ]; then
|
||||
echo "❌ 错误: 未配置访问令牌"
|
||||
echo "请在 Settings -> Secrets 中配置 STATS_TOKEN 或确保 GITHUB_TOKEN 可用"
|
||||
echo "请在 Settings -> Secrets 中配置 WORKFLOW secret"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检测使用的是哪个 token
|
||||
if [ -n "${{ secrets.STATS_TOKEN }}" ]; then
|
||||
echo "✅ 使用自定义 STATS_TOKEN"
|
||||
echo "token_type=STATS_TOKEN" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "✅ 使用默认 GITHUB_TOKEN"
|
||||
echo "token_type=GITHUB_TOKEN" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
echo "✅ 使用 WORKFLOW secret"
|
||||
echo "token_type=WORKFLOW" >> $GITHUB_OUTPUT
|
||||
|
||||
echo "🔗 仓库: ${{ github.repository }}"
|
||||
echo "🌿 分支: ${{ github.ref_name }}"
|
||||
|
|
@ -736,7 +730,7 @@ jobs:
|
|||
### Token 配置
|
||||
|
||||
- 当前使用: **${{ steps.validate_token.outputs.token_type }}**
|
||||
- 推荐配置自定义 `STATS_TOKEN` 以获得更好的权限控制
|
||||
- 需要在 Settings -> Secrets 中配置 `WORKFLOW`
|
||||
|
||||
### 排除规则
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,16 @@ test_workflows_do_not_hardcode_company_server() {
|
|||
! rg -q 'https://git\.mytsl\.cn' "${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml" || fail "stats workflow should not hardcode company server"
|
||||
}
|
||||
|
||||
test_stats_workflow_uses_workflow_secret_consistently() {
|
||||
local file
|
||||
|
||||
file="${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml"
|
||||
|
||||
grep -q 'ACCESS_TOKEN: ${{ secrets.WORKFLOW }}' "${file}" || fail "stats workflow should read ACCESS_TOKEN from WORKFLOW secret"
|
||||
! rg -q 'STATS_TOKEN' "${file}" || fail "stats workflow should not mention legacy STATS_TOKEN secret"
|
||||
! rg -q 'GITHUB_TOKEN' "${file}" || fail "stats workflow should not mention GITHUB_TOKEN in token guidance"
|
||||
}
|
||||
|
||||
test_preset_env_examples_exist() {
|
||||
local file
|
||||
|
||||
|
|
@ -41,6 +51,7 @@ test_preset_env_examples_exist() {
|
|||
|
||||
test_preset_compose_uses_env_for_instance
|
||||
test_workflows_do_not_hardcode_company_server
|
||||
test_stats_workflow_uses_workflow_secret_consistently
|
||||
test_preset_env_examples_exist
|
||||
|
||||
echo "template_defaults_test.sh: PASS"
|
||||
|
|
|
|||
Loading…
Reference in New Issue