-
Notifications
You must be signed in to change notification settings - Fork 5
Add SPM Caching Action #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reverts commit 5fb1859.
Question about the Shellcheck error I'm getting:
It's referring to Without the quotes around 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 |
@spencertransier Adding the quotes around On the other hand, not quoting the 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) |
bin/install_swiftpm_dependencies
Outdated
# `artifacts` should be excluded because it causes issues when downloading | ||
# certain packages to have the artifacts already present after extracting | ||
# cache | ||
TAR_OPTIONS="--exclude=./checkouts --exclude=./artifacts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than fighting with bash syntax regarding using quote or not, I'm wondering if it'd be simpler to just delete these unwanted files from the SPM_CACHE_LOCATION?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, copy the "SPM_CACHE_LOCATION", delete the unwanted files from the new copy, call save_cache
on the new copy, and delete the new copy afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AliSoftware Thank you for the explanation! The array solution makes a lot of sense after the behavior I saw while debugging this.
@crazytonyli Good idea! I think I'm going to go with deleting those directories before saving the cache. It removes the complexity of passing the tar options along with simplifying the changes to save_cache
.
bin/install_swiftpm_dependencies
Outdated
|
||
CUSTOM_PACKAGE_RESOLVED_PATH=${1-} | ||
BUILD_TYPE=${2-} | ||
SPM_CACHE_LOCATION="$HOME/spm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There exists a $HOME/.swiftpm/cache
folder on my Mac that was probably created by SPM itself at some point.
I wonder if we shouldn't use that folder (for conventions) as opposed to ~/spm
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point! Jeremy and I had discussed using the cache that's within DerivedData, but I wasn't able to make that work because there's not a consistent path name within DerivedData. But it does work great with making the cache location in the script point to $HOME/Library/Caches/org.swift.swiftpm
. And that has the added benefit of client repos not needing to specify a specific SPM cache folder in the Fastfile. Package resolution will pull from that org.swift.swiftpm
folder automatically when resolving the packages.
Added in 44785e4
bin/save_cache
Outdated
echo " Compressing" | ||
tar -czf "$CACHE_KEY" "$CACHE_FILE" | ||
TAR_CONFIG=${4-} | ||
if [[ "$TAR_CONFIG" == '--use_alternate_tar_config' ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit but I'm not a fan of the name of this custom flag… what about --use_relative_path_in_tar
or something like that instead?
Also, I'm wondering if it wouldn't make sense to adopt that -C
behavior… in all circumstances after all (seems a nicer solution than including /User/builder
in the cache path and risking the un-tar-ing to fail if used on a different builder which might not have a /User/builder
folder (all our Mac VMs currently do, but we shouldn't need to make that assumption, and also nothing says the cache would be restored on a Mac VM vs an Android AMI or Docker container or whatnot, so…).
That one might be a broader investigation to verify that changing that behavior that save_cache
was using so far (and you kept in the else
) to instead use -C "$CACHE_FILE" .
in all cases would not break existing setups depending on how they use restore_cache
on their end; so could be saved for a subsequent PR if you're not sure about that. But would be a nice simplification if we can confirm it and go in that direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I like --use_relative_path_in_tar
better, too. Changed in b919255
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it wouldn't make sense to adopt that -C behavior in all circumstances.
I agree that would be nice to use the same behavior for all cases if possible. Because I saw different behavior between the existing tar
configuration versus the one I added in this PR, I had assumed the projects that use save_cache
would need to be updated and cause a breaking change. I haven't tested that out yet, but I think it'd be outside the scope for this project. I'll create a separate issue for it.
Co-authored-by: Olivier Halligon <[email protected]>
Co-authored-by: Olivier Halligon <[email protected]>
|
||
# If this is the first time we've seen this particular cache key, save it for the future | ||
echo " Saving SPM Cache" | ||
save_cache "$SPM_CACHE_LOCATION" "$CACHE_KEY" false --use_relative_path_in_tar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker. This sequence of argument feels prone to errors, it's probably worth looking into parsing the arguments and options, using getopts
for example. Statement as below would look much nicer 😸
save_cache --cache-key "$CACHE_KEY" --overwrite --use_relative_path_in_tar "$SPM_CACHE_LOCATION"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion! I am going to land this PR and work on improving this in my next iteration of the SPM caching and save_cache
improvements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #54
cd - | ||
|
||
# This will let Xcode use the system SSH config for downloading packages | ||
sudo defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of this PR. Is this preference same as xcodebuild -scmProvider system
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@crazytonyli I think so but I'm not sure. I will look into this and see about adding in the next update of the SPM caching action.
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.