Skip to content
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

[eas-cli] Combine .env and EAS environment variables for deploy command #2783

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow env vars to be loaded from .env and EAS env simultaneously
  • Loading branch information
kitten committed Jan 8, 2025
commit ac0e4411706c76968ee4bf5bd5cec85eabbc3cf0
11 changes: 9 additions & 2 deletions packages/eas-cli/src/commands/worker/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,28 @@ export default class WorkerDeploy extends EasCommand {
let progress = ora('Preparing project').start();

try {
const manifest = await WorkerAssets.createManifestAsync(
const manifestResult = await WorkerAssets.createManifestAsync(
{
environment: flags.environment,
projectDir,
projectId,
},
graphqlClient
);
if (manifestResult.conflictingVariableNames?.length) {
Log.warn(
'> The following environment variables were loaded both from local .env files as well as EAS environment variables, '
+ ' and will be set to the EAS environment variable values instead: '
+ manifestResult.conflictingVariableNames.join(' '),
);
}
assetMap = await WorkerAssets.createAssetMapAsync(
projectDist.type === 'server' ? projectDist.clientPath : projectDist.path
);
tarPath = await WorkerAssets.packFilesIterableAsync(
emitWorkerTarballAsync({
assetMap,
manifest,
manifest: manifestResult.manifest,
})
);

Expand Down
43 changes: 28 additions & 15 deletions packages/eas-cli/src/worker/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export interface Manifest {
env: Record<string, string | undefined>;
}

export interface CreateManifestResult {
conflictingVariableNames: string[] | undefined;
manifest: Manifest;
}

interface CreateManifestParams {
projectId: string;
projectDir: string;
Expand All @@ -108,23 +113,31 @@ interface CreateManifestParams {
export async function createManifestAsync(
params: CreateManifestParams,
graphqlClient: ExpoGraphqlClient
): Promise<Manifest> {
let env: Record<string, string | undefined>;
): Promise<CreateManifestResult> {
// NOTE: This is required for the .env resolution
process.env.NODE_ENV = 'production';
kitten marked this conversation as resolved.
Show resolved Hide resolved
// Resolve .env file variables
const env: Record<string, string | undefined> = getEnv(params.projectDir).env;
kitten marked this conversation as resolved.
Show resolved Hide resolved
// Maybe load EAS Environment Variables (based on `--environment` arg)
let conflictingVariableNames: string[] | undefined;
if (params.environment) {
env = Object.fromEntries(
(
await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
appId: params.projectId,
environment: params.environment,
})
).map(variable => [variable.name, variable.value ?? undefined])
);
} else {
// NOTE: This is required for the .env resolution
process.env.NODE_ENV = 'production';
env = getEnv(params.projectDir).env;
const loadedVariables = await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
appId: params.projectId,
environment: params.environment,
});
// Load EAS Env vars into `env` object, keeping track of conflicts
conflictingVariableNames = [];
for (const variable of loadedVariables) {
if (variable.value != null) {
if (env[variable.name] != null) {
conflictingVariableNames.push(variable.name);
}
env[variable.name] = variable.value;
}
}
}
kitten marked this conversation as resolved.
Show resolved Hide resolved
return { env };
const manifest: Manifest = { env };
return { conflictingVariableNames, manifest };
}

interface WorkerFileEntry {
Expand Down