-
Notifications
You must be signed in to change notification settings - Fork 36
feat: remote (and local) build caching #48
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
Merged
Merged
Changes from 52 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
8d372ef
tweak publish config
mdjastrzebski 41fd9f0
improve
mdjastrzebski c598e14
simplify script
mdjastrzebski 44f07f3
adapt gh workflows
mdjastrzebski c6abeff
.
mdjastrzebski 9bcde38
post only when in PR
mdjastrzebski 55b2f57
.
mdjastrzebski b8adcfe
.
mdjastrzebski a629730
.
mdjastrzebski b15a453
detect project root and ci
mdjastrzebski a4e6a93
fetch artifact (wip)
mdjastrzebski 46298ac
detect GH remote repo details
mdjastrzebski cd35fb2
cached build workflow
mdjastrzebski 75227b1
query and download artifact
mdjastrzebski fb53dfc
update actions
mdjastrzebski e46a9e0
cleanup logs
mdjastrzebski 3295a59
.
mdjastrzebski d0798dc
unzip downloaded archive to apk
thymikee e922395
adjust wording
thymikee c5e3d57
cleanup zip code
mdjastrzebski e4ec1a2
eslint ignore dist
mdjastrzebski 4303f7a
.
mdjastrzebski 1247f1f
local caching android
mdjastrzebski f549041
extract fetchCachedBuild fn
thymikee 25f0941
remove unnecessary binaryPath check
thymikee 98b23ca
parametrize fetchCachedBuild with ci provider
thymikee 06ae444
build android action improvements
mdjastrzebski 4146774
fix ios artifact packing
mdjastrzebski b930a38
ios fetch cached build
mdjastrzebski fe246a2
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski db611b3
remote build caching on iOS simu!
mdjastrzebski 2c90119
use nano-spawn
thymikee bbda187
update expo fingerprint
mdjastrzebski 1e412b5
fix test
mdjastrzebski 02be174
fix e2e
mdjastrzebski 2c4db97
refactor android
mdjastrzebski cb0c895
refactor ios
mdjastrzebski fe6e16c
self code review
mdjastrzebski 0471743
fix test
mdjastrzebski fa9a202
fix tests, add `--no-remote-build-cache` CLI option
mdjastrzebski dfbf966
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski ff4c3ea
code review changes
mdjastrzebski 2c8d0cc
.
mdjastrzebski 0be05fb
.
mdjastrzebski 7038dd8
.
mdjastrzebski e466d10
.
mdjastrzebski 82c6268
.
mdjastrzebski 1c6c4b8
.
mdjastrzebski e00317a
git ignore
mdjastrzebski 794d2a8
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski 54ed84f
.
mdjastrzebski 0ed7359
tweak cache location
mdjastrzebski f59febd
.
mdjastrzebski b35c6b3
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski 91d72e6
fix lockfile
mdjastrzebski 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
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
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
87 changes: 87 additions & 0 deletions
87
packages/plugin-platform-android/src/lib/commands/runAndroid/fetchCachedBuild.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,87 @@ | ||
| import { | ||
| LocalBuild, | ||
| createRemoteBuildCache, | ||
| findFilesWithPattern, | ||
| formatArtifactName, | ||
| getProjectRoot, | ||
| nativeFingerprint, | ||
| queryLocalBuildCache, | ||
| } from '@rnef/tools'; | ||
| import { spinner } from '@clack/prompts'; | ||
| import path from 'node:path'; | ||
| import color from 'picocolors'; | ||
|
|
||
| export type FetchCachedBuildOptions = { | ||
| mode: string; | ||
| }; | ||
|
|
||
| export async function fetchCachedBuild({ | ||
| mode, | ||
| }: FetchCachedBuildOptions): Promise<LocalBuild | null> { | ||
| const loader = spinner(); | ||
| loader.start('Looking for a local cached build'); | ||
|
|
||
| const root = getProjectRoot(); | ||
| const artifactName = await calculateArtifactName(mode); | ||
|
|
||
| const localBuild = queryLocalBuildCache(artifactName, { findBinary }); | ||
| if (localBuild != null) { | ||
| loader.stop(`Found local cached build: ${color.cyan(localBuild.name)}`); | ||
| return localBuild; | ||
| } | ||
|
|
||
| const remoteBuildCache = createRemoteBuildCache(); | ||
| if (!remoteBuildCache) { | ||
| loader.stop(`No CI provider detected, skipping.`); | ||
| return null; | ||
| } | ||
|
|
||
| loader.message(`Looking for a cached build on ${remoteBuildCache.name}`); | ||
| const remoteBuild = await remoteBuildCache.query(artifactName); | ||
| if (!remoteBuild) { | ||
| loader.stop(`No cached build found for "${artifactName}".`); | ||
| return null; | ||
| } | ||
|
|
||
| loader.message(`Downloading cached build from ${remoteBuildCache.name}`); | ||
| const fetchedBuild = await remoteBuildCache.download(remoteBuild); | ||
| const binaryPath = findBinary(fetchedBuild.path); | ||
| if (!binaryPath) { | ||
| loader.stop(`No binary found in "${artifactName}".`); | ||
| return null; | ||
| } | ||
|
|
||
| loader.stop( | ||
| `Downloaded cached build: ${color.cyan(path.relative(root, binaryPath))}.` | ||
| ); | ||
|
|
||
| return { | ||
| name: fetchedBuild.name, | ||
| artifactPath: fetchedBuild.path, | ||
| binaryPath, | ||
| }; | ||
| } | ||
|
|
||
| async function calculateArtifactName(mode: string) { | ||
| const root = getProjectRoot(); | ||
| const fingerprint = await nativeFingerprint(root, { platform: 'android' }); | ||
| return formatArtifactName({ | ||
| platform: 'android', | ||
| mode, | ||
| hash: fingerprint.hash, | ||
| }); | ||
| } | ||
|
|
||
| function findBinary(path: string): string | null { | ||
| const apks = findFilesWithPattern(path, /\.apk$/); | ||
| if (apks.length > 0) { | ||
| return apks[0]; | ||
| } | ||
|
|
||
| const aabs = findFilesWithPattern(path, /\.aab$/); | ||
| if (aabs.length > 0) { | ||
| return aabs[0]; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.