Closed spencertransier closed 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.
@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)
Summary
This PR adds a caching action for Swift Package Manager to the CI toolkit. Some notes:
hostmgr
or Swift packages if they have SPM dependencies. The action automatically detects what kind of repo it is based on where thePackage.resolved
file is located.install_swiftpm_dependencies
action because I didn't see it being used elsewhere. If that's incorrect (@jkmassel & @AliSoftware looks like you both worked on that action in the past), please let me know and I can move SPM caching into a separate action.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:
To try regenerating the cache, you can delete any of the
day-one-spm-cache...
files from thea8c-ci-cache
and re-run the build to verify that the cache rebuilds.