cache icon indicating copy to clipboard operation
cache copied to clipboard

Fix Swift Package Manager example

Open younke opened this issue 3 years ago • 1 comments

Previous example is somewhat misleading.

When new package is added, old cache is being restored, which may lead to package resolve errors as described here.

Considering this guide:

To ensure the CI workflow’s reliability, make sure it uses the appropriate version of package dependencies. SwiftPM records the result of dependency resolution in Package.resolved (at the top-level of the package) and it's used when performing dependency resolution (rather than having SwiftPM searching the latest eligible version of each package). Running swift package update updates all dependencies to the latest eligible versions and updates the Package.resolved. You can commit Package.resolved to your Git repository to ensure it’s always up-to-date on the CI environment to prevent the CI from building your project with unexpected versions of package dependencies. Otherwise you can choose to add Package.resolved file to .gitignore file and have swift package resolve command in charge of resolving the dependencies (swift package resolve is invoked by most SwiftPM commands).

We mustn't use restore-keys for spm cache.

younke avatar Aug 10 '22 04:08 younke

Hi @younke, thanks for your contribution. We have kept restore-key in examples for everyone to understand how the templates would look by default.

Your recommendation looks more like a good practice. Would you like to add a generic note instead in the Known practices and workarounds section? The same thing would also apply to languages/frameworks like NodeJS, GoLang (for example), that maintain a similar resolved packages file package-lock.json or go.sum. So this note would help users having background in multiple technologies.

kotewar avatar Sep 15 '22 07:09 kotewar

kadoned avatar Oct 16 '22 19:10 kadoned

Closing this PR as there is no response. But to make this clearer, the readme will be updated by giving better insights on cache-hit and partial match restore-key. PR raised here.

kotewar avatar Oct 18 '22 19:10 kotewar