用Renovate处理Private Submodules

Renovate不支持Private Submodule

Renovate运行时会自己clone仓库,GitHub Actions中clone的Submodule不会被使用。

而且遗憾的是,cloneSubmodules配置明确说明不支持Private Submodule:

Important: private submodules aren't supported by Renovate, unless the underlying ssh layer already has the correct permissions.

这对于通过路径引用Submodule的包管理工具来说是个问题。虽然可以选择放弃使用Submodule,但我不希望因为Renovate的限制而改变项目结构。

尝试了各种方法后,终于找到了解决方案,在此分享。

需求

  • 希望使用GitHub App认证而非Personal access token。
    • 不想在公司项目使用个人PAT。
  • Submodule有多个,SSH和HTTP混用。
    • 官方文档中提到的SSH层解决方案不足以满足需求。

Dependabot似乎也不支持Personal access token认证。

Self-hosted Renovate

之前一直使用Mend托管的Renovate GitHub App,但这次的配置需要切换到Self-hosted,这里使用GitHub Action Renovate

配置

GitHub App

需要按照Renovate指定的权限进行授权:

Permission Scope
Checks read + write
Commit statuses read + write
Contents read + write
Issues read + write
Pull requests read + write
Workflows read + write
Administration read
Dependabot alerts read
Members read
Metadata read

安装后如需修改权限,需要在安装界面批准新增的权限。

GitHub Repository

首先禁用现有的Renovate GitHub App。然后在Actions secrets and variables中添加以下值,供Renovate Action使用:

类型 名称
Variables App ID GH_APP_ID
Secrets Private key GH_APP_PRIVATE_KEY

GitHub Actions

将以下内容保存为.github/workflows/renovate.yml

yml 复制代码
name: Renovate
on:
  schedule:
    # 每15分钟执行一次
    - cron: "0/15 * * * *"
  workflow_dispatch:
jobs:
  renovate:
    runs-on: ubuntu-latest
    steps:
      - name: Generate github token
        uses: actions/create-github-app-token@v1
        id: app-token
        with:
          app-id: ${{ vars.GH_APP_ID }}
          private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
          owner: ${{ github.repository_owner }}

      - uses: actions/checkout@v4
        with:
          submodules: "recursive"
          token: ${{ steps.app-token.outputs.token }}
          persist-credentials: false

      - name: Self-hosted Renovate
        uses: renovatebot/github-action@v41.0.13
        with:
          configurationFile: self_hosted_renovate.js
          token: ${{ steps.app-token.outputs.token }}
          env-regex: "^(?:RENOVATE_\\w+|LOG_LEVEL|GITHUB_COM_TOKEN|NODE_OPTIONS|GIT_CONFIG_\\w+)$"
        env:
          GIT_CONFIG_COUNT: "2"
          GIT_CONFIG_KEY_0: "url.https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/.insteadOf"
          GIT_CONFIG_VALUE_0: "https://github.com/"
          GIT_CONFIG_KEY_1: "url.https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/.insteadOf"
          GIT_CONFIG_VALUE_1: "git@github.com:"

关键在于env部分的GIT_CONFIG_*。它利用Git的url.<base>.insteadOf配置,将以https://github.com/git@github.com:开头的URL自动替换为带有token的URL。

这样Renovate在clone Submodule时会自动附带认证信息。这与官方文档提到的"ssh层解决方案"类似,都是在Renovate外部解决认证问题。

Renovate configuration

将以下内容编辑后 保存为self_hosted_renovate.js

js 复制代码
module.exports = {
  dependencyDashboard: true,
  onboarding: false,
  requireConfig: "optional",
  branchPrefix: "self-hosted-renovate/",
  // 如果现有Renovate分支导致问题,取消注释此行。
  // branchPrefixOld: "ignore-old-renovate/",
  platform: "github",
  repositories: [
    // 编辑为目标仓库并取消注释。
    // "org_name/repository"
  ],
  cloneSubmodules: true,
};

最后

如果有更优雅的解决方案,欢迎分享。

原文: sijiaoh.com/zh/posts/re...

相关推荐
l1t2 小时前
DeepSeek总结的DuckDB在 CI 中为 release 和 glibc CLI 构建启用 LTO - #24225
开发语言·数据库·ci/cd·duckdb
天天喝旺仔2 小时前
Docker 镜像瘦身实战:多阶段构建把体积缩小 90%
运维·后端·ci/cd·docker·云原生·容器·性能优化
CoderJia程序员甲2 小时前
GitHub 热榜项目 - 周榜(2026-08-30)
ai·大模型·llm·github·ai教程
YuePeng3 小时前
把商业版模块开源了:Erupt 2.1 更新说明
github
u1301304 小时前
GitHub 热榜项目:周榜(2026-08-30)
github
阿里嘎多学长4 小时前
2026-08-30 GitHub 热点项目精选
开发语言·程序员·github·代码托管
wangruofeng14 小时前
Phosphor Icons 官网源码拆解:URL 即存储、水波动画与 7362 Star 图标库的架构实践
前端·架构·github
wangruofeng15 小时前
AI 画架构图总差点意思,archify 给它加了一条验收流水线
架构·github·aigc
林澈在路上17 小时前
AI翻唱软件哪个好 2026国产AI写歌工具对比推荐
大数据·人工智能·深度学习·github·aigc·音视频·音频
百变梦仔20 小时前
Codex 写前端任务时,我用这张 GitHub Skill 地图先选工具
前端·github