-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add eas env:push and env:pull commands (#2495)
* Implement `eas env:pull` and `eas env:push` commands * Implement review suggestions * Implement review suggestions * Allow fetching sensitive variables with env:get * Implement review suggestions * fix push * Implement `including-sensitive` for env:list * Use envvariables in local build * Remove withSudo * Remove sudo * Evaluate dynamicProjectConfig with EnvVars
- Loading branch information
1 parent
1540b13
commit 56510f0
Showing
30 changed files
with
7,557 additions
and
1,040 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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
81 changes: 81 additions & 0 deletions
81
packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts
This file contains 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,81 @@ | ||
import { Env } from '@expo/eas-build-job'; | ||
import { BuildProfile } from '@expo/eas-json'; | ||
|
||
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient'; | ||
import { EnvironmentVariableEnvironment } from '../graphql/generated'; | ||
import { EnvironmentVariablesQuery } from '../graphql/queries/EnvironmentVariablesQuery'; | ||
import Log from '../log'; | ||
|
||
function isEnvironment(env: string): env is EnvironmentVariableEnvironment { | ||
return Object.values(EnvironmentVariableEnvironment).includes( | ||
env.toUpperCase() as EnvironmentVariableEnvironment | ||
); | ||
} | ||
|
||
export async function evaluateConfigWithEnvVarsAsync<Config extends { projectId: string }, Opts>({ | ||
flags, | ||
buildProfile, | ||
graphqlClient, | ||
getProjectConfig, | ||
opts, | ||
}: { | ||
flags: { environment?: string }; | ||
buildProfile: BuildProfile; | ||
graphqlClient: ExpoGraphqlClient | null; | ||
opts: Opts; | ||
getProjectConfig(opts: Opts): Promise<Config>; | ||
}): Promise<Config & { env: Env }> { | ||
if (!graphqlClient) { | ||
Log.warn('An Expo user account is required to fetch environment variables.'); | ||
const config = await getProjectConfig(opts); | ||
return { env: buildProfile.env ?? {}, ...config }; | ||
} | ||
const { projectId } = await getProjectConfig({ env: buildProfile.env, ...opts }); | ||
const env = await resolveEnvVarsAsync({ flags, buildProfile, graphqlClient, projectId }); | ||
const config = await getProjectConfig({ ...opts, env }); | ||
|
||
return { env, ...config }; | ||
} | ||
|
||
async function resolveEnvVarsAsync({ | ||
flags, | ||
buildProfile, | ||
graphqlClient, | ||
projectId, | ||
}: { | ||
flags: { environment?: string }; | ||
buildProfile: BuildProfile; | ||
graphqlClient: ExpoGraphqlClient; | ||
projectId: string; | ||
}): Promise<Env> { | ||
const environment = | ||
flags.environment ?? buildProfile.environment ?? process.env.EAS_CURRENT_ENVIRONMENT; | ||
|
||
if (!environment || !isEnvironment(environment)) { | ||
return { ...buildProfile.env }; | ||
} | ||
|
||
try { | ||
const environmentVariables = await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync( | ||
graphqlClient, | ||
{ | ||
appId: projectId, | ||
environment, | ||
} | ||
); | ||
const envVars = Object.fromEntries( | ||
environmentVariables | ||
.filter(({ name, value }) => name && value) | ||
.map(({ name, value }) => [name, value]) | ||
) as Record<string, string>; | ||
|
||
return { ...envVars, ...buildProfile.env }; | ||
} catch (e) { | ||
Log.error('Failed to pull env variables for environment ${environment} from EAS servers'); | ||
Log.error(e); | ||
Log.error( | ||
'This can possibly be a bug in EAS/EAS CLI. Report it here: https://github.com/expo/eas-cli/issues' | ||
); | ||
return { ...buildProfile.env }; | ||
} | ||
} |
This file contains 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 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 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 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 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.