From 29d45fb2469d7f7aa313a22f1cab4131a3258c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Fri, 19 Jan 2024 20:56:38 +0100 Subject: [PATCH 1/3] Use credentials types from eas-build-job where possible --- packages/eas-cli/src/build/ios/build.ts | 3 +- packages/eas-cli/src/build/ios/credentials.ts | 8 ++-- packages/eas-cli/src/build/ios/prepareJob.ts | 23 +++-------- .../src/credentials/credentialsJson/read.ts | 20 +++++----- .../src/credentials/credentialsJson/types.ts | 40 +++++++------------ .../src/credentials/credentialsJson/update.ts | 31 +++++++------- .../src/credentials/credentialsJson/utils.ts | 4 +- .../credentials/ios/IosCredentialsProvider.ts | 17 ++++---- .../ios/actions/SetUpBuildCredentials.ts | 19 ++++----- ...etUpBuildCredentialsFromCredentialsJson.ts | 4 +- ...rgetBuildCredentialsFromCredentialsJson.ts | 27 +++++++------ ...uildCredentialsFromCredentialsJson-test.ts | 10 ++--- packages/eas-cli/src/credentials/ios/types.ts | 10 ----- 13 files changed, 88 insertions(+), 128 deletions(-) diff --git a/packages/eas-cli/src/build/ios/build.ts b/packages/eas-cli/src/build/ios/build.ts index e2793d04f0..79c7b40f2a 100644 --- a/packages/eas-cli/src/build/ios/build.ts +++ b/packages/eas-cli/src/build/ios/build.ts @@ -6,7 +6,6 @@ import { transformJob } from './graphql'; import { prepareJobAsync } from './prepareJob'; import { syncProjectConfigurationAsync } from './syncProjectConfiguration'; import { resolveRemoteBuildNumberAsync } from './version'; -import { IosCredentials } from '../../credentials/ios/types'; import { BuildParamsInput } from '../../graphql/generated'; import { BuildMutation, BuildResult } from '../../graphql/mutations/BuildMutation'; import { ensureBundleIdentifierIsDefinedForManagedProjectAsync } from '../../project/ios/bundleIdentifier'; @@ -93,7 +92,7 @@ export async function prepareIosBuildAsync( }, prepareJobAsync: async ( ctx: BuildContext, - jobData: JobData + jobData: JobData ): Promise => { return await prepareJobAsync(ctx, { ...jobData, diff --git a/packages/eas-cli/src/build/ios/credentials.ts b/packages/eas-cli/src/build/ios/credentials.ts index 7fe36007ac..619a8c6f32 100644 --- a/packages/eas-cli/src/build/ios/credentials.ts +++ b/packages/eas-cli/src/build/ios/credentials.ts @@ -1,10 +1,10 @@ -import { Platform } from '@expo/eas-build-job'; +import { Ios, Platform } from '@expo/eas-build-job'; import { BuildProfile } from '@expo/eas-json'; import { CredentialsContext } from '../../credentials/context'; import IosCredentialsProvider from '../../credentials/ios/IosCredentialsProvider'; import { getAppFromContextAsync } from '../../credentials/ios/actions/BuildCredentialsUtils'; -import { IosCredentials, Target } from '../../credentials/ios/types'; +import { Target } from '../../credentials/ios/types'; import { CredentialsResult } from '../build'; import { BuildContext } from '../context'; import { logCredentialsSource } from '../utils/credentials'; @@ -12,7 +12,7 @@ import { logCredentialsSource } from '../utils/credentials'; export async function ensureIosCredentialsAsync( buildCtx: BuildContext, targets: Target[] -): Promise | undefined> { +): Promise | undefined> { if (!shouldProvideCredentials(buildCtx)) { return; } @@ -37,7 +37,7 @@ export async function ensureIosCredentialsForBuildResignAsync( credentialsCtx: CredentialsContext, targets: Target[], buildProfile: BuildProfile -): Promise> { +): Promise> { const provider = new IosCredentialsProvider(credentialsCtx, { app: await getAppFromContextAsync(credentialsCtx), targets, diff --git a/packages/eas-cli/src/build/ios/prepareJob.ts b/packages/eas-cli/src/build/ios/prepareJob.ts index 921bf8fec4..04cffcf3f1 100644 --- a/packages/eas-cli/src/build/ios/prepareJob.ts +++ b/packages/eas-cli/src/build/ios/prepareJob.ts @@ -12,7 +12,6 @@ import nullthrows from 'nullthrows'; import path from 'path'; import slash from 'slash'; -import { IosCredentials, TargetCredentials } from '../../credentials/ios/types'; import { IosJobSecretsInput } from '../../graphql/generated'; import { getCustomBuildConfigPath } from '../../project/customBuildConfig'; import { getUsername } from '../../project/projectUtils'; @@ -20,7 +19,7 @@ import { BuildContext } from '../context'; interface JobData { projectArchive: ArchiveSource; - credentials?: IosCredentials; + credentials?: Ios.BuildCredentials; buildScheme: string; } @@ -41,7 +40,7 @@ export async function prepareJobAsync( if (jobData.credentials) { const targetNames = Object.keys(jobData.credentials); for (const targetName of targetNames) { - buildCredentials[targetName] = prepareTargetCredentials(jobData.credentials[targetName]); + buildCredentials[targetName] = jobData.credentials[targetName]; } } @@ -102,28 +101,18 @@ export async function prepareJobAsync( return sanitizeJob(job); } -export function prepareCredentialsToResign(credentials: IosCredentials): IosJobSecretsInput { +export function prepareCredentialsToResign(credentials: Ios.BuildCredentials): IosJobSecretsInput { const buildCredentials: IosJobSecretsInput['buildCredentials'] = []; for (const targetName of Object.keys(credentials ?? {})) { buildCredentials.push({ targetName, - provisioningProfileBase64: nullthrows(credentials?.[targetName].provisioningProfile), + provisioningProfileBase64: nullthrows(credentials?.[targetName].provisioningProfileBase64), distributionCertificate: { - dataBase64: nullthrows(credentials?.[targetName].distributionCertificate.certificateP12), - password: nullthrows(credentials?.[targetName].distributionCertificate.certificatePassword), + dataBase64: nullthrows(credentials?.[targetName].distributionCertificate.dataBase64), + password: nullthrows(credentials?.[targetName].distributionCertificate.password), }, }); } return { buildCredentials }; } - -function prepareTargetCredentials(targetCredentials: TargetCredentials): Ios.TargetCredentials { - return { - provisioningProfileBase64: targetCredentials.provisioningProfile, - distributionCertificate: { - dataBase64: targetCredentials.distributionCertificate.certificateP12, - password: targetCredentials.distributionCertificate.certificatePassword, - }, - }; -} diff --git a/packages/eas-cli/src/credentials/credentialsJson/read.ts b/packages/eas-cli/src/credentials/credentialsJson/read.ts index 409e4c9978..8903f84acf 100644 --- a/packages/eas-cli/src/credentials/credentialsJson/read.ts +++ b/packages/eas-cli/src/credentials/credentialsJson/read.ts @@ -1,14 +1,12 @@ +import { Ios } from '@expo/eas-build-job'; import fs from 'fs-extra'; import path from 'path'; import { AndroidCredentials, CredentialsJson, - CredentialsJsonIosCredentials, CredentialsJsonIosTargetCredentials, CredentialsJsonSchema, - IosCredentials, - IosTargetCredentials, } from './types'; import { getCredentialsJsonPath } from './utils'; import { Target } from '../ios/types'; @@ -32,7 +30,7 @@ export async function readAndroidCredentialsAsync(projectDir: string): Promise { +): Promise { const credentialsJson = await readAsync(projectDir); if (!credentialsJson.ios) { throw new Error('iOS credentials are missing in credentials.json'); @@ -40,7 +38,7 @@ export async function readIosCredentialsAsync( if (isCredentialsMap(credentialsJson.ios)) { const targets = Object.keys(credentialsJson.ios); - const iosCredentials: IosCredentials = {}; + const iosCredentials: Ios.BuildCredentials = {}; for (const target of targets) { iosCredentials[target] = await readCredentialsForTargetAsync( projectDir, @@ -60,26 +58,26 @@ export async function readIosCredentialsAsync( } function isCredentialsMap( - ios: CredentialsJsonIosTargetCredentials | CredentialsJsonIosCredentials -): ios is CredentialsJsonIosCredentials { + ios: Exclude +): ios is Record { return typeof ios.provisioningProfilePath !== 'string'; } async function readCredentialsForTargetAsync( projectDir: string, targetCredentials: CredentialsJsonIosTargetCredentials -): Promise { +): Promise { return { - provisioningProfile: await fs.readFile( + provisioningProfileBase64: await fs.readFile( getAbsolutePath(projectDir, targetCredentials.provisioningProfilePath), 'base64' ), distributionCertificate: { - certificateP12: await fs.readFile( + dataBase64: await fs.readFile( getAbsolutePath(projectDir, targetCredentials.distributionCertificate.path), 'base64' ), - certificatePassword: targetCredentials.distributionCertificate.password, + password: targetCredentials.distributionCertificate.password, }, }; } diff --git a/packages/eas-cli/src/credentials/credentialsJson/types.ts b/packages/eas-cli/src/credentials/credentialsJson/types.ts index e7e9de6ccc..a24a8d9dca 100644 --- a/packages/eas-cli/src/credentials/credentialsJson/types.ts +++ b/packages/eas-cli/src/credentials/credentialsJson/types.ts @@ -2,20 +2,6 @@ import Joi from 'joi'; import { Keystore } from '../android/credentials'; -export interface CredentialsJson { - android?: CredentialsJsonAndroidCredentials; - ios?: CredentialsJsonIosTargetCredentials | CredentialsJsonIosCredentials; -} - -export interface CredentialsJsonAndroidCredentials { - keystore: { - keystorePath: string; - keystorePassword: string; - keyAlias: string; - keyPassword?: string; - }; -} - export interface CredentialsJsonIosTargetCredentials { provisioningProfilePath: string; distributionCertificate: { @@ -23,22 +9,12 @@ export interface CredentialsJsonIosTargetCredentials { password: string; }; } -export type CredentialsJsonIosCredentials = Record; export interface AndroidCredentials { keystore: Keystore; } -export interface IosTargetCredentials { - provisioningProfile: string; - distributionCertificate: { - certificateP12: string; - certificatePassword: string; - }; -} -export type IosCredentials = Record; - -const CredentialsJsonIosTargetCredentialsSchema = Joi.object({ +const CredentialsJsonIosTargetCredentialsSchema = Joi.object({ provisioningProfilePath: Joi.string().required(), distributionCertificate: Joi.object({ path: Joi.string().required(), @@ -46,7 +22,19 @@ const CredentialsJsonIosTargetCredentialsSchema = Joi.object({ }).required(), }); -export const CredentialsJsonSchema = Joi.object({ +export type CredentialsJson = { + android?: { + keystore: { + keystorePath: string; + keystorePassword: string; + keyAlias: string; + keyPassword?: string; + }; + }; + ios?: CredentialsJsonIosTargetCredentials | Record; +}; + +export const CredentialsJsonSchema = Joi.object({ android: Joi.object({ keystore: Joi.object({ keystorePath: Joi.string().required(), diff --git a/packages/eas-cli/src/credentials/credentialsJson/update.ts b/packages/eas-cli/src/credentials/credentialsJson/update.ts index 0ed7c2170d..2c1574a503 100644 --- a/packages/eas-cli/src/credentials/credentialsJson/update.ts +++ b/packages/eas-cli/src/credentials/credentialsJson/update.ts @@ -1,13 +1,10 @@ +import { Ios } from '@expo/eas-build-job'; import fs from 'fs-extra'; import nullthrows from 'nullthrows'; import path from 'path'; import { readRawAsync } from './read'; -import { - CredentialsJson, - CredentialsJsonIosCredentials, - CredentialsJsonIosTargetCredentials, -} from './types'; +import { CredentialsJson, CredentialsJsonIosTargetCredentials } from './types'; import { getCredentialsJsonPath } from './utils'; import { AndroidAppBuildCredentialsFragment, IosDistributionType } from '../../graphql/generated'; import Log from '../../log'; @@ -16,7 +13,7 @@ import zipObject from '../../utils/expodash/zipObject'; import GitClient from '../../vcs/clients/git'; import { Client } from '../../vcs/vcs'; import { CredentialsContext } from '../context'; -import { App, Target, TargetCredentials } from '../ios/types'; +import { App, Target } from '../ios/types'; /** * Update Android credentials.json with values from www, content of credentials.json @@ -112,7 +109,7 @@ export async function updateIosCredentialsAsync( throw new Error(errorMessage); } - const iosCredentials: CredentialsJsonIosCredentials = {}; + const iosCredentials: CredentialsJson['ios'] = {}; const targetCredentialsPathsMap = createTargetCredentialsPathsMap( targets, rawCredentialsJson.ios @@ -209,7 +206,7 @@ async function getTargetBuildCredentialsAsync( app: App, target: Target, iosDistributionType: IosDistributionType -): Promise { +): Promise { const appCredentials = await ctx.ios.getIosAppCredentialsWithCommonFieldsAsync( ctx.graphqlClient, { @@ -237,12 +234,12 @@ async function getTargetBuildCredentialsAsync( } return { distributionCertificate: { - certificateP12: nullthrows(appBuildCredentials.distributionCertificate.certificateP12), - certificatePassword: nullthrows( - appBuildCredentials.distributionCertificate.certificatePassword - ), + dataBase64: nullthrows(appBuildCredentials.distributionCertificate.certificateP12), + password: nullthrows(appBuildCredentials.distributionCertificate.certificatePassword), }, - provisioningProfile: nullthrows(appBuildCredentials.provisioningProfile.provisioningProfile), + provisioningProfileBase64: nullthrows( + appBuildCredentials.provisioningProfile.provisioningProfile + ), }; } @@ -252,7 +249,7 @@ async function backupTargetCredentialsAsync( targetCredentials, targetCredentialsPaths, }: { - targetCredentials: TargetCredentials; + targetCredentials: Ios.TargetCredentials; targetCredentialsPaths: TargetCredentialsPaths; } ): Promise { @@ -262,20 +259,20 @@ async function backupTargetCredentialsAsync( await updateFileAsync( ctx.projectDir, provisioningProfilePath, - targetCredentials.provisioningProfile + targetCredentials.provisioningProfileBase64 ); Log.log(`Writing Distribution Certificate to ${distCertPath}`); await updateFileAsync( ctx.projectDir, distCertPath, - targetCredentials.distributionCertificate.certificateP12 + targetCredentials.distributionCertificate.dataBase64 ); return { distributionCertificate: { path: distCertPath, - password: targetCredentials.distributionCertificate.certificatePassword, + password: targetCredentials.distributionCertificate.password, }, provisioningProfilePath, }; diff --git a/packages/eas-cli/src/credentials/credentialsJson/utils.ts b/packages/eas-cli/src/credentials/credentialsJson/utils.ts index 9dc04430d6..0eb15b9cbd 100644 --- a/packages/eas-cli/src/credentials/credentialsJson/utils.ts +++ b/packages/eas-cli/src/credentials/credentialsJson/utils.ts @@ -1,6 +1,6 @@ +import { Ios } from '@expo/eas-build-job'; import path from 'path'; -import { IosCredentials } from './types'; import { Target } from '../ios/types'; export function getCredentialsJsonPath(projectDir: string): string { @@ -9,7 +9,7 @@ export function getCredentialsJsonPath(projectDir: string): string { export function ensureAllTargetsAreConfigured( targets: Target[], - credentialsJson: IosCredentials + credentialsJson: Ios.BuildCredentials ): void { const notConfiguredTargets: string[] = []; for (const target of targets) { diff --git a/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts b/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts index 5d43a2b7ad..2e607e968f 100644 --- a/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts +++ b/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts @@ -1,4 +1,4 @@ -import { Platform } from '@expo/eas-build-job'; +import { Ios, Platform } from '@expo/eas-build-job'; import { CredentialsSource, DistributionType, @@ -9,7 +9,7 @@ import { import { getAppFromContextAsync } from './actions/BuildCredentialsUtils'; import { SetUpBuildCredentials } from './actions/SetUpBuildCredentials'; import { SetUpPushKey } from './actions/SetUpPushKey'; -import { App, IosCredentials, Target } from './types'; +import { App, Target } from './types'; import { isAdHocProfile, isEnterpriseUniversalProfile } from './utils/provisioningProfile'; import { CommonIosAppCredentialsFragment } from '../../graphql/generated'; import Log from '../../log'; @@ -35,14 +35,11 @@ enum PushNotificationSetupOption { export default class IosCredentialsProvider { public readonly platform = Platform.IOS; - constructor( - private ctx: CredentialsContext, - private options: Options - ) {} + constructor(private ctx: CredentialsContext, private options: Options) {} public async getCredentialsAsync( src: CredentialsSource.LOCAL | CredentialsSource.REMOTE - ): Promise { + ): Promise { let buildCredentials; if (src === CredentialsSource.LOCAL) { buildCredentials = await this.getLocalAsync(); @@ -53,7 +50,7 @@ export default class IosCredentialsProvider { return buildCredentials; } - private async getLocalAsync(): Promise { + private async getLocalAsync(): Promise { const applicationTarget = findApplicationTarget(this.options.targets); const iosCredentials = await credentialsJsonReader.readIosCredentialsAsync( this.ctx.projectDir, @@ -62,14 +59,14 @@ export default class IosCredentialsProvider { ensureAllTargetsAreConfigured(this.options.targets, iosCredentials); for (const target of this.options.targets) { this.assertProvisioningProfileType( - iosCredentials[target.targetName].provisioningProfile, + iosCredentials[target.targetName].provisioningProfileBase64, target.targetName ); } return iosCredentials; } - private async getRemoteAsync(): Promise { + private async getRemoteAsync(): Promise { return await new SetUpBuildCredentials({ app: this.options.app, targets: this.options.targets, diff --git a/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentials.ts b/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentials.ts index b5c8df63d8..3bcded0801 100644 --- a/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentials.ts +++ b/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentials.ts @@ -1,3 +1,4 @@ +import { Ios } from '@expo/eas-build-job'; import { DistributionType, IosEnterpriseProvisioning } from '@expo/eas-json'; import chalk from 'chalk'; import nullthrows from 'nullthrows'; @@ -5,7 +6,7 @@ import nullthrows from 'nullthrows'; import { SetUpTargetBuildCredentials } from './SetUpTargetBuildCredentials'; import Log from '../../../log'; import { CredentialsContext } from '../../context'; -import { App, IosAppBuildCredentialsMap, IosCredentials, Target } from '../types'; +import { App, IosAppBuildCredentialsMap, Target } from '../types'; import { displayProjectCredentials } from '../utils/printCredentials'; interface Options { @@ -18,7 +19,7 @@ interface Options { export class SetUpBuildCredentials { constructor(private options: Options) {} - async runAsync(ctx: CredentialsContext): Promise { + async runAsync(ctx: CredentialsContext): Promise { const hasManyTargets = this.options.targets.length > 1; const iosAppBuildCredentialsMap: IosAppBuildCredentialsMap = {}; if (hasManyTargets) { @@ -71,19 +72,19 @@ export class SetUpBuildCredentials { } } -function toIosCredentials(appBuildCredentialsMap: IosAppBuildCredentialsMap): IosCredentials { +function toIosCredentials(appBuildCredentialsMap: IosAppBuildCredentialsMap): Ios.BuildCredentials { return Object.entries(appBuildCredentialsMap).reduce((acc, [targetName, appBuildCredentials]) => { acc[targetName] = { distributionCertificate: { - certificateP12: nullthrows(appBuildCredentials.distributionCertificate?.certificateP12), - certificatePassword: nullthrows( - appBuildCredentials.distributionCertificate?.certificatePassword - ), + dataBase64: nullthrows(appBuildCredentials.distributionCertificate?.certificateP12), + password: nullthrows(appBuildCredentials.distributionCertificate?.certificatePassword), }, - provisioningProfile: nullthrows(appBuildCredentials.provisioningProfile?.provisioningProfile), + provisioningProfileBase64: nullthrows( + appBuildCredentials.provisioningProfile?.provisioningProfile + ), }; return acc; - }, {} as IosCredentials); + }, {} as Ios.BuildCredentials); } function formatAppInfo({ account, projectName }: App, targets: Target[]): string { diff --git a/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentialsFromCredentialsJson.ts b/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentialsFromCredentialsJson.ts index 0de5951142..5417d13e79 100644 --- a/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentialsFromCredentialsJson.ts +++ b/packages/eas-cli/src/credentials/ios/actions/SetUpBuildCredentialsFromCredentialsJson.ts @@ -1,3 +1,4 @@ +import { Ios } from '@expo/eas-build-job'; import chalk from 'chalk'; import { SetUpTargetBuildCredentialsFromCredentialsJson } from './SetUpTargetBuildCredentialsFromCredentialsJson'; @@ -6,7 +7,6 @@ import Log from '../../../log'; import { findApplicationTarget } from '../../../project/ios/target'; import { CredentialsContext } from '../../context'; import { readIosCredentialsAsync } from '../../credentialsJson/read'; -import { IosCredentials } from '../../credentialsJson/types'; import { ensureAllTargetsAreConfigured } from '../../credentialsJson/utils'; import { App, Target } from '../types'; @@ -45,7 +45,7 @@ export class SetUpBuildCredentialsFromCredentialsJson { } } - private async readCredentialsJsonAsync(ctx: CredentialsContext): Promise { + private async readCredentialsJsonAsync(ctx: CredentialsContext): Promise { const applicationTarget = findApplicationTarget(this.targets); try { return await readIosCredentialsAsync(ctx.projectDir, applicationTarget); diff --git a/packages/eas-cli/src/credentials/ios/actions/SetUpTargetBuildCredentialsFromCredentialsJson.ts b/packages/eas-cli/src/credentials/ios/actions/SetUpTargetBuildCredentialsFromCredentialsJson.ts index 62d2fbe3dc..45bb50cc6c 100644 --- a/packages/eas-cli/src/credentials/ios/actions/SetUpTargetBuildCredentialsFromCredentialsJson.ts +++ b/packages/eas-cli/src/credentials/ios/actions/SetUpTargetBuildCredentialsFromCredentialsJson.ts @@ -1,3 +1,4 @@ +import { Ios } from '@expo/eas-build-job'; import chalk from 'chalk'; import nullthrows from 'nullthrows'; @@ -17,7 +18,6 @@ import { import Log from '../../../log'; import { confirmAsync } from '../../../prompts'; import { CredentialsContext } from '../../context'; -import { IosTargetCredentials } from '../../credentialsJson/types'; import { AppLookupParams } from '../api/graphql/types/AppLookupParams'; import { displayProjectCredentials } from '../utils/printCredentials'; import { readAppleTeam } from '../utils/provisioningProfile'; @@ -26,7 +26,7 @@ export class SetUpTargetBuildCredentialsFromCredentialsJson { constructor( private app: AppLookupParams, private distributionType: IosDistributionType, - private targetCredentials: IosTargetCredentials + private targetCredentials: Ios.TargetCredentials ) {} async runAsync(ctx: CredentialsContext): Promise { @@ -42,7 +42,7 @@ export class SetUpTargetBuildCredentialsFromCredentialsJson { // new credentials from local json const appleTeamFromProvisioningProfile = readAppleTeam( - this.targetCredentials.provisioningProfile + this.targetCredentials.provisioningProfileBase64 ); const appleTeam = await ctx.ios.createOrGetExistingAppleTeamAsync( ctx.graphqlClient, @@ -110,22 +110,22 @@ export class SetUpTargetBuildCredentialsFromCredentialsJson { appleTeam: AppleTeamFragment, currentDistributionCertificate: AppleDistributionCertificateFragment | null ): Promise { - const { certificateP12, certificatePassword } = this.targetCredentials.distributionCertificate; + const { dataBase64, password } = this.targetCredentials.distributionCertificate; if (!currentDistributionCertificate) { return await ctx.ios.createDistributionCertificateAsync(ctx.graphqlClient, this.app.account, { - certP12: certificateP12, - certPassword: certificatePassword, + certP12: dataBase64, + certPassword: password, teamId: appleTeam.appleTeamIdentifier, teamName: appleTeam.appleTeamName ?? undefined, }); } - const isSameCertificate = currentDistributionCertificate.certificateP12 === certificateP12; + const isSameCertificate = currentDistributionCertificate.certificateP12 === dataBase64; if (!isSameCertificate) { return await ctx.ios.createDistributionCertificateAsync(ctx.graphqlClient, this.app.account, { - certP12: certificateP12, - certPassword: certificatePassword, + certP12: dataBase64, + certPassword: password, teamId: appleTeam.appleTeamIdentifier, teamName: appleTeam.appleTeamName ?? undefined, }); @@ -140,13 +140,14 @@ export class SetUpTargetBuildCredentialsFromCredentialsJson { appleTeam: AppleTeamFragment, currentProvisioningProfile: AppleProvisioningProfileFragment | null ): Promise { - const { provisioningProfile } = this.targetCredentials; + const { provisioningProfileBase64 } = this.targetCredentials; if (!currentProvisioningProfile) { return await this.createNewProvisioningProfileAsync(ctx, appleTeam); } - const isSameProfile = currentProvisioningProfile.provisioningProfile === provisioningProfile; + const isSameProfile = + currentProvisioningProfile.provisioningProfile === provisioningProfileBase64; if (!isSameProfile) { return await this.createNewProvisioningProfileAsync(ctx, appleTeam); } @@ -159,7 +160,7 @@ export class SetUpTargetBuildCredentialsFromCredentialsJson { ctx: CredentialsContext, appleTeam: AppleTeamFragment ): Promise { - const { provisioningProfile } = this.targetCredentials; + const { provisioningProfileBase64 } = this.targetCredentials; const appleAppIdentifier = await ctx.ios.createOrGetExistingAppleAppIdentifierAsync( ctx.graphqlClient, @@ -171,7 +172,7 @@ export class SetUpTargetBuildCredentialsFromCredentialsJson { this.app, appleAppIdentifier, { - appleProvisioningProfile: provisioningProfile, + appleProvisioningProfile: provisioningProfileBase64, } ); } diff --git a/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts b/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts index 299e5a8f8a..b6a43e2789 100644 --- a/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts +++ b/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts @@ -1,3 +1,4 @@ +import { Ios } from '@expo/eas-build-job'; import { IosDistributionType } from '../../../../graphql/generated'; import { AppQuery } from '../../../../graphql/queries/AppQuery'; import { findApplicationTarget } from '../../../../project/ios/target'; @@ -14,7 +15,6 @@ import { testProvisioningProfileFragment, testTargets, } from '../../../__tests__/fixtures-ios'; -import { IosTargetCredentials } from '../../../credentialsJson/types'; import { getAppLookupParamsFromContextAsync } from '../BuildCredentialsUtils'; import { SetUpTargetBuildCredentialsFromCredentialsJson } from '../SetUpTargetBuildCredentialsFromCredentialsJson'; @@ -31,12 +31,12 @@ describe('SetUpTargetBuildCredentialsFromCredentialsJson', () => { beforeEach(() => { jest.mocked(AppQuery.byIdAsync).mockResolvedValue(testAppQueryByIdResponse); }); - const targetCredentials: IosTargetCredentials = { + const targetCredentials: Ios.TargetCredentials = { distributionCertificate: { - certificateP12: testDistCert.certP12, - certificatePassword: testDistCert.certPassword, + dataBase64: testDistCert.certP12, + password: testDistCert.certPassword, }, - provisioningProfile: testProvisioningProfile.provisioningProfile, + provisioningProfileBase64: testProvisioningProfile.provisioningProfile, }; it('sets up build credentials with same prior configuration in Interactive Mode', async () => { diff --git a/packages/eas-cli/src/credentials/ios/types.ts b/packages/eas-cli/src/credentials/ios/types.ts index 960454e549..4fbb801cb9 100644 --- a/packages/eas-cli/src/credentials/ios/types.ts +++ b/packages/eas-cli/src/credentials/ios/types.ts @@ -21,15 +21,5 @@ export interface Target { buildSettings?: XCBuildConfiguration['buildSettings']; } -export interface TargetCredentials { - distributionCertificate: { - certificateP12: string; - certificatePassword: string; - }; - provisioningProfile: string; -} - -export type IosCredentials = Record; - export type IosAppBuildCredentialsMap = Record; export type IosAppCredentialsMap = Record; From 29e4256fe7a0cde98ceb39ddad2fd83a200ad403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Fri, 19 Jan 2024 21:11:27 +0000 Subject: [PATCH 2/3] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dd994bb66..b94d1fc1f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This is the log of notable changes to EAS CLI and related packages. ### 🧹 Chores - Remove support for classic updates release channel in 50+. ([#2189](https://github.com/expo/eas-cli/pull/2189) by [@wschurman](https://github.com/wschurman)) +- Migrate to using credentials types from `eas-build-job` where possible. ([#2191](https://github.com/expo/eas-cli/pull/2191) by [@sjchmiela](https://github.com/sjchmiela)) ## [7.0.0](https://github.com/expo/eas-cli/releases/tag/v7.0.0) - 2024-01-19 From d8e8060a89827a35eaf280da43a02a7ad8e58f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Fri, 19 Jan 2024 20:56:38 +0100 Subject: [PATCH 3/3] Use credentials types from eas-build-job where possible --- .../credentialsJson/__tests__/read-test.ts | 18 +++++++++--------- .../credentials/ios/IosCredentialsProvider.ts | 5 ++++- .../__tests__/IosCredentialsProvider-test.ts | 6 +++--- ...BuildCredentialsFromCredentialsJson-test.ts | 1 + 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/eas-cli/src/credentials/credentialsJson/__tests__/read-test.ts b/packages/eas-cli/src/credentials/credentialsJson/__tests__/read-test.ts index 1b5c3d773b..9d112368b8 100644 --- a/packages/eas-cli/src/credentials/credentialsJson/__tests__/read-test.ts +++ b/packages/eas-cli/src/credentials/credentialsJson/__tests__/read-test.ts @@ -109,10 +109,10 @@ describe('credentialsJson', () => { const result = await credentialsJsonReader.readIosCredentialsAsync('.', applicationTarget); expect(result).toEqual({ [applicationTarget.targetName]: { - provisioningProfile: 'c29tZWJpbmFyeWNvbnRlbnQ=', + provisioningProfileBase64: 'c29tZWJpbmFyeWNvbnRlbnQ=', distributionCertificate: { - certificateP12: 'c29tZWJpbmFyeWNvbnRlbnQy', - certificatePassword: 'certPass', + dataBase64: 'c29tZWJpbmFyeWNvbnRlbnQy', + password: 'certPass', }, }, }); @@ -230,17 +230,17 @@ describe('credentialsJson', () => { ); expect(result).toEqual({ target1: { - provisioningProfile: 'cHByb2ZpbGUtMS1zb21lYmluYXJ5Y29udGVudA==', + provisioningProfileBase64: 'cHByb2ZpbGUtMS1zb21lYmluYXJ5Y29udGVudA==', distributionCertificate: { - certificateP12: 'Y2VydC0xLXNvbWViaW5hcnljb250ZW50', - certificatePassword: 'cert-pass-1', + dataBase64: 'Y2VydC0xLXNvbWViaW5hcnljb250ZW50', + password: 'cert-pass-1', }, }, target2: { - provisioningProfile: 'cHByb2ZpbGUtMi1zb21lYmluYXJ5Y29udGVudA==', + provisioningProfileBase64: 'cHByb2ZpbGUtMi1zb21lYmluYXJ5Y29udGVudA==', distributionCertificate: { - certificateP12: 'Y2VydC0yLXNvbWViaW5hcnljb250ZW50', - certificatePassword: 'cert-pass-2', + dataBase64: 'Y2VydC0yLXNvbWViaW5hcnljb250ZW50', + password: 'cert-pass-2', }, }, }); diff --git a/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts b/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts index 2e607e968f..15b779c483 100644 --- a/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts +++ b/packages/eas-cli/src/credentials/ios/IosCredentialsProvider.ts @@ -35,7 +35,10 @@ enum PushNotificationSetupOption { export default class IosCredentialsProvider { public readonly platform = Platform.IOS; - constructor(private ctx: CredentialsContext, private options: Options) {} + constructor( + private ctx: CredentialsContext, + private options: Options + ) {} public async getCredentialsAsync( src: CredentialsSource.LOCAL | CredentialsSource.REMOTE diff --git a/packages/eas-cli/src/credentials/ios/__tests__/IosCredentialsProvider-test.ts b/packages/eas-cli/src/credentials/ios/__tests__/IosCredentialsProvider-test.ts index 9965a1de74..01b88fdd74 100644 --- a/packages/eas-cli/src/credentials/ios/__tests__/IosCredentialsProvider-test.ts +++ b/packages/eas-cli/src/credentials/ios/__tests__/IosCredentialsProvider-test.ts @@ -125,10 +125,10 @@ describe(IosCredentialsProvider, () => { { testapp: { distributionCertificate: { - certificateP12: buildCredentials.distributionCertificate?.certificateP12, - certificatePassword: buildCredentials.distributionCertificate?.certificatePassword, + dataBase64: buildCredentials.distributionCertificate?.certificateP12, + password: buildCredentials.distributionCertificate?.certificatePassword, }, - provisioningProfile: buildCredentials.provisioningProfile?.provisioningProfile, + provisioningProfileBase64: buildCredentials.provisioningProfile?.provisioningProfile, }, } ); diff --git a/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts b/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts index b6a43e2789..95e818cad0 100644 --- a/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts +++ b/packages/eas-cli/src/credentials/ios/actions/__tests__/SetUpTargetBuildCredentialsFromCredentialsJson-test.ts @@ -1,4 +1,5 @@ import { Ios } from '@expo/eas-build-job'; + import { IosDistributionType } from '../../../../graphql/generated'; import { AppQuery } from '../../../../graphql/queries/AppQuery'; import { findApplicationTarget } from '../../../../project/ios/target';