19

我正在尝试使用 Github Actions 构建一个 macOS 应用程序。这已经很好地工作了,直到我将我的依赖项迁移到 Swift 包管理器。现在我在构建我的应用程序时收到以下错误:

xcodebuild: error: Could not resolve package dependencies: The server SSH fingerprint failed to verify.

我有一个私有 GitHub 存储库作为我的应用程序中的依赖项,使用 ssh 位置添加为 Swift 包。因此,我需要在Set up ssh-agent步骤中为依赖项添加我的 ssh 密钥。使用步骤手动克隆存储库git clone工作正常,但我需要让它与 xcodebuild 一起使用才能成功构建我的应用程序。

工作流文件

name: Main
on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  build:
    name: Release
    runs-on: macOS-latest
    steps:
      - name: Checkout
        uses: actions/checkout@master
        with:
          fetch-depth: 1
      - name: Set up ssh-agent
        uses: yakuhzi/action-ssh-agent@v1
        with:
          public: ${{ secrets.SSH_PUBLIC_KEY }}
          private: ${{ secrets.SSH_PRIVATE_KEY }}
      - name: Build application
        run: |
          sudo xcode-select -switch /Applications/Xcode_11.app
          xcodebuild -project Application.xcodeproj -scheme Application -configuration Release -derivedDataPath $HOME/Application build
4

7 回答 7

21

最后我想通了。这似乎是 Xcode 11 ( https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes ) 中的一个已知问题。

感谢这篇文章中的 Dosium ( https://discuss.bitrise.io/t/xcode-11-resolving-packages-fails-with-ssh-fingerprint/10388 ),我能够让它工作。

解决方案是在运行 xcodebuild 之前运行以下命令: for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts

于 2019-10-01T13:38:46.333 回答
4

TS 询问了对私有存储库的依赖问题,但以防万一有人遇到公共存储库依赖的问题,请确保对该依赖存储库地址使用 HTTPS 而不是 SSH。

例子:

https://github.com/Alamofire/Alamofire.git

代替

git@github.com:Alamofire/Alamofire.git
于 2020-06-10T05:21:01.107 回答
4

对于CircleCI

添加到 Yakuhzi 的答案中,以下是 Circle Ci 的 yaml 文件中的步骤:

- run:
    name: Enable SSH
    command: |
       for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts
于 2021-01-06T17:17:29.497 回答
3

在进行构建的机器上打开项目。转到工作区日志。双击显示包验证失败的红色日志条目。现在您会看到一个窗口,要求您信任主机。相信它,你很高兴。

编辑:我错了。虽然它确实信任主机并且您可以在 CI 机器上打开并运行项目,但 CI 过程仍然失败......

于 2020-03-27T13:11:21.807 回答
1

Xcode 13中这很容易 - 您只需单击错误,就会出现一个警告,询问您是否信任服务器

于 2021-11-17T09:01:59.030 回答
1

如果您正在寻找特定于 GitHub 操作的内容,我更新了@rob-caraway 的答案以匹配 GitHub 的语法。我找到了以下步骤,在尝试为我构建作品之前插入:

    - name: Trust the GitHub SSH keys
      run: |
        for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts
于 2021-04-03T01:29:42.423 回答
0

尝试添加一个 Github 令牌作为秘密并在结帐步骤中使用它:

build:
    runs-on: macOS-latest
    steps:
    - uses: actions/checkout@v2.3.3
      with: 
        token:  ${{ secrets.YOUR_CI_ACCOUNT_TOKEN }}

或将您的 SSH 私钥添加为秘密并使用它:

build:
    runs-on: macOS-latest
    steps:
    - uses: actions/checkout@v2.3.3
      with: 
        ssh-key:  ${{ secrets.YOUR_CI_ACCOUNT_SSH_KEY }}
于 2020-10-13T17:09:35.747 回答