Xcode 使用 CocoaPods 的云项目 shell 脚本在本地构建但在云上失败
Xcode Cloud project with CocoaPods shell script builds locally but fails on cloud
我目前正在测试 Xcode Cloud 作为 Apple 私人测试版计划的成员,并在尝试在云上为我的项目存档/构建(任何操作)时遇到问题。
该项目是一个相当基本的 SwiftUI 应用程序,具有 CocoaPods 依赖项。我按照步骤将 CocoaPods 集成到我的项目 as described by Apple 中,只需将我的 Pods 目录提交到 GitHub。但是,每次尝试操作时,我都会在云上收到构建错误:
Command PhaseScriptExecution failed with a nonzero exit code
这里是ASC日志供参考:
这很奇怪,因为同一个项目在我的本地机器上成功构建和归档。我在工作流编辑器中使用了与本地版本 Xcode.
相同的 macOS 和 Xcode 版本
我该如何解决这个错误?
自定义 shell 脚本限制
TL;DR
Apple 已通过仅启用 shell 脚本 运行 作为 ci_post_clone.sh
、ci_pre_xcodebuild.sh
或 ci_post_xcodebuild.sh
的一部分来锁定其托管基础设施的安全性在 ci_scripts
文件夹中。您的 Pods 项目在此文件夹外有一个自定义 shell 脚本,它不是由这些 CI 脚本之一触发的,因此没有 运行ning 权限。
此特定问题的解决方案是:
- (技术上)重构您的构建脚本阶段以将 shell 脚本文件内联到 运行 脚本中。
- (推荐,但并非总是可行)如果可用,请使用 CocoaPod 的 Swift 包版本。
- (解决方法)将 CocoaPod 降级到没有外部 shell 脚本的版本。
参考
来自 Customize your advanced Xcode Cloud workflows:
If your script doesn't appear to be running when you expect it to,
double-check that you've named it correctly and placed it in a
ci_scripts
folder alongside your project.
...
Lastly, it should be
noted that in a test action, multiple environments are used to build
and run your tests. Only the environment that is used for building
your tests will have your source code cloned into it by default. The
environments that run your tests won't have source code cloned into
them. They'll only have the ci_scripts folder made available on
them. As a result, the post-clone script won't run in these
environments and your custom scripts and any of their dependencies,
such as other shell scripts and small tools, must be entirely
contained within the ci_scripts folder.
允许构建脚本阶段 运行 user-defined 代码 作为构建过程的一部分 ,但是,我们只能 运行 内联 自定义脚本在这里。如前所述,外部 shell 脚本具有受限权限。 运行在移动到 ci_scripts
后绑定外部 shell 脚本文件不起作用。例如"${PODS_ROOT}/../ci_scripts/AppCenter-xcframeworks.sh"
.
虽然此处不相关,但请注意 测试项目的环境不会将源代码克隆到其中。
对于引用自定义脚本文件的测试或其他环境,我们需要在 ci_scripts
文件夹中存储额外的脚本,以确保操作可以访问它。 Apple 只允许 3 个脚本 运行 对应于构建的 3 个阶段:
- 将源代码克隆到构建环境后。
- 在运行宁
xcodebuild
之前。
- 宁运行后
xcodebuild
.
其他 shell 脚本只能 运行 在从 [=13= 中的相应 ci_post_clone.sh
、ci_pre_xcodebuild.sh
或 ci_post_xcodebuild.sh
文件委派后]文件夹。
解决方案 1
我的问题是 运行在构建过程中 shell 使用外部 shell 脚本 。 Apple 确实允许 运行 在 Xcode 云工作流中编写脚本构建阶段,但它们必须内联。因此,作为构建阶段的一部分,我必须对 运行 自定义 Pod shell 脚本执行 4 个步骤:
- 重构您的 Build Phases -> 运行 Script Phase 脚本以内联 shell 脚本文件。
- 清除
DerivedData
后在本地检查项目构建。
- 将您的代码提交到 GitHub / VCS。
- 触发工作流。
解决方案 2(推荐,但并非总是可行)
之后添加 CocoaPod 的 Swift 包版本作为依赖项
解决方案 3(解决方法)
将您的 CocoaPod 降级到没有外部 shell 脚本的版本。
备注
从使用 Xcode Cloud 解决自定义 shell 脚本构建阶段所需的工作量可以看出,我建议在特定 CocoaPod 存储库上提出问题以从自定义 shell 脚本构建阶段迁移=124=]脚本文件。这些步骤使得使用 Xcode Cloud 非常痛苦。
随着 Xcode 云采用率的增长,个别 CocoaPods 完全有可能不再引用自定义 shell 脚本文件。我没有看到苹果开放他们的基础设施来启用任意 shell 脚本执行,因为这是一个安全风险,老实说,其他 CI 供应商也应该被阻止。
我还可以看到像这些包含遗留 CocoaPods 依赖项的麻烦如何加速更多项目迁移到 SPM。 SPM 已经很流行,并且随着 Apple 确保 first-class 集成,它可能会变得更流行。
免责声明: Xcode Cloud 处于私人测试阶段,因此如果 shell 放宽脚本权限,此问题可能会在未来的版本中得到解决...
我目前正在测试 Xcode Cloud 作为 Apple 私人测试版计划的成员,并在尝试在云上为我的项目存档/构建(任何操作)时遇到问题。
该项目是一个相当基本的 SwiftUI 应用程序,具有 CocoaPods 依赖项。我按照步骤将 CocoaPods 集成到我的项目 as described by Apple 中,只需将我的 Pods 目录提交到 GitHub。但是,每次尝试操作时,我都会在云上收到构建错误:
Command PhaseScriptExecution failed with a nonzero exit code
这里是ASC日志供参考:
这很奇怪,因为同一个项目在我的本地机器上成功构建和归档。我在工作流编辑器中使用了与本地版本 Xcode.
相同的 macOS 和 Xcode 版本我该如何解决这个错误?
自定义 shell 脚本限制
TL;DR
Apple 已通过仅启用 shell 脚本 运行 作为 ci_post_clone.sh
、ci_pre_xcodebuild.sh
或 ci_post_xcodebuild.sh
的一部分来锁定其托管基础设施的安全性在 ci_scripts
文件夹中。您的 Pods 项目在此文件夹外有一个自定义 shell 脚本,它不是由这些 CI 脚本之一触发的,因此没有 运行ning 权限。
此特定问题的解决方案是:
- (技术上)重构您的构建脚本阶段以将 shell 脚本文件内联到 运行 脚本中。
- (推荐,但并非总是可行)如果可用,请使用 CocoaPod 的 Swift 包版本。
- (解决方法)将 CocoaPod 降级到没有外部 shell 脚本的版本。
参考
来自 Customize your advanced Xcode Cloud workflows:
If your script doesn't appear to be running when you expect it to, double-check that you've named it correctly and placed it in a
ci_scripts
folder alongside your project....
Lastly, it should be noted that in a test action, multiple environments are used to build and run your tests. Only the environment that is used for building your tests will have your source code cloned into it by default. The environments that run your tests won't have source code cloned into them. They'll only have the ci_scripts folder made available on them. As a result, the post-clone script won't run in these environments and your custom scripts and any of their dependencies, such as other shell scripts and small tools, must be entirely contained within the ci_scripts folder.
允许构建脚本阶段 运行 user-defined 代码 作为构建过程的一部分 ,但是,我们只能 运行 内联 自定义脚本在这里。如前所述,外部 shell 脚本具有受限权限。 运行在移动到 ci_scripts
后绑定外部 shell 脚本文件不起作用。例如"${PODS_ROOT}/../ci_scripts/AppCenter-xcframeworks.sh"
.
虽然此处不相关,但请注意 测试项目的环境不会将源代码克隆到其中。
对于引用自定义脚本文件的测试或其他环境,我们需要在 ci_scripts
文件夹中存储额外的脚本,以确保操作可以访问它。 Apple 只允许 3 个脚本 运行 对应于构建的 3 个阶段:
- 将源代码克隆到构建环境后。
- 在运行宁
xcodebuild
之前。 - 宁运行后
xcodebuild
.
其他 shell 脚本只能 运行 在从 [=13= 中的相应 ci_post_clone.sh
、ci_pre_xcodebuild.sh
或 ci_post_xcodebuild.sh
文件委派后]文件夹。
解决方案 1
我的问题是 运行在构建过程中 shell 使用外部 shell 脚本 。 Apple 确实允许 运行 在 Xcode 云工作流中编写脚本构建阶段,但它们必须内联。因此,作为构建阶段的一部分,我必须对 运行 自定义 Pod shell 脚本执行 4 个步骤:
- 重构您的 Build Phases -> 运行 Script Phase 脚本以内联 shell 脚本文件。
- 清除
DerivedData
后在本地检查项目构建。 - 将您的代码提交到 GitHub / VCS。
- 触发工作流。
解决方案 2(推荐,但并非总是可行)
之后添加 CocoaPod 的 Swift 包版本作为依赖项解决方案 3(解决方法)
将您的 CocoaPod 降级到没有外部 shell 脚本的版本。
备注
从使用 Xcode Cloud 解决自定义 shell 脚本构建阶段所需的工作量可以看出,我建议在特定 CocoaPod 存储库上提出问题以从自定义 shell 脚本构建阶段迁移=124=]脚本文件。这些步骤使得使用 Xcode Cloud 非常痛苦。
随着 Xcode 云采用率的增长,个别 CocoaPods 完全有可能不再引用自定义 shell 脚本文件。我没有看到苹果开放他们的基础设施来启用任意 shell 脚本执行,因为这是一个安全风险,老实说,其他 CI 供应商也应该被阻止。
我还可以看到像这些包含遗留 CocoaPods 依赖项的麻烦如何加速更多项目迁移到 SPM。 SPM 已经很流行,并且随着 Apple 确保 first-class 集成,它可能会变得更流行。
免责声明: Xcode Cloud 处于私人测试阶段,因此如果 shell 放宽脚本权限,此问题可能会在未来的版本中得到解决...