-
Notifications
You must be signed in to change notification settings - Fork 230
[build-tools] support remote CocoaPods caching #4266
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
Open
AbbanMustafa
wants to merge
5
commits into
main
Choose a base branch
from
mustafa/cocoapods-build-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9824c8f
[build-tools] Cache CocoaPods dependencies between iOS builds
AbbanMustafa 214b2ff
restore/save cache
AbbanMustafa dfcc384
remove CocoaPods download cache
AbbanMustafa f635bd7
Merge remote-tracking branch 'origin/main' into mustafa/cocoapods-bui…
AbbanMustafa 11a0961
remove no-lockfile cache key
AbbanMustafa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
packages/build-tools/src/steps/functions/__tests__/cocoapodsBuildCache.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { spawnAsync } from '@expo/steps'; | ||
| import { vol } from 'memfs'; | ||
|
|
||
| import { createMockLogger } from '../../../__tests__/utils/logger'; | ||
| import { Datadog } from '../../../datadog'; | ||
| import { | ||
| compressCocoapodsCacheAsync, | ||
| getCocoapodsCachePaths, | ||
| resolveCocoapodsCacheKeyAsync, | ||
| restoreCocoapodsCacheArchiveAsync, | ||
| } from '../../../utils/cocoapodsCache'; | ||
| import { downloadCacheAsync } from '../restoreCache'; | ||
| import { restoreCocoapodsCacheAsync } from '../restoreBuildCache'; | ||
| import { uploadCacheAsync } from '../saveCache'; | ||
| import { saveCocoapodsCacheAsync } from '../saveBuildCache'; | ||
|
|
||
| jest.mock('@expo/steps', () => ({ | ||
| ...jest.requireActual('@expo/steps'), | ||
| spawnAsync: jest.fn(), | ||
| })); | ||
| jest.mock('../restoreCache', () => ({ | ||
| decompressCacheAsync: jest.fn(), | ||
| downloadCacheAsync: jest.fn(), | ||
| downloadPublicCacheAsync: jest.fn(), | ||
| })); | ||
| jest.mock('../saveCache', () => ({ | ||
| compressCacheAsync: jest.fn(), | ||
| uploadCacheAsync: jest.fn(), | ||
| })); | ||
| jest.mock('../../../utils/cocoapodsCache', () => ({ | ||
| compressCocoapodsCacheAsync: jest.fn(), | ||
| getCocoapodsCachePaths: jest.fn(), | ||
| resolveCocoapodsCacheKeyAsync: jest.fn(), | ||
| restoreCocoapodsCacheArchiveAsync: jest.fn(), | ||
| })); | ||
|
|
||
| const logger = createMockLogger(); | ||
| const env = { | ||
| EAS_PODS_CACHE: '1', | ||
| EAS_BUILD_ID: 'build-id', | ||
| __API_SERVER_URL: 'https://api.expo.test', | ||
| }; | ||
| const secrets = { robotAccessToken: 'robot-token' }; | ||
|
|
||
| describe('CocoaPods build cache', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| vol.fromJSON( | ||
| { | ||
| '/workingdir/ios/Pods/Manifest.lock': 'manifest', | ||
| '/workingdir/ios/Podfile.lock': 'lockfile', | ||
| '/tmp/cocoapods-cache.tar.gz': 'archive', | ||
| }, | ||
| '/' | ||
| ); | ||
| jest.mocked(getCocoapodsCachePaths).mockReturnValue({ | ||
| iosDirectory: '/workingdir/ios', | ||
| podsDirectory: '/workingdir/ios/Pods', | ||
| podfileLockPath: '/workingdir/ios/Podfile.lock', | ||
| }); | ||
| jest.mocked(resolveCocoapodsCacheKeyAsync).mockResolvedValue({ | ||
| key: 'ios-pods-1.16.2-lock-hash', | ||
| keyPrefix: 'ios-pods-1.16.2-', | ||
| }); | ||
| jest.mocked(spawnAsync).mockResolvedValue({ stdout: '1.16.2\n' } as any); | ||
| }); | ||
|
|
||
| it('does nothing when the cache is disabled', async () => { | ||
| await restoreCocoapodsCacheAsync({ | ||
| logger, | ||
| workingDirectory: '/workingdir', | ||
| env: {}, | ||
| secrets, | ||
| }); | ||
| await saveCocoapodsCacheAsync({ | ||
| logger, | ||
| workingDirectory: '/workingdir', | ||
| env: {}, | ||
| secrets, | ||
| }); | ||
|
|
||
| expect(spawnAsync).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('restores the newest matching CocoaPods cache', async () => { | ||
| jest.mocked(downloadCacheAsync).mockResolvedValue({ | ||
| archivePath: '/tmp/cocoapods-cache.tar.gz', | ||
| matchedKey: 'ios-pods-1.16.2-older-lock-hash', | ||
| }); | ||
| const datadogLogSpy = jest.spyOn(Datadog, 'log'); | ||
|
|
||
| await restoreCocoapodsCacheAsync({ | ||
| logger, | ||
| workingDirectory: '/workingdir', | ||
| env, | ||
| secrets, | ||
| }); | ||
|
|
||
| expect(downloadCacheAsync).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| key: 'ios-pods-1.16.2-lock-hash', | ||
| keyPrefixes: ['ios-pods-1.16.2-'], | ||
| paths: ['/workingdir/ios/Pods'], | ||
| }) | ||
| ); | ||
| expect(restoreCocoapodsCacheArchiveAsync).toHaveBeenCalledWith({ | ||
| archivePath: '/tmp/cocoapods-cache.tar.gz', | ||
| workingDirectory: '/workingdir', | ||
| }); | ||
| expect(datadogLogSpy).toHaveBeenCalledWith('CocoaPods cache restored (prefix_match)', { | ||
| event: 'cocoapods_cache_restored', | ||
| cache_hit_type: 'prefix_match', | ||
| }); | ||
| }); | ||
|
|
||
| it('compresses and saves the installed Pods directory', async () => { | ||
| jest.mocked(compressCocoapodsCacheAsync).mockResolvedValue({ | ||
| archivePath: '/tmp/cocoapods-cache.tar.gz', | ||
| }); | ||
|
|
||
| await saveCocoapodsCacheAsync({ | ||
| logger, | ||
| workingDirectory: '/workingdir', | ||
| env, | ||
| secrets, | ||
| }); | ||
|
|
||
| expect(uploadCacheAsync).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| archivePath: '/tmp/cocoapods-cache.tar.gz', | ||
| key: 'ios-pods-1.16.2-lock-hash', | ||
| paths: ['/workingdir/ios/Pods'], | ||
| }) | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same