You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter GitHub Actions配置SSH后私有Git依赖仍报‘Repository not found’错误求助

Flutter GitHub Actions配置SSH后私有Git依赖仍报‘Repository not found’错误求助

大家好,我最近在折腾用GitHub Actions部署Flutter Web应用时遇到了一个棘手的问题:执行flutter pub get拉取私有GitHub仓库作为Git依赖时总是失败,提示仓库找不到,但我明明已经正确配置并加载了SSH密钥到SSH代理里了。

错误信息

执行flutter pub get时的错误输出如下:

Resolving dependencies...
Git error.
Command: `git clone --mirror git@github.com:myorg/my_shared_ui.git /home/runner/.pub-cache/_temp/dirXXXXXX`
stdout:
stderr: Cloning into bare repository '/home/runner/.pub-cache/_temp/dirXXXXXX'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
exit code: 128
Failed to update packages.
Error: Process completed with exit code 69.

仓库与依赖结构

  • 主仓库:flutter_app(私有),是我要部署的Flutter Web应用
  • 依赖1:core_library(私有),提供核心功能
  • 依赖2:shared_ui(私有),提供共享UI组件,且这个依赖本身也依赖core_library

pubspec.yaml 依赖配置

dependencies:
  flutter:
    sdk: flutter
  core_library:
    git:
      url: git@github.com:myorg/core_library.git
      ref: main
  shared_ui:
    git:
      url: git@github.com:myorg/shared_ui.git
      ref: main

GitHub Actions 工作流配置

name: Deploy Flutter App
on:
  push:
    branches: [ main ]
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Setup SSH Agent
        uses: webfactory/ssh-agent@v0.9.0
        with:
          ssh-private-key: |
            ${{ secrets.CORE_LIBRARY_SSH_KEY }}
            ${{ secrets.SHARED_UI_SSH_KEY }}
      - name: Verify SSH setup
        run: |
          ssh-add -l
          ssh -T git@github.com || echo "SSH test completed"
      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.35.2'
          channel: 'stable'
          cache: true
      - name: Build Flutter app
        run: |
          flutter clean
          flutter pub get --verbose
          flutter build web --release --wasm

SSH密钥配置情况

我为两个私有依赖仓库分别生成了独立的RSA部署密钥:

ssh-keygen -t rsa -b 4096 -m PEM -f ~/.ssh/core_library_key -N "" -C "core_library_deploy_key"
ssh-keygen -t rsa -b 4096 -m PEM -f ~/.ssh/shared_ui_key -N "" -C "shared_ui_deploy_key"
  • 公钥已经分别添加到对应私有仓库的部署密钥中(仅只读权限)
  • 私钥则分别存在GitHub Secrets中:CORE_LIBRARY_SSH_KEY和SHARED_UI_SSH_KEY,包含完整的私钥内容(包括开头和结尾的标识行)

我已经尝试过的方案

  • 更换不同的SSH Agent Action:试过shimataro/ssh-key-action和webfactory/ssh-agent
  • 手动配置SSH config:添加了IdentitiesOnly相关配置
  • Git URL重写:执行git config --global url."git@github.com:".insteadOf "https://github.com/"
  • 环境变量验证:确认SSH_AUTH_SOCK和SSH_AGENT_PID已正确设置
  • 密钥加载方式测试:分别单独加载单个密钥和同时加载两个密钥都试过

最困惑的点

让我百思不得其解的是,以下操作在GitHub Actions的环境里都是成功的:

  • SSH代理显示两个密钥都已加载(ssh-add -l能列出)
  • 执行ssh -T git@github.com能成功验证身份
  • 执行git ls-remote git@github.com:myorg/core_library.git HEAD也能正常返回结果

但偏偏flutter pub get就是报仓库找不到,我怀疑是不是Flutter的pub get没有正确使用SSH代理,或者存在子进程隔离的问题?

想请教大家的问题

  • 要让Flutter的pub get在GitHub Actions里正常使用SSH代理,有没有什么特殊配置?
  • flutter pub get处理SSH认证的方式和普通git命令有什么不一样吗?
  • webfactory/ssh-agent和Flutter依赖之间有没有已知的兼容性问题?
  • 依赖链(shared_ui依赖core_library)会不会导致SSH密钥选择出问题?

我的环境信息:

  • Flutter:3.35.2 stable
  • GitHub Actions:ubuntu-latest
  • SSH Agent:webfactory/ssh-agent@v0.9.0
  • Git依赖使用的是SSH URL(不是HTTPS)

如果大家有任何思路或者替代方案,麻烦告诉我,非常感谢!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 08:54:39