From ef3448f08bbc89502f0b6eff6d5077bbbc507c04 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/2] 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 +++++++------ packages/eas-cli/src/credentials/ios/types.ts | 10 ----- 12 files changed, 83 insertions(+), 123 deletions(-) diff --git a/packages/eas-cli/src/build/ios/build.ts b/packages/eas-cli/src/build/ios/build.ts index 8735eb90fb..68d24e7e78 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'; @@ -94,7 +93,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/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 5c710eb4789fe09922a1084752edb67f3990d2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Fri, 19 Jan 2024 22:06:41 +0100 Subject: [PATCH 2/2] Add provisioningProfileType --- .../src/credentials/credentialsJson/read.ts | 4 +++ .../ios/appstore/Credentials.types.ts | 26 ++++++++++++++++ .../ios/appstore/provisioningProfile.ts | 18 +++++------ .../ios/appstore/provisioningProfileAdhoc.ts | 30 ++++++++++++++----- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/packages/eas-cli/src/credentials/credentialsJson/read.ts b/packages/eas-cli/src/credentials/credentialsJson/read.ts index 8903f84acf..225076eb45 100644 --- a/packages/eas-cli/src/credentials/credentialsJson/read.ts +++ b/packages/eas-cli/src/credentials/credentialsJson/read.ts @@ -72,6 +72,10 @@ async function readCredentialsForTargetAsync( getAbsolutePath(projectDir, targetCredentials.provisioningProfilePath), 'base64' ), + provisioningProfileType: + path.extname(targetCredentials.provisioningProfilePath) === 'provisionprofile' + ? Ios.ProvisioningProfileType.PROVISIONPROFILE + : Ios.ProvisioningProfileType.MOBILEPROVISION, distributionCertificate: { dataBase64: await fs.readFile( getAbsolutePath(projectDir, targetCredentials.distributionCertificate.path), diff --git a/packages/eas-cli/src/credentials/ios/appstore/Credentials.types.ts b/packages/eas-cli/src/credentials/ios/appstore/Credentials.types.ts index 8ef8028fad..4ecf727a60 100644 --- a/packages/eas-cli/src/credentials/ios/appstore/Credentials.types.ts +++ b/packages/eas-cli/src/credentials/ios/appstore/Credentials.types.ts @@ -1,4 +1,6 @@ +import { ProfileType } from '@expo/app-store'; import { UserRole } from '@expo/apple-utils'; +import { Ios } from '@expo/eas-build-job'; export interface DistributionCertificateStoreInfo { id: string; @@ -26,6 +28,30 @@ export interface ProvisioningProfile { provisioningProfile: string; teamId: string; teamName?: string; + provisioningProfileType: Ios.ProvisioningProfileType; +} + +export function getProvisioningProfileTypeForDistributionMethod( + distributionMethod: ProfileType +): Ios.ProvisioningProfileType { + switch (distributionMethod) { + case ProfileType.IOS_APP_DEVELOPMENT: + case ProfileType.IOS_APP_STORE: + case ProfileType.IOS_APP_ADHOC: + case ProfileType.IOS_APP_INHOUSE: + case ProfileType.TVOS_APP_DEVELOPMENT: + case ProfileType.TVOS_APP_STORE: + case ProfileType.TVOS_APP_ADHOC: + case ProfileType.TVOS_APP_INHOUSE: + return Ios.ProvisioningProfileType.MOBILEPROVISION; + case ProfileType.MAC_APP_DEVELOPMENT: + case ProfileType.MAC_APP_STORE: + case ProfileType.MAC_APP_DIRECT: + case ProfileType.MAC_CATALYST_APP_DEVELOPMENT: + case ProfileType.MAC_CATALYST_APP_STORE: + case ProfileType.MAC_CATALYST_APP_DIRECT: + return Ios.ProvisioningProfileType.PROVISIONPROFILE; + } } export interface ProvisioningProfileStoreInfo extends ProvisioningProfile { diff --git a/packages/eas-cli/src/credentials/ios/appstore/provisioningProfile.ts b/packages/eas-cli/src/credentials/ios/appstore/provisioningProfile.ts index 84138d2c63..dcef4db410 100644 --- a/packages/eas-cli/src/credentials/ios/appstore/provisioningProfile.ts +++ b/packages/eas-cli/src/credentials/ios/appstore/provisioningProfile.ts @@ -4,6 +4,7 @@ import { DistributionCertificate, ProvisioningProfile, ProvisioningProfileStoreInfo, + getProvisioningProfileTypeForDistributionMethod, } from './Credentials.types'; import { getRequestContext } from './authenticate'; import { AuthCtx } from './authenticateTypes'; @@ -71,8 +72,11 @@ async function transformProfileAsync( status: cert.attributes.profileState, expires: new Date(cert.attributes.expirationDate).getTime() / 1000, distributionMethod: cert.attributes.profileType, - // @ts-ignore -- this can be null when the profile has expired. - provisioningProfile: cert.attributes.profileContent, + provisioningProfileType: getProvisioningProfileTypeForDistributionMethod( + cert.attributes.profileType + ), + // this can be null when the profile has expired. + provisioningProfile: cert.attributes.profileContent as string, certificates: (await cert.getCertificatesAsync()).map(transformCertificate), teamId: authCtx.team.id, teamName: authCtx.team.name, @@ -147,17 +151,13 @@ export async function useExistingProvisioningProfileAsync( `Provisioning profile "${profile.attributes.name}" (${profile.id}) is expired!` ); } - const result = { - provisioningProfileId: profile.id, - provisioningProfile: content, - teamId: authCtx.team.id, - teamName: authCtx.team.name, - }; spinner.succeed( `Updated provisioning profile (${profile.id}) with distribution certificate${certIdTag}` ); return { - ...result, + provisioningProfileId: profile.id, + provisioningProfile: content, + provisioningProfileType: provisioningProfile.provisioningProfileType, teamId: authCtx.team.id, teamName: authCtx.team.name, }; diff --git a/packages/eas-cli/src/credentials/ios/appstore/provisioningProfileAdhoc.ts b/packages/eas-cli/src/credentials/ios/appstore/provisioningProfileAdhoc.ts index ca67ab29da..ef481490f2 100644 --- a/packages/eas-cli/src/credentials/ios/appstore/provisioningProfileAdhoc.ts +++ b/packages/eas-cli/src/credentials/ios/appstore/provisioningProfileAdhoc.ts @@ -1,6 +1,9 @@ import { Device, Profile, ProfileState, ProfileType, RequestContext } from '@expo/apple-utils'; -import { ProvisioningProfile } from './Credentials.types'; +import { + ProvisioningProfile, + getProvisioningProfileTypeForDistributionMethod, +} from './Credentials.types'; import { getRequestContext } from './authenticate'; import { AuthCtx } from './authenticateTypes'; import { getBundleIdForIdentifierAsync, getProfilesForBundleIdAsync } from './bundleId'; @@ -14,6 +17,7 @@ interface ProfileResults { profileName?: string; provisioningProfileId: string; provisioningProfile: any; + provisioningProfileType: ProfileType; } function uniqueItems(items: T[]): T[] { @@ -177,6 +181,7 @@ async function manageAdHocProfilesAsync( profileName: existingProfile?.attributes?.name, provisioningProfileId: existingProfile?.id, provisioningProfile: existingProfile?.attributes.profileContent, + provisioningProfileType: existingProfile?.attributes.profileType, }; if (didUpdate) { result.didUpdate = true; @@ -208,6 +213,7 @@ async function manageAdHocProfilesAsync( profileName: updatedProfile.attributes.name, provisioningProfileId: updatedProfile.id, provisioningProfile: updatedProfile.attributes.profileContent, + provisioningProfileType: updatedProfile.attributes.profileType, }; } @@ -239,6 +245,7 @@ async function manageAdHocProfilesAsync( profileName: newProfile.attributes.name, provisioningProfileId: newProfile.id, provisioningProfile: newProfile.attributes.profileContent, + provisioningProfileType: newProfile.attributes.profileType, }; } @@ -252,13 +259,18 @@ export async function createOrReuseAdhocProvisioningProfileAsync( const spinner = ora(`Handling Apple ad hoc provisioning profiles`).start(); try { const context = getRequestContext(authCtx); - const { didUpdate, didCreate, profileName, ...adhocProvisioningProfile } = - await manageAdHocProfilesAsync(context, { - udids, - bundleId: bundleIdentifier, - certSerialNumber: distCertSerialNumber, - profileType, - }); + const { + didUpdate, + didCreate, + profileName, + provisioningProfileType, + ...adhocProvisioningProfile + } = await manageAdHocProfilesAsync(context, { + udids, + bundleId: bundleIdentifier, + certSerialNumber: distCertSerialNumber, + profileType, + }); if (didCreate) { spinner.succeed(`Created new profile: ${profileName}`); @@ -270,6 +282,8 @@ export async function createOrReuseAdhocProvisioningProfileAsync( return { ...adhocProvisioningProfile, + provisioningProfileType: + getProvisioningProfileTypeForDistributionMethod(provisioningProfileType), teamId: authCtx.team.id, teamName: authCtx.team.name, };