Skip to content

Commit 5c6880f

Browse files
authored
[eas-cli] cache downloaded app archives in eas build:dev (#2864)
<!-- If this PR requires a changelog entry, add it by commenting the PR with the command `/changelog-entry [breaking-change|new-feature|bug-fix|chore] [message]`. --> <!-- You can skip the changelog check by labeling the PR with "no changelog". --> # Why We don't need to redownload app every single time in `eas build:dev`. We can cache it locally. This functionality already exists for `eas build:run`. # How Use caching the same way we do for `eas build:run` # Test Plan Tested manually
1 parent d5f562e commit 5c6880f

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

packages/eas-cli/src/build/runBuildAndSubmit.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { LoggerLevel } from '@expo/logger';
1212
import assert from 'assert';
1313
import chalk from 'chalk';
14+
import { pathExists } from 'fs-extra';
1415
import nullthrows from 'nullthrows';
1516

1617
import { prepareAndroidBuildAsync } from './android/build';
@@ -62,7 +63,7 @@ import {
6263
validateBuildProfileVersionSettingsAsync,
6364
} from '../project/remoteVersionSource';
6465
import { confirmAsync } from '../prompts';
65-
import { runAsync } from '../run/run';
66+
import { getEasBuildRunCachedAppPath, runAsync } from '../run/run';
6667
import { isRunnableOnSimulatorOrEmulator } from '../run/utils';
6768
import { createSubmissionContextAsync } from '../submit/context';
6869
import {
@@ -545,11 +546,21 @@ function exitWithNonZeroCodeIfSomeBuildsFailed(maybeBuilds: (BuildFragment | nul
545546
}
546547
}
547548

548-
async function downloadAndRunAsync(build: BuildFragment): Promise<void> {
549+
export async function downloadAndRunAsync(build: BuildFragment): Promise<void> {
549550
assert(build.artifacts?.applicationArchiveUrl);
551+
const cachedAppPath = getEasBuildRunCachedAppPath(build.project.id, build.id, build.platform);
552+
553+
if (await pathExists(cachedAppPath)) {
554+
Log.newLine();
555+
Log.log(`Using cached app...`);
556+
await runAsync(cachedAppPath, build.platform);
557+
return;
558+
}
559+
550560
const buildPath = await downloadAndMaybeExtractAppAsync(
551561
build.artifacts.applicationArchiveUrl,
552-
build.platform
562+
build.platform,
563+
cachedAppPath
553564
);
554565
await runAsync(buildPath, build.platform);
555566
}

packages/eas-cli/src/commands/build/dev.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ensureProjectConfiguredAsync,
99
} from '../../build/configure';
1010
import { evaluateConfigWithEnvVarsAsync } from '../../build/evaluateConfigWithEnvVarsAsync';
11-
import { runBuildAndSubmitAsync } from '../../build/runBuildAndSubmit';
11+
import { downloadAndRunAsync, runBuildAndSubmitAsync } from '../../build/runBuildAndSubmit';
1212
import { ensureRepoIsCleanAsync } from '../../build/utils/repository';
1313
import EasCommand from '../../commandUtils/EasCommand';
1414
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
@@ -19,8 +19,6 @@ import Log from '../../log';
1919
import { RequestedPlatform } from '../../platform';
2020
import { resolveWorkflowAsync } from '../../project/workflow';
2121
import { confirmAsync, promptAsync } from '../../prompts';
22-
import { runAsync } from '../../run/run';
23-
import { downloadAndMaybeExtractAppAsync } from '../../utils/download';
2422
import { createFingerprintAsync } from '../../utils/fingerprintCli';
2523
import { ProfileData, getProfilesAsync } from '../../utils/profiles';
2624
import { Client } from '../../vcs/vcs';
@@ -123,11 +121,7 @@ export default class BuildDev extends EasCommand {
123121
);
124122

125123
if (build.artifacts?.applicationArchiveUrl) {
126-
const buildPath = await downloadAndMaybeExtractAppAsync(
127-
build.artifacts.applicationArchiveUrl,
128-
build.platform
129-
);
130-
await runAsync(buildPath, build.platform);
124+
await downloadAndRunAsync(build);
131125
return;
132126
} else {
133127
Log.warn('Artifacts for this build expired. New build will be started.');

packages/eas-cli/src/commands/build/run.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Errors, Flags } from '@oclif/core';
22
import assert from 'assert';
33
import { pathExists } from 'fs-extra';
4-
import path from 'path';
54

65
import { getLatestBuildAsync, listAndSelectBuildOnAppAsync } from '../../build/queries';
76
import EasCommand from '../../commandUtils/EasCommand';
@@ -17,13 +16,12 @@ import Log from '../../log';
1716
import { appPlatformDisplayNames } from '../../platform';
1817
import { getDisplayNameForProjectIdAsync } from '../../project/projectUtils';
1918
import { promptAsync } from '../../prompts';
20-
import { RunArchiveFlags, runAsync } from '../../run/run';
19+
import { RunArchiveFlags, getEasBuildRunCachedAppPath, runAsync } from '../../run/run';
2120
import { isRunnableOnSimulatorOrEmulator } from '../../run/utils';
2221
import {
2322
downloadAndMaybeExtractAppAsync,
2423
extractAppFromLocalArchiveAsync,
2524
} from '../../utils/download';
26-
import { getEasBuildRunCacheDirectoryPath } from '../../utils/paths';
2725

2826
interface RawRunFlags {
2927
latest?: boolean;
@@ -245,17 +243,6 @@ async function maybeGetBuildAsync(
245243
}
246244
}
247245

248-
function getEasBuildRunCachedAppPath(
249-
projectId: string,
250-
buildId: string,
251-
platform: AppPlatform
252-
): string {
253-
return path.join(
254-
getEasBuildRunCacheDirectoryPath(),
255-
`${projectId}_${buildId}.${platform === AppPlatform.Ios ? 'app' : 'apk'}`
256-
);
257-
}
258-
259246
async function getPathToSimulatorBuildAppAsync(
260247
graphqlClient: ExpoGraphqlClient,
261248
projectId: string,

packages/eas-cli/src/run/run.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import path from 'path';
2+
13
import { runAppOnAndroidEmulatorAsync } from './android/run';
24
import { runAppOnIosSimulatorAsync } from './ios/run';
35
import { AppPlatform } from '../graphql/generated';
6+
import { getEasBuildRunCacheDirectoryPath } from '../utils/paths';
47

58
export interface RunArchiveFlags {
69
latest?: boolean;
@@ -19,3 +22,14 @@ export async function runAsync(
1922
await runAppOnAndroidEmulatorAsync(simulatorBuildPath);
2023
}
2124
}
25+
26+
export function getEasBuildRunCachedAppPath(
27+
projectId: string,
28+
buildId: string,
29+
platform: AppPlatform
30+
): string {
31+
return path.join(
32+
getEasBuildRunCacheDirectoryPath(),
33+
`${projectId}_${buildId}.${platform === AppPlatform.Ios ? 'app' : 'apk'}`
34+
);
35+
}

0 commit comments

Comments
 (0)