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

相关推荐
小年糕是糕手1 小时前
【C++】类和对象(六) -- 友元、内部类、匿名对象、对象拷贝时的编译器优化
开发语言·c++·算法·pdf·github·排序算法
ylmzfun2 小时前
CI/CD技术全景解析:从理念到高效落地的自动化流水线
运维·ci/cd·自动化
dragoooon343 小时前
[Linux网络基础——Lesson9.「TCP 全连接队列与 tcpdump 抓包」]
前端·git·github
多想和从前一样3 小时前
GitHub Desktop提交文件报错:连接问题
github
CPU NULL4 小时前
Claude Code/Codex在WSL下粘贴图片的工具
github·开源软件
一勺-_-4 小时前
如何在本地把文件上传到GitHub(超过2个G)
github
熊猫钓鱼>_>6 小时前
CI/CD 配置完全指南:从零开始构建自动化流水线
servlet·ci/cd·自动化
CoderJia程序员甲21 小时前
GitHub 热榜项目 - 日榜(2025-12-4)
ai·开源·大模型·github·ai教程
青瓷看世界21 小时前
鸿蒙开发时AI编程工具codeGenie与Github Copilot的区别
github·copilot·ai编程·harmonyos·codegenie