From 16e420f740ecf9868098034d89f6eabb4193d5a4 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 24 Jun 2021 17:11:45 -0700 Subject: [PATCH 1/7] [eas-cli] Automatically migrate build credentials to EAS --- .../android/actions/BuildCredentialsUtils.ts | 104 ++++++++---------- 1 file changed, 43 insertions(+), 61 deletions(-) diff --git a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts index 5769fdb83b..93a58d2ecb 100644 --- a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts +++ b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts @@ -3,10 +3,8 @@ import { nanoid } from 'nanoid'; import ora from 'ora'; import { AndroidAppBuildCredentialsFragment } from '../../../graphql/generated'; -import Log from '../../../log'; import { getApplicationId } from '../../../project/android/applicationId'; import { getProjectAccountName, getProjectConfigDescription } from '../../../project/projectUtils'; -import { confirmAsync, promptAsync } from '../../../prompts'; import { findAccountByName } from '../../../user/Account'; import { Context } from '../../context'; import { AppLookupParams } from '../api/GraphqlClient'; @@ -34,62 +32,57 @@ export async function promptUserAndCopyLegacyCredentialsAsync( ctx: Context, app: AppLookupParams ): Promise { - assert( - !ctx.nonInteractive, - 'Copying over Expo Classic credentials cannot be run in non-interactive mode' - ); assert( await canCopyLegacyCredentialsAsync(ctx, app), - 'User not eligible to copy Expo Classic credentials to EAS' + 'User not eligible to copy classic build credentials to EAS' ); - const shouldCopy = await confirmAsync({ - message: `We've detected credentials from Expo Classic (expo-cli). Would you like to copy them over to Expo Application Services (EAS)?`, - }); - if (!shouldCopy) { - return; - } - Log.log('Copying credentials...'); - const spinner = ora().start(); + const spinner = ora('Classic credentials detected, copying to EAS...').start(); - const legacyAppCredentials = await ctx.android.getLegacyAndroidAppCredentialsWithCommonFieldsAsync( - app - ); - if (!legacyAppCredentials) { - return; - } + try { + const legacyAppCredentials = await ctx.android.getLegacyAndroidAppCredentialsWithCommonFieldsAsync( + app + ); + if (!legacyAppCredentials) { + return; + } - const appCredentials = await ctx.android.createOrGetExistingAndroidAppCredentialsWithBuildCredentialsAsync( - app - ); - const legacyFcm = legacyAppCredentials.androidFcm; - if (legacyFcm) { - const clonedFcm = await ctx.android.createFcmAsync( - app.account, - legacyFcm.credential, - legacyFcm.version + const appCredentials = await ctx.android.createOrGetExistingAndroidAppCredentialsWithBuildCredentialsAsync( + app ); - await ctx.android.updateAndroidAppCredentialsAsync(appCredentials, { - androidFcmId: clonedFcm.id, - }); - } + const legacyFcm = legacyAppCredentials.androidFcm; + if (legacyFcm) { + const clonedFcm = await ctx.android.createFcmAsync( + app.account, + legacyFcm.credential, + legacyFcm.version + ); + await ctx.android.updateAndroidAppCredentialsAsync(appCredentials, { + androidFcmId: clonedFcm.id, + }); + } - const legacyBuildCredentials = await ctx.android.getLegacyAndroidAppBuildCredentialsAsync(app); - const legacyKeystore = legacyBuildCredentials?.androidKeystore ?? null; - - if (legacyKeystore) { - const clonedKeystore = await ctx.android.createKeystoreAsync(app.account, { - keystore: legacyKeystore.keystore, - keystorePassword: legacyKeystore.keystorePassword, - keyAlias: legacyKeystore.keyAlias, - keyPassword: legacyKeystore.keyPassword ?? undefined, - type: legacyKeystore.type, - }); - await createOrUpdateDefaultAndroidAppBuildCredentialsAsync(ctx, app, { - androidKeystoreId: clonedKeystore.id, - }); + const legacyBuildCredentials = await ctx.android.getLegacyAndroidAppBuildCredentialsAsync(app); + const legacyKeystore = legacyBuildCredentials?.androidKeystore ?? null; + + if (legacyKeystore) { + const clonedKeystore = await ctx.android.createKeystoreAsync(app.account, { + keystore: legacyKeystore.keystore, + keystorePassword: legacyKeystore.keystorePassword, + keyAlias: legacyKeystore.keyAlias, + keyPassword: legacyKeystore.keyPassword ?? undefined, + type: legacyKeystore.type, + }); + await createOrUpdateDefaultAndroidAppBuildCredentialsAsync(ctx, app, { + androidKeystoreId: clonedKeystore.id, + }); + } + } catch (e) { + spinner.fail(e.message); + return; } - spinner.succeed('Credentials successfully copied'); + + spinner.succeed('Credentials copied to EAS.'); } export function getAppLookupParamsFromContext(ctx: Context): AppLookupParams { @@ -135,7 +128,7 @@ export async function createOrUpdateDefaultAndroidAppBuildCredentialsAsync( { androidKeystoreId } ); } - const providedName = await promptForNameAsync(); + const providedName = generateRandomName(); return await ctx.android.createAndroidAppBuildCredentialsAsync(appLookupParams, { name: providedName, isDefault: true, @@ -143,17 +136,6 @@ export async function createOrUpdateDefaultAndroidAppBuildCredentialsAsync( }); } -export async function promptForNameAsync(): Promise { - const { providedName } = await promptAsync({ - type: 'text', - name: 'providedName', - message: 'Assign a name to your build credentials:', - initial: generateRandomName(), - validate: (input: string) => input !== '', - }); - return providedName; -} - /** * sort a build credentials array in descending order of preference * prefer default credentials, then prefer names that come first lexicographically From b346561bc9877a2670c101fa0f6e4d813db1faa8 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 24 Jun 2021 17:12:58 -0700 Subject: [PATCH 2/7] [eas-cli] Improve error message --- .../src/credentials/android/actions/BuildCredentialsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts index 93a58d2ecb..5808302798 100644 --- a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts +++ b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts @@ -78,7 +78,7 @@ export async function promptUserAndCopyLegacyCredentialsAsync( }); } } catch (e) { - spinner.fail(e.message); + spinner.fail(`Unable to migrate credentials to EAS. Error: ${e.message}`); return; } From e10f4b831f00f0b76263032edc596ec914410518 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 24 Jun 2021 17:13:50 -0700 Subject: [PATCH 3/7] [eas-cli] Skip intermediary variable --- .../src/credentials/android/actions/BuildCredentialsUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts index 5808302798..4129e6afbc 100644 --- a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts +++ b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts @@ -128,9 +128,8 @@ export async function createOrUpdateDefaultAndroidAppBuildCredentialsAsync( { androidKeystoreId } ); } - const providedName = generateRandomName(); return await ctx.android.createAndroidAppBuildCredentialsAsync(appLookupParams, { - name: providedName, + name: generateRandomName(), isDefault: true, androidKeystoreId, }); From 5c0527473d1e4fa70682dd8133569381e2027ae6 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 24 Jun 2021 17:14:47 -0700 Subject: [PATCH 4/7] [eas-cli] Rethrow error instead of swallowing --- .../src/credentials/android/actions/BuildCredentialsUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts index 4129e6afbc..14409fc13b 100644 --- a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts +++ b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts @@ -78,8 +78,8 @@ export async function promptUserAndCopyLegacyCredentialsAsync( }); } } catch (e) { - spinner.fail(`Unable to migrate credentials to EAS. Error: ${e.message}`); - return; + spinner.fail(`Unable to migrate credentials to EAS.`); + throw e; } spinner.succeed('Credentials copied to EAS.'); From 8a4c9500b20fe7278d3402b0184f261aab04d26d Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 24 Jun 2021 17:16:49 -0700 Subject: [PATCH 5/7] [eas-cli] Add back promptForNameAsync --- .../android/actions/BuildCredentialsUtils.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts index 14409fc13b..1c4632078f 100644 --- a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts +++ b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts @@ -5,6 +5,7 @@ import ora from 'ora'; import { AndroidAppBuildCredentialsFragment } from '../../../graphql/generated'; import { getApplicationId } from '../../../project/android/applicationId'; import { getProjectAccountName, getProjectConfigDescription } from '../../../project/projectUtils'; +import { promptAsync } from '../../../prompts'; import { findAccountByName } from '../../../user/Account'; import { Context } from '../../context'; import { AppLookupParams } from '../api/GraphqlClient'; @@ -135,6 +136,17 @@ export async function createOrUpdateDefaultAndroidAppBuildCredentialsAsync( }); } +export async function promptForNameAsync(): Promise { + const { providedName } = await promptAsync({ + type: 'text', + name: 'providedName', + message: 'Assign a name to your build credentials:', + initial: generateRandomName(), + validate: (input: string) => input !== '', + }); + return providedName; +} + /** * sort a build credentials array in descending order of preference * prefer default credentials, then prefer names that come first lexicographically @@ -154,4 +166,4 @@ export function sortBuildCredentials( function generateRandomName(): string { return `Build Credentials ${nanoid(10)}`; -} +} \ No newline at end of file From cdc228697933bb2b8402a3e120a1822e568207fd Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 24 Jun 2021 17:23:47 -0700 Subject: [PATCH 6/7] [eas-cli] Use ora to match style of other logs --- .../credentials/android/actions/SetupBuildCredentials.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/eas-cli/src/credentials/android/actions/SetupBuildCredentials.ts b/packages/eas-cli/src/credentials/android/actions/SetupBuildCredentials.ts index e4cbd137a8..de1a37f00c 100644 --- a/packages/eas-cli/src/credentials/android/actions/SetupBuildCredentials.ts +++ b/packages/eas-cli/src/credentials/android/actions/SetupBuildCredentials.ts @@ -1,4 +1,5 @@ import nullthrows from 'nullthrows'; +import ora from 'ora'; import { AndroidAppBuildCredentialsFragment, @@ -94,9 +95,9 @@ export class SetupBuildCredentials { ); const defaultKeystore = defaultBuildCredentials?.androidKeystore ?? null; if (defaultKeystore) { - Log.log( + ora( `Using Keystore from configuration: ${nullthrows(defaultBuildCredentials).name} (default)` - ); + ).succeed(); return defaultBuildCredentials; } return null; @@ -118,11 +119,11 @@ export class SetupBuildCredentials { const keystore = maybeBuildCredentials?.androidKeystore ?? null; if (keystore) { const buildCredentials = nullthrows(maybeBuildCredentials); - Log.log( + ora( `Using Keystore from configuration: ${buildCredentials.name}${ buildCredentials.isDefault ? ' (default)' : '' }` - ); + ).succeed(); return buildCredentials; } Log.log( From 20d77bf89759544fe465ac933f33088d2c798286 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Thu, 24 Jun 2021 17:24:18 -0700 Subject: [PATCH 7/7] Fix lint warning --- .../src/credentials/android/actions/BuildCredentialsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts index 1c4632078f..e3e97abe33 100644 --- a/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts +++ b/packages/eas-cli/src/credentials/android/actions/BuildCredentialsUtils.ts @@ -166,4 +166,4 @@ export function sortBuildCredentials( function generateRandomName(): string { return `Build Credentials ${nanoid(10)}`; -} \ No newline at end of file +}