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] Automatically migrate build credentials to EAS #477

Merged
merged 7 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ 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 { promptAsync } from '../../../prompts';
import { findAccountByName } from '../../../user/Account';
import { Context } from '../../context';
import { AppLookupParams } from '../api/GraphqlClient';
Expand Down Expand Up @@ -34,62 +33,57 @@ export async function promptUserAndCopyLegacyCredentialsAsync(
ctx: Context,
app: AppLookupParams
): Promise<void> {
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(`Unable to migrate credentials to EAS.`);
throw e;
}
spinner.succeed('Credentials successfully copied');

spinner.succeed('Credentials copied to EAS.');
}

export function getAppLookupParamsFromContext(ctx: Context): AppLookupParams {
Expand Down Expand Up @@ -135,9 +129,8 @@ export async function createOrUpdateDefaultAndroidAppBuildCredentialsAsync(
{ androidKeystoreId }
);
}
const providedName = await promptForNameAsync();
return await ctx.android.createAndroidAppBuildCredentialsAsync(appLookupParams, {
name: providedName,
name: generateRandomName(),
isDefault: true,
androidKeystoreId,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nullthrows from 'nullthrows';
import ora from 'ora';

import {
AndroidAppBuildCredentialsFragment,
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down