rat*_*bum 15 git xcode circleci swift swift-package-manager
所以背景是这样的:我有一个 Xcode 项目,它依赖于 github 上私有存储库中的 swift 包。当然,这需要密钥才能访问。到目前为止,我已经设法配置 CI,以便我可以 ssh 进入实例和git clone
swift 包所需的存储库。不幸的是,当xcbuild
像 CI 一样运行它时,它不起作用,我收到以下消息:
static:ios distiller$ xcodebuild -showBuildSettings -workspace ./Project.xcworkspace \
-scheme App\ Prod
Resolve Package Graph
Fetching git@github.com:company-uk/ProjectDependency.git
xcodebuild: error: Could not resolve package dependencies:
Authentication failed because the credentials were rejected
Run Code Online (Sandbox Code Playgroud)
相比之下,git clone
会很高兴地获取这个 repo,如下所示:
static:ios distiller$ git clone git@github.com:company-uk/ProjectDependency.git
Cloning into 'ProjectDependency'...
Warning: Permanently added the RSA host key for IP address '11.22.33.44' to the list of known hosts.
remote: Enumerating objects: 263, done.
remote: Counting objects: 100% (263/263), done.
remote: Compressing objects: 100% (171/171), done.
remote: Total 1335 (delta 165), reused 174 (delta 86), pack-reused 1072
Receiving objects: 100% (1335/1335), 1.11 MiB | 5.67 MiB/s, done.
Resolving deltas: 100% (681/681), done.
Run Code Online (Sandbox Code Playgroud)
对于更多上下文,这是在 CircleCI 上运行的,在 GitHub 上使用 Deploy 密钥进行设置,该密钥已添加到 CI 上的作业中。
任何关于 Xcode 尝试获取依赖项的方式与 vanilla git 的方式之间可能不同的建议都会很棒。谢谢。
对于无法登录 GitHub 或其他存储库主机的 CI 管道,这是我发现绕过 Xcode 围绕私有 Swift 包的限制/错误的解决方案。
对私有依赖项使用 https url,因为 ssh 配置当前被 xcodebuild 忽略,即使文档另有说明。
一旦您可以使用 https 在本地构建,请转到您的存储库主机并创建个人访问令牌 (PAT)。可在此处找到 GitHub 说明。
在您的 CI 系统中,将此 PAT 添加为秘密环境变量。在下面的脚本中,它被称为GITHUB_PAT
.
然后在运行之前在 CI 管道中xcodebuild
确保运行此 bash 脚本的适当修改版本:
for FILE in $(grep -Ril "https://github.com/[org_name]" .); do
sed -i '' "s/https:\/\/github.com\/[org_name]/https:\/\/${GITHUB_PAT}@github.com\/[org_name]/g" ${FILE}
done
Run Code Online (Sandbox Code Playgroud)
此脚本将查找所有 https 引用并将 PAT 注入其中,以便无需密码即可使用。
不要忘记:
[org_name]
为您的组织名称。${GITHUB_PAT}
如果您以不同的方式命名,请替换为您的 CI 机密的名称。grep
命令以忽略您不想被脚本修改的任何路径。这似乎是带有 SSH 的 Xcode 11 中的错误。切换到 HTTPS 以解决 Swift Packages 解决了这个问题:
所以从这个:
E29801192303068A00018344 /* XCRemoteSwiftPackageReference "ProjectDependency" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "git@github.com:company-uk/ProjectDependency.git";
requirement = {
branch = "debug";
kind = branch;
};
};
Run Code Online (Sandbox Code Playgroud)
到:
E29801192303068A00018344 /* XCRemoteSwiftPackageReference "ProjectDependency" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/company-uk/ProjectDependency.git";
requirement = {
branch = "debug";
kind = branch;
};
};
Run Code Online (Sandbox Code Playgroud)
此外,现在 Xcode 12 已发布,您可以使用它,它已修复。
归档时间: |
|
查看次数: |
3591 次 |
最近记录: |