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

相关推荐
一点一木4 小时前
🚀 2026 年 6 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
OpenTiny社区1 天前
从零开发 AI 聊天页要两周?试试这款 Vue3 垂直对话组件库 TinyRobot,直接开箱即用
前端·vue.js·github
逛逛GitHub1 天前
2 万多 Star!Google 开源了这个神级 GitHub 项目。
github
逛逛GitHub1 天前
免费 Token 烧掉 5 万亿之后,他们出了个一站式创作平台。
github
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
inhere1 天前
eget:不用等中央仓库,直接安装 GitHub 和任意下载站的工具
程序员·开源·github
YuePeng2 天前
写了五年注解的低代码框架,2.0 决定让你连注解都不用写了
github·产品
小白ai2 天前
从"能 ping 通吗"到"为什么上不了网"——我写了一个网络故障诊断引擎
github
徐小夕2 天前
jitword 协同文档3.2发布:打造浏览器中最强word编辑器
前端·架构·github
齐翊2 天前
分享一个在 Claude Code 里 [同时] 用多个 ApiKey 的方法
程序员·github·agent