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

相关推荐
逛逛GitHub3 小时前
国产AI大模型 Minimax M2.1效果相当惊艳,赶紧试试
github
-拟墨画扇-4 小时前
Git | 文件提交操作
git·gitee·github·gitcode
<e^πi+1=0>4 小时前
Docker部署Lighthouse CI Server总结
ci/cd·docker·容器
CoderJia程序员甲4 小时前
GitHub 热榜项目 - 日榜(2025-12-25)
git·ai·开源·llm·github
A13247053125 小时前
进程管理入门:查看和控制Linux进程
linux·运维·服务器·网络·chrome·github
深兰科技5 小时前
深兰科技入选“2025中国新经济30强(行业之星)”,人工智能产业化能力获认可
人工智能·windows·ci/cd·phpstorm·visual studio code·深兰科技·gyic2025
-拟墨画扇-5 小时前
Git | 文件修改操作
大数据·git·gitee·github·gitcode
-拟墨画扇-5 小时前
Git | 版本控制操作
大数据·git·gitee·github
一条闲鱼_mytube5 小时前
GitHub K8S CI/CD 部署指南
github
lyx_20166 小时前
尝试理清楚Github fork, tag, release和PR
github