用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...

相关推荐
高频因子挖掘机5 分钟前
量化回测前的数据审计:如何判断股票历史行情是否缺失、重复或存在偏差
后端·github·api
亿道电子Emdoor8 分钟前
【Perforce】Klocwork-kwgcheck图形化界面无法打开如何解决
git·python·github
深蓝AI9 小时前
GitHub的Push一年涨4.9倍:AI Agent为什么逼它重做Git存储?
人工智能·github
zhengqweasd13 小时前
机房托管服务器怎么选硬盘,机械盘和 SSD 托管场景差异
运维·服务器·github
七牛云行业应用15 小时前
OpenCode 报错 Rate limit exceeded:限流原因、日志定位与修复步骤(2026 年 10 月)
人工智能·github
SL_staff15 小时前
目标健康度自检清单:开发者视角下的目标-计划-任务链路断点诊断
java·开源·github
SL_staff16 小时前
设备越多系统越崩?根源在三层抽象失效
spring boot·物联网·github
北极象17 小时前
Adobe全家桶被AI克隆,github地址
adobe·github
来自于狂人19 小时前
GitHub 开源趋势日报 | 2026年10月9日
开源·github