-
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 all 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/Library/Caches/org.swift.swiftpm" | ||
|
|
||
| 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" | ||
| exit 1 | ||
| fi | ||
|
|
||
| PACKAGE_RESOLVED_HASH=$(hash_file "$PACKAGE_RESOLVED_LOCATION") | ||
| CACHE_KEY="${BUILDKITE_PIPELINE_SLUG}-spm-cache-${PACKAGE_RESOLVED_HASH}" | ||
|
|
||
| # 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\`" | ||
AliSoftware marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| xcodebuild -resolvePackageDependencies | ||
| elif [[ "$BUILD_TYPE" == "SWIFT" ]]; then | ||
| echo " Resolving packages with \`swift\`" | ||
| swift package resolve | ||
| else | ||
| echo "BUILD_TYPE must be set" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # `checkouts` can be removed because the system can quickly generate them | ||
| # instead of needing to download them in the cache each time. | ||
| # | ||
| # `artifacts` should be removed because it causes issues when downloading | ||
| # certain packages to have the artifacts already present after extracting | ||
| # cache | ||
| echo " Cleaning up cache files before saving cache" | ||
| rm -rf "$SPM_CACHE_LOCATION/checkouts" "$SPM_CACHE_LOCATION/artifacts" | ||
|
|
||
| # 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 | ||
|
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 a blocker. This sequence of argument feels prone to errors, it's probably worth looking into parsing the arguments and options, using
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. 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
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. See #54 |
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.