Travis CI - Swift 包管理 - 结帐已经存在? [英] Travis CI - Swift Package Manage - checkout already exists?

查看:29
本文介绍了Travis CI - Swift 包管理 - 结帐已经存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在配置为使用 Swift 包管理器的项目中设置示例项目,但出现奇怪的错误.

Attempting to setup a sample project within a project that is configured to use Swift Package Manager and getting a strange error.

项目结构:

MyProject/
    - Package.swift
    MyProject/
        - etc...
    Samples/
        - MySampleProject/

Swift 包存储库设置:

MySampleProject 设置为使用应该存在于 travis 作业中的本地 Swift 包:

MySampleProject is set up to use a local Swift package that should exist in the travis job:

file:///Users/travis/build/MyProject/MyProject <- 指向分支:HEAD

Travis 构建命令:

travis 脚本 cd 进入 Sample/MySampleProject 并运行:

The travis script cd's into Sample/MySampleProject and runs:

xcodebuild clean build -target MySampleProject -sdk iphonesimulator

错误:

在运行过程中,travis 声称该包的检出已经存在.

During the run, travis is claiming the checkout of the package already exists.

来自日志:

Resolve Package Graph

Fetching /Users/travis/build/<namespace>/MyProject

Cloning /Users/travis/build/<namespace>/MyProject

xcodebuild: error: Could not resolve package dependencies:

  An unknown error occurred. '/Users/travis/Library/Developer/Xcode/DerivedData/MySampleProject-agdvdspgtwakvignsmkkrkoxijnm/SourcePackages/checkouts/MyProject' exists and is not an empty directory (-4)

这在本地有效.为什么结帐已经存在于 travis 构建的派生数据中?我没有运行任何特殊命令来修改有关 SPM 的任何内容.

This works locally. Why would the checkout already be present in derived data for the travis builds? I'm not running any special commands to modify anything regarding SPM.

推荐答案

需要注意的两点:

  1. 错误信息非常具有误导性.如果实际上没有提交拉取,您将收到此错误消息.

  1. The error message is very misleading. You will get this error message if there is not actually a commit to pull.

一位同事指出,Travis 实际上是在使用 refs/pull/$TRAVIS_PULL_REQUEST/merge 作为 $TRAVIS_COMMIT

A coworker pointed out that Travis is actually using refs/pull/$TRAVIS_PULL_REQUEST/merge for the value of $TRAVIS_COMMIT

完整解决方案:

在plist中找到对应XCRemoteSwiftPackageReference的对象您可以通过在文本编辑器中打开 YourProject.xcodeproj/project.pbxproj 并搜索 XCRemoteSwiftPackageReference 来找到它.获取 ID,因为您需要在构建步骤中对其进行硬编码.

Full solution:

Find the object in the plist that corresponds to XCRemoteSwiftPackageReference You can find this by opening YourProject.xcodeproj/project.pbxproj in a text editor and searching for XCRemoteSwiftPackageReference. Grab the ID since you'll need to hardcode it in your build step.

注意:如果您删除并重新添加程序包,则需要更新它.

Note: You'll need to update this if you remove and re-add the package.

接下来使用 PlistBuddy 将分支更新为拉取请求的合并引用.

Next use PlistBuddy to update the branch to be the merge ref for the pull request.

    echo "Updating project file to point to merge commit at: refs/pull/$TRAVIS_PULL_REQUEST/merge"
    /usr/libexec/PlistBuddy \
        -c "set :objects:F4CEA53E23C29C9E0086EB16:requirement:branch refs/pull/$TRAVIS_PULL_REQUEST/merge" \
        YourProject.xcodeproj/project.pbxproj

    # Redirecting to /dev/null because we only care about errors here and the full output drowns Travis
    xcodebuild build -scheme YourScheme \
      -sdk iphonesimulator > /dev/null
  }

这篇关于Travis CI - Swift 包管理 - 结帐已经存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆