Automattic / a8c-ci-toolkit-buildkite-plugin

A caching plugin that can be invoked from your build script.
21 stars 5 forks source link

Add SPM Caching Action #43

Closed spencertransier closed 1 year ago

spencertransier commented 1 year ago

Summary

This PR adds a caching action for Swift Package Manager to the CI toolkit. Some notes:

How to Test

You can see this CI build of Day One iOS/Mac that's using the latest caching code:

Example Builds:

There is now a "Restoring SPM Cache" step:

Screenshot 2023-03-01 at 3 39 13 PM

To try regenerating the cache, you can delete any of the day-one-spm-cache... files from the a8c-ci-cache and re-run the build to verify that the cache rebuilds.

spencertransier commented 1 year ago

Question about the Shellcheck error I'm getting:

In bin/save_cache line 58: [2023-03-01T23:35:12Z] tar $TAR_OPTIONS -czf "$CACHE_KEY" -C "$CACHE_FILE" . [2023-03-01T23:35:12Z] ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

It's referring to $TAR_OPTIONS not being surrounded in quotes. The issue is that if I add the quotes, the tar options that I'm passing to save_cache from install_swiftpm_dependencies don't actually get used by tar when archiving the cache. In this case, I'm passing folders that should be excluded when creating the cache archive.

Without the quotes around $TAR_OPTIONS in save_cache, the folders are excluded from the archive as expected. With the quotes, the --exclude options are ignored and the folders are not excluded from the archive.

I'm just not sure why adding the quotes is doing that. Any suggestions about what could be changed to allow for the quotes to be added? I know this is just an info issue with Shellcheck. I assume we have Shellcheck fail for info issues for a reason, so I didn't want to ignore this one even though it's not even a warning.

AliSoftware commented 1 year ago

@spencertransier Adding the quotes around "$TAR_OPTIONS" means that if that variable contains eg --exclude Foo then it will consider "--exclude foo" as a single argument (one which contains spaces) as opposed to two.

On the other hand, not quoting the $TAR_OPTIONS means that if it contains --exclude foo it'll see it as two individual arguments like you probably want… but that also means that if the folder you want to exclude contains a space, eg --exclude my project it will see it as three distinct arguments (--exclude, my and project)

The best solution for your case is probably to use the bash array syntax to build your list or tar options (whose syntax I always forget but a quick search on the net should help)