Github 操作:xcodebuild 由于服务器指纹而失败

Github Actions: xcodebuild fails due to server fingerprint

我正在尝试使用 Github 操作构建一个 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

我终于明白了。这似乎是 Xcode 11 (https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes) 中的一个已知问题。

多亏了 post (https://discuss.bitrise.io/t/xcode-11-resolving-packages-fails-with-ssh-fingerprint/10388) 中的 Dosium,我才能够让它工作。

解决方法是运行在运行ning 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

在构建的机器上打开项目。 转到工作区日志。 双击表示包验证失败的红色日志条目。 现在你得到一个 window 要求你信任主机。 相信它,一切顺利。

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

TS 询问了对私有存储库的依赖性问题,但以防万一有人 运行 遇到此问题 public 存储库依赖性,请确保您使用 HTTPS 而不是 SSH 作为该依赖项存储库地址。

示例:

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

而不是

git@github.com:Alamofire/Alamofire.git

尝试添加一个 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 }}

对于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

如果您正在寻找特定于 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

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