Skip to content

Commit 0a22f90

Browse files
committed
[eas-cli] add build profile support for fingerprint
Temporary Commit at 3/16/2025, 6:31:01 PM Temporary Commit at 3/16/2025, 6:37:24 PM Temporary Commit at 3/16/2025, 7:59:29 PM Temporary Commit at 3/16/2025, 8:01:21 PM Temporary Commit at 3/18/2025, 2:38:20 PM Temporary Commit at 3/18/2025, 3:21:52 PM
1 parent f297df7 commit 0a22f90

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

packages/eas-cli/src/commands/fingerprint/compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ function isJSON(str: string): boolean {
757757
}
758758
}
759759

760-
export async function selectBuildToCompareAsync(
760+
async function selectBuildToCompareAsync(
761761
graphqlClient: ExpoGraphqlClient,
762762
projectId: string,
763763
projectDisplayName: string,

packages/eas-cli/src/commands/fingerprint/generate.ts

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { Env, Platform } from '@expo/eas-build-job';
2+
import { EasJsonAccessor } from '@expo/eas-json';
13
import { Flags } from '@oclif/core';
24

35
import { getExpoWebsiteBaseUrl } from '../../api';
6+
import { evaluateConfigWithEnvVarsAsync } from '../../build/evaluateConfigWithEnvVarsAsync';
47
import EasCommand from '../../commandUtils/EasCommand';
58
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
69
import {
@@ -12,22 +15,28 @@ import { AppQuery } from '../../graphql/queries/AppQuery';
1215
import Log, { link } from '../../log';
1316
import { promptAsync } from '../../prompts';
1417
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
18+
import { getProfilesAsync } from '../../utils/profiles';
1519

1620
export default class FingerprintGenerate extends EasCommand {
1721
static override description = 'generate fingerprints from the current project';
1822
static override strict = false;
1923
static override hidden = true;
2024

2125
static override examples = [
22-
'$ eas fingerprint:generate',
23-
'$ eas fingerprint:generate --json --non-interactive -p android',
26+
'$ eas fingerprint:generate \t # Generate fingerprint in interactive mode',
27+
'$ eas fingerprint:generate --profile preview \t # Generate a fingerprint using the "preview" build profile',
28+
'$ eas fingerprint:generate --json --non-interactive --platform android \t # Output fingerprint json to stdout',
2429
];
2530

2631
static override flags = {
2732
platform: Flags.enum({
2833
char: 'p',
2934
options: ['android', 'ios'],
3035
}),
36+
profile: Flags.string({
37+
char: 'e',
38+
description: 'Name of the build profile from eas.json.',
39+
}),
3140
...EasNonInteractiveAndJsonFlags,
3241
};
3342

@@ -36,17 +45,24 @@ export default class FingerprintGenerate extends EasCommand {
3645
...this.ContextOptions.ProjectConfig,
3746
...this.ContextOptions.LoggedIn,
3847
...this.ContextOptions.Vcs,
48+
...this.ContextOptions.DynamicProjectConfig,
3949
};
4050

4151
async runAsync(): Promise<void> {
4252
const { flags } = await this.parse(FingerprintGenerate);
43-
const { json, 'non-interactive': nonInteractive, platform: platformStringFlag } = flags;
53+
const {
54+
json,
55+
'non-interactive': nonInteractive,
56+
platform: platformStringFlag,
57+
profile: buildProfileName,
58+
} = flags;
4459

4560
const {
4661
projectId,
4762
privateProjectConfig: { projectDir },
4863
loggedIn: { graphqlClient },
4964
vcsClient,
65+
getDynamicPrivateProjectConfigAsync,
5066
} = await this.getContextAsync(FingerprintGenerate, {
5167
nonInteractive,
5268
withServerSideEnvironment: null,
@@ -64,12 +80,39 @@ export default class FingerprintGenerate extends EasCommand {
6480
}
6581
platform = await selectRequestedPlatformAsync();
6682
}
83+
84+
let env: Env | undefined;
85+
if (buildProfileName) {
86+
const easJsonAccessor = EasJsonAccessor.fromProjectPath(projectDir);
87+
const buildProfile = (
88+
await getProfilesAsync({
89+
type: 'build',
90+
easJsonAccessor,
91+
platforms: [appPlatformtoPlatform(platform)],
92+
profileName: buildProfileName ?? undefined,
93+
projectDir,
94+
})
95+
)[0];
96+
if (!buildProfile) {
97+
throw new Error(`Build profile ${buildProfile} not found for platform: ${platform}`);
98+
}
99+
const configResult = await evaluateConfigWithEnvVarsAsync({
100+
buildProfile: buildProfile.profile,
101+
buildProfileName: buildProfile.profileName,
102+
graphqlClient,
103+
getProjectConfig: getDynamicPrivateProjectConfigAsync,
104+
opts: { env: buildProfile.profile.env },
105+
});
106+
env = configResult.env;
107+
}
108+
67109
const fingerprint = await getFingerprintInfoFromLocalProjectForPlatformsAsync(
68110
graphqlClient,
69111
projectDir,
70112
projectId,
71113
vcsClient,
72-
[platform]
114+
[platform],
115+
{ env }
73116
);
74117

75118
if (json) {
@@ -89,7 +132,7 @@ export default class FingerprintGenerate extends EasCommand {
89132
}
90133
}
91134

92-
export async function selectRequestedPlatformAsync(): Promise<AppPlatform> {
135+
async function selectRequestedPlatformAsync(): Promise<AppPlatform> {
93136
const { requestedPlatform } = await promptAsync({
94137
type: 'select',
95138
message: 'Select platform',
@@ -101,3 +144,13 @@ export async function selectRequestedPlatformAsync(): Promise<AppPlatform> {
101144
});
102145
return requestedPlatform;
103146
}
147+
148+
function appPlatformtoPlatform(appPlatform: AppPlatform): Platform {
149+
if (appPlatform === AppPlatform.Android) {
150+
return Platform.ANDROID;
151+
} else if (appPlatform === AppPlatform.Ios) {
152+
return Platform.IOS;
153+
} else {
154+
throw new Error('Unsupported platform: ' + appPlatform);
155+
}
156+
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,20 @@ async function createFingerprintWithoutLoggingAsync(
103103
if (options.debug) {
104104
fingerprintOptions.debug = true;
105105
}
106-
// eslint-disable-next-line @typescript-eslint/return-await
107-
return await Fingerprint.createFingerprintAsync(projectDir, fingerprintOptions);
106+
107+
return await withTemporaryEnv(options.env ?? {}, () =>
108+
Fingerprint.createFingerprintAsync(projectDir, fingerprintOptions)
109+
);
110+
}
111+
112+
function withTemporaryEnv(envVars: Env, fn: () => Promise<any>): Promise<any> {
113+
const originalEnv = { ...process.env };
114+
115+
Object.assign(process.env, envVars);
116+
117+
return fn().finally(() => {
118+
process.env = originalEnv;
119+
});
108120
}
109121

110122
/**

packages/eas-cli/src/fingerprint/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export async function getFingerprintInfoFromLocalProjectForPlatformsAsync(
1515
projectDir: string,
1616
projectId: string,
1717
vcsClient: Client,
18-
platforms: AppPlatform[]
18+
platforms: AppPlatform[],
19+
{ env }: { env?: Record<string, string> } = {}
1920
): Promise<Fingerprint> {
2021
const workflows = await resolveWorkflowPerPlatformAsync(projectDir, vcsClient);
2122
const optionsFromWorkflow = getFingerprintOptionsFromWorkflow(platforms, workflows);
@@ -24,7 +25,7 @@ export async function getFingerprintInfoFromLocalProjectForPlatformsAsync(
2425
...optionsFromWorkflow,
2526
platforms: platforms.map(appPlatformToString),
2627
debug: true,
27-
env: undefined,
28+
env,
2829
});
2930
if (!projectFingerprint) {
3031
throw new Error('Project fingerprints can only be computed for projects with SDK 52 or higher');
@@ -45,6 +46,7 @@ export async function getFingerprintInfoFromLocalProjectForPlatformsAsync(
4546

4647
return projectFingerprint;
4748
}
49+
4850
function getFingerprintOptionsFromWorkflow(
4951
platforms: AppPlatform[],
5052
workflowsByPlatform: Record<Platform, Workflow>

0 commit comments

Comments
 (0)