简体   繁体   English

SPM 缓存不适用于 github 操作,有什么想法吗?

[英]SPM cache not working on github actions, any ideas?

I am trying to cache the SPM packages on GitHub Actions with cache action , I am following this example:我正在尝试使用缓存操作在 GitHub Actions 上缓存 SPM 包,我正在遵循以下示例:

  - uses: actions/cache@v2
  with:
    path: Myproject.xcworkspace/xcshareddata/swiftpm/Package.resolved
    key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
    restore-keys: |
      ${{ runner.os }}-spm-

I feel like is not possible to use cache, when you add your SPM packages with Xcode当您使用 Xcode 添加 SPM 包时,我觉得不可能使用缓存

Did anyone have succeed adding cache to your project even managing SPM via Xcode?是否有人成功地将缓存添加到您的项目中,甚至通过 Xcode 管理 SPM? Or maybe something is wrong in my .yml file but unfortunately I could not make it work.或者我的 .yml 文件可能有问题,但不幸的是我无法让它工作。

You are using the path parameter incorrectly.您使用的path参数不正确。

path - A list of files, directories, and wildcard patterns to cache and restore. path - 要缓存和恢复的文件、目录和通配符模式的列表。 See @actions/glob for supported patterns.有关支持的模式,请参阅@actions/glob

Instead of setting path to the resolve file it should point to whatever file/folder that you wish to cache.它应该指向您希望缓存的任何文件/文件夹,而不是设置解析文件的path

The documentation for actions/cache actually shows exactly how to use it for SPM: actions/cache的文档实际上显示了如何将它用于 SPM:

- uses: actions/cache@v2
  with:
    path: .build
    key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
    restore-keys: |
      ${{ runner.os }}-spm-

Since you are letting Xcode manage the Swift packages the files end up being stored in a different location than they would be if you manually managed them using swift package .由于您让 Xcode 管理 Swift 包,因此文件最终存储在与使用swift package手动管理它们不同的位置。

This variation should find the files (but Xcode could change where it stores them at any time):这种变体应该可以找到文件(但 Xcode 可以随时更改存储它们的位置):

- uses: actions/cache@v2
  with:
    path: /Users/runner/Library/Developer/Xcode/DerivedData/**/SourcePackages/checkouts 
    key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
    restore-keys: |
      ${{ runner.os }}-spm-

Since you are using CI + SPM I would recommend you stop managing SPM via Xcode and instead manually use swift package .由于您使用的是 CI + SPM,我建议您停止通过 Xcode 管理 SPM,而是手动使用swift package This will allow you to have a more predictable location ( .build ) for the SPM packages.这将允许您为 SPM 包提供更可预测的位置 ( .build )。

The second variation don't know why It didn't work for me, thanks anyway for your help 🙌.第二个变体不知道为什么它对我不起作用,无论如何感谢您的帮助🙌。

I gave it a last shot, and this worked!我给了它最后一枪,这成功了!

- uses: actions/cache@v3
        name: "Cache: SPM"
        with:
          path: ~/Library/Developer/Xcode/DerivedData/AppName*/SourcePackages/
          key: ${{ runner.os }}-spm-${{ hashFiles('AppName.xcworkspace/xcshareddata/swiftpm/Package.resolved') }}
          restore-keys: |
            ${{ runner.os }}-spm-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM