-
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
Changes from 32 commits
4fe69cf
702c16e
5fb1859
bf61231
0697fb3
ca48379
1f19980
dc1ef56
9c1565a
4855a65
ac1697b
776efe7
e6813ff
74e046b
7237304
cdd1414
38c1a99
543042e
8bfe4f7
68b361b
b3fe073
d988855
1423e71
9432ed6
71f18ab
f71842b
f3ba705
f08a599
1b518d5
bdaf289
48bc2ac
f8942a8
8a6377f
e8784f5
c05d5e8
82af9b6
44785e4
b919255
9d49421
4cec047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,65 @@ | ||
| #!/bin/bash -eu | ||
|
|
||
| CUSTOM_PACKAGE_RESOLVED_PATH=${1-} | ||
| BUILD_TYPE=${2-} | ||
| SPM_CACHE_LOCATION="$HOME/spm" | ||
|
|
||
| WORKSPACE_PACKAGE_RESOLVED_PATH=(*.xcworkspace/xcshareddata/swiftpm/Package.resolved) | ||
| ROOT_PACKAGE_RESOLVED_PATH=Package.resolved | ||
|
|
||
| # Find where Package.resolved is located | ||
| if [[ -n "$CUSTOM_PACKAGE_RESOLVED_PATH" ]]; then | ||
| PACKAGE_RESOLVED_LOCATION=$CUSTOM_PACKAGE_RESOLVED_PATH | ||
| elif [[ -f ${WORKSPACE_PACKAGE_RESOLVED_PATH[0]} ]]; then | ||
| BUILD_TYPE="XCODEBUILD" | ||
| PACKAGE_RESOLVED_LOCATION=${WORKSPACE_PACKAGE_RESOLVED_PATH[0]} | ||
| elif [[ -f $ROOT_PACKAGE_RESOLVED_PATH ]]; then | ||
| BUILD_TYPE="SWIFT" | ||
| PACKAGE_RESOLVED_LOCATION=$ROOT_PACKAGE_RESOLVED_PATH | ||
| else | ||
| echo "Unable to find Package.resolved" | ||
| fi | ||
|
|
||
| PACKAGE_RESOLVED_HASH=$(hash_file "$PACKAGE_RESOLVED_LOCATION") | ||
| CACHE_KEY="$BUILDKITE_PIPELINE_SLUG-spm-cache-$PACKAGE_RESOLVED_HASH" | ||
spencertransier marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Restore SPM cache if it's available | ||
| mkdir -p "$SPM_CACHE_LOCATION" | ||
| cd "$SPM_CACHE_LOCATION" | ||
| restore_cache "$CACHE_KEY" | ||
| cd - | ||
|
|
||
| # This will let Xcode use the system SSH config for downloading packages | ||
| sudo defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of this PR. Is this preference same as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| # Trust all GitHub.com and BitBucket.org keys – this allows checking out dependencies via SSH | ||
| add_host_to_ssh_known_hosts bitbucket.org | ||
| add_host_to_ssh_known_hosts github.com | ||
|
|
||
| xcodebuild -resolvePackageDependencies | ||
| # Based on the project type, resolve the packages using the correct build type | ||
| if [[ "$BUILD_TYPE" == "XCODEBUILD" ]]; then | ||
| echo "Resolving packages with \`xcodebuild\`" | ||
| xcodebuild \ | ||
| -resolvePackageDependencies \ | ||
| -clonedSourcePackagesDirPath "$SPM_CACHE_LOCATION" | ||
| elif [[ "$BUILD_TYPE" == "SWIFT" ]]; then | ||
| echo "Resolving packages with \`swift\`" | ||
| swift package resolve \ | ||
| --cache-path "$SPM_CACHE_LOCATION" \ | ||
| --verbose | ||
| else | ||
| echo "BUILD_TYPE is not set" | ||
| fi | ||
|
|
||
| # `checkouts` can be excluded because the system can quickly generate them | ||
| # instead of needing to download them in the cache each time. | ||
| # | ||
| # `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" | ||
|
||
|
|
||
| # If this is the first time we've seen this particular cache key, save it for the future | ||
| save_cache "$SPM_CACHE_LOCATION" "$CACHE_KEY" false "$TAR_OPTIONS" | ||
|
|
||
|
|
||
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/cachefolder 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
~/spmhere?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 thatorg.swift.swiftpmfolder automatically when resolving the packages.Added in 44785e4