Skip to content

Commit 0953622

Browse files
committed
[eas-cli] add support for build profiles in fingerprint generation
1 parent ff9843d commit 0953622

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ export async function getFingerprintInfoFromLocalProjectForPlatformsAsync(
440440
projectDir: string,
441441
projectId: string,
442442
vcsClient: Client,
443-
platforms: AppPlatform[]
443+
platforms: AppPlatform[],
444+
{ env }: { env?: Record<string, string> } = {}
444445
): Promise<Fingerprint> {
445446
const workflows = await resolveWorkflowPerPlatformAsync(projectDir, vcsClient);
446447
const optionsFromWorkflow = getFingerprintOptionsFromWorkflow(platforms, workflows);
@@ -449,7 +450,7 @@ export async function getFingerprintInfoFromLocalProjectForPlatformsAsync(
449450
...optionsFromWorkflow,
450451
platforms: platforms.map(appPlatformToString),
451452
debug: true,
452-
env: undefined,
453+
env,
453454
});
454455
if (!projectFingerprint) {
455456
throw new Error('Project fingerprints can only be computed for projects with SDK 52 or higher');

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

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
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 {
46
getFingerprintInfoFromLocalProjectForPlatformsAsync,
57
stringToAppPlatform,
68
} from './compare';
79
import { getExpoWebsiteBaseUrl } from '../../api';
10+
import { evaluateConfigWithEnvVarsAsync } from '../../build/evaluateConfigWithEnvVarsAsync';
811
import EasCommand from '../../commandUtils/EasCommand';
912
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
1013
import { AppPlatform } from '../../graphql/generated';
1114
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 --json --non-interactive --platform android \t # Output fingerprint json to stdout',
2428
];
2529

2630
static override flags = {
2731
platform: Flags.enum({
2832
char: 'p',
2933
options: ['android', 'ios'],
3034
}),
35+
profile: Flags.string({
36+
char: 'e',
37+
description: 'Name of the build profile from eas.json.',
38+
}),
3139
...EasNonInteractiveAndJsonFlags,
3240
};
3341

@@ -36,17 +44,24 @@ export default class FingerprintGenerate extends EasCommand {
3644
...this.ContextOptions.ProjectConfig,
3745
...this.ContextOptions.LoggedIn,
3846
...this.ContextOptions.Vcs,
47+
...this.ContextOptions.DynamicProjectConfig,
3948
};
4049

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

4559
const {
4660
projectId,
4761
privateProjectConfig: { projectDir },
4862
loggedIn: { graphqlClient },
4963
vcsClient,
64+
getDynamicPrivateProjectConfigAsync,
5065
} = await this.getContextAsync(FingerprintGenerate, {
5166
nonInteractive,
5267
withServerSideEnvironment: null,
@@ -64,12 +79,39 @@ export default class FingerprintGenerate extends EasCommand {
6479
}
6580
platform = await selectRequestedPlatformAsync();
6681
}
82+
83+
let env: Env | undefined;
84+
if (buildProfileName) {
85+
const easJsonAccessor = EasJsonAccessor.fromProjectPath(projectDir);
86+
const buildProfile = (
87+
await getProfilesAsync({
88+
type: 'build',
89+
easJsonAccessor,
90+
platforms: [appPlatformtoPlatform(platform)],
91+
profileName: buildProfileName ?? undefined,
92+
projectDir,
93+
})
94+
)[0];
95+
if (!buildProfile) {
96+
throw new Error(`Build profile ${buildProfile} not found for platform: ${platform}`);
97+
}
98+
const configResult = await evaluateConfigWithEnvVarsAsync({
99+
buildProfile: buildProfile.profile,
100+
buildProfileName: buildProfile.profileName,
101+
graphqlClient,
102+
getProjectConfig: getDynamicPrivateProjectConfigAsync,
103+
opts: { env: buildProfile.profile.env },
104+
});
105+
env = configResult.env;
106+
}
107+
67108
const fingerprint = await getFingerprintInfoFromLocalProjectForPlatformsAsync(
68109
graphqlClient,
69110
projectDir,
70111
projectId,
71112
vcsClient,
72-
[platform]
113+
[platform],
114+
{ env }
73115
);
74116

75117
if (json) {
@@ -101,3 +143,13 @@ export async function selectRequestedPlatformAsync(): Promise<AppPlatform> {
101143
});
102144
return requestedPlatform;
103145
}
146+
147+
function appPlatformtoPlatform(appPlatform: AppPlatform): Platform {
148+
if (appPlatform === AppPlatform.Android) {
149+
return Platform.ANDROID;
150+
} else if (appPlatform === AppPlatform.Ios) {
151+
return Platform.IOS;
152+
} else {
153+
throw new Error('Unsupported platform: ' + appPlatform);
154+
}
155+
}

packages/eas-cli/src/platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function selectPlatformAsync(platform?: string): Promise<Platform>
6464
return resolvedPlatform;
6565
}
6666

67-
export function toPlatforms(requestedPlatform: RequestedPlatform): Platform[] {
67+
export function toPlatform(requestedPlatform: RequestedPlatform): Platform[] {
6868
if (requestedPlatform === RequestedPlatform.All) {
6969
return [Platform.ANDROID, Platform.IOS];
7070
} else if (requestedPlatform === RequestedPlatform.Android) {

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

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

110123
/**

0 commit comments

Comments
 (0)