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

Support Mac provisioning profiles #321

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 @@ -19,6 +19,7 @@ const iosCredentials: Ios.BuildCredentials = {
dataBase64: '',
password: '',
},
provisioningProfileType: Ios.ProvisioningProfileType.MOBILEPROVISION,
},
};

Expand Down Expand Up @@ -60,6 +61,7 @@ describe(IosCredentialsManager, () => {
[targetName]: {
distributionCertificate,
provisioningProfileBase64: provisioningProfile.dataBase64,
provisioningProfileType: Ios.ProvisioningProfileType.MOBILEPROVISION,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ describe('ProvisioningProfile class', () => {
});

it("shouldn't throw any error if the provisioning profile and distribution certificate match", async () => {
const pp = new ProvisioningProfile(
const pp = new ProvisioningProfile({
ctx,
Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychain.data.path,
'testapp',
'Abc 123'
);
profile: Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychainPath: keychain.data.path,
target: 'testapp',
certificateCommonName: 'Abc 123',
});
try {
await pp.init();
expect(() => {
Expand All @@ -52,13 +52,13 @@ describe('ProvisioningProfile class', () => {
});

it("should throw an error if the provisioning profile and distribution certificate don't match", async () => {
const pp = new ProvisioningProfile(
const pp = new ProvisioningProfile({
ctx,
Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychain.data.path,
'testapp',
'Abc 123'
);
profile: Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychainPath: keychain.data.path,
target: 'testapp',
certificateCommonName: 'Abc 123',
});

try {
await pp.init();
Expand Down
13 changes: 7 additions & 6 deletions packages/build-tools/src/ios/credentials/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ export default class IosCredentialsManager<TJob extends Ios.Job> {
);

this.ctx.logger.info('Initializing provisioning profile');
const provisioningProfile = new ProvisioningProfile(
this.ctx,
Buffer.from(targetCredentials.provisioningProfileBase64, 'base64'),
this.keychain.data.path,
const provisioningProfile = new ProvisioningProfile({
ctx: this.ctx,
profile: Buffer.from(targetCredentials.provisioningProfileBase64, 'base64'),
keychainPath: this.keychain.data.path,
target,
certificateCommonName
);
certificateCommonName,
profileType: targetCredentials.provisioningProfileType,
});
await provisioningProfile.init();

this.ctx.logger.info(
Expand Down
53 changes: 44 additions & 9 deletions packages/build-tools/src/ios/credentials/provisioningProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export enum DistributionType {
ENTERPRISE = 'enterprise',
}

/** Type enum may not correspond with extension. */
function getExtensionForType(type: Ios.ProvisioningProfileType): string {
switch (type) {
case Ios.ProvisioningProfileType.MOBILEPROVISION:
return type;
case Ios.ProvisioningProfileType.PROVISIONPROFILE:
return type;
}
}

const PROVISIONING_PROFILES_DIRECTORY = path.join(
os.homedir(),
'Library/MobileDevice/Provisioning Profiles'
Expand All @@ -42,17 +52,40 @@ export default class ProvisioningProfile<TJob extends Ios.Job> {
}
}

private readonly ctx: BuildContext<TJob>;
private readonly profile: Buffer;
private readonly keychainPath: string;
private readonly target: string;
private readonly certificateCommonName: string;
private readonly profilePath: string;
private readonly profileType: Ios.ProvisioningProfileType;
private profileData?: ProvisioningProfileData;

constructor(
private readonly ctx: BuildContext<TJob>,
private readonly profile: Buffer,
private readonly keychainPath: string,
private readonly target: string,
private readonly certificateCommonName: string
) {
this.profilePath = path.join(PROVISIONING_PROFILES_DIRECTORY, `${uuid()}.mobileprovision`);
constructor({
ctx,
profile,
keychainPath,
target,
certificateCommonName,
profileType,
}: {
ctx: BuildContext<TJob>;
profile: Buffer;
keychainPath: string;
target: string;
certificateCommonName: string;
profileType: Ios.ProvisioningProfileType;
}) {
this.ctx = ctx;
this.profile = profile;
this.keychainPath = keychainPath;
this.target = target;
this.certificateCommonName = certificateCommonName;
this.profileType = profileType;
this.profilePath = path.join(
PROVISIONING_PROFILES_DIRECTORY,
`${uuid()}.${getExtensionForType(profileType)}`
);
}

public async init(): Promise<void> {
Expand Down Expand Up @@ -111,7 +144,9 @@ Profile's certificate fingerprint = ${devCertFingerprint}, distribution certific
}

const applicationIdentifier = (plistData.Entitlements as plist.PlistObject)[
'application-identifier'
this.profileType === Ios.ProvisioningProfileType.PROVISIONPROFILE
? 'com.apple.application-identifier'
: 'application-identifier'
] as string;
const bundleIdentifier = applicationIdentifier.replace(/^.+?\./, '');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BuildFunction, BuildStepInput, BuildStepInputValueTypeName } from '@exp
import { Ios } from '@expo/eas-build-job';

import IosCredentialsManager from '../utils/ios/credentials/manager';
import { IosBuildCredentialsSchema } from '../utils/ios/credentials/credentials';
import { configureCredentialsAsync } from '../utils/ios/configure';
import { resolveBuildConfiguration } from '../utils/ios/resolve';

Expand All @@ -28,7 +27,7 @@ export function configureIosCredentialsFunction(): BuildFunction {
],
fn: async (stepCtx, { inputs }) => {
const rawCredentialsInput = inputs.credentials.value as Record<string, any>;
const { value, error } = IosBuildCredentialsSchema.validate(rawCredentialsInput, {
const { value, error } = Ios.BuildCredentialsSchema.validate(rawCredentialsInput, {
stripUnknown: true,
convert: true,
abortEarly: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BuildFunction, BuildStepInput, BuildStepInputValueTypeName } from '@exp
import { Ios } from '@expo/eas-build-job';
import semver from 'semver';

import { IosBuildCredentialsSchema } from '../utils/ios/credentials/credentials';
import IosCredentialsManager from '../utils/ios/credentials/manager';
import { updateVersionsAsync } from '../utils/ios/configure';
import { resolveBuildConfiguration } from '../utils/ios/resolve';
Expand Down Expand Up @@ -39,7 +38,7 @@ export function configureIosVersionFunction(): BuildFunction {
],
fn: async (stepCtx, { inputs }) => {
const rawCredentialsInput = inputs.credentials.value as Record<string, any>;
const { value, error } = IosBuildCredentialsSchema.validate(rawCredentialsInput, {
const { value, error } = Ios.BuildCredentialsSchema.validate(rawCredentialsInput, {
stripUnknown: true,
convert: true,
abortEarly: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { bunyan } from '@expo/logger';
import templateFile from '@expo/template-file';
import { v4 as uuid } from 'uuid';

import { IosBuildCredentialsSchema } from '../utils/ios/credentials/credentials';
import IosCredentialsManager, { Credentials } from '../utils/ios/credentials/manager';
import { resolveBuildConfiguration, resolveScheme } from '../utils/ios/resolve';
import { isTVOS } from '../utils/ios/tvos';
Expand Down Expand Up @@ -102,7 +101,7 @@ export function generateGymfileFromTemplateFunction(): BuildFunction {
let credentials: Credentials | undefined = undefined;
const rawCredentialsInput = inputs.credentials.value as Record<string, any> | undefined;
if (rawCredentialsInput) {
const { value, error } = IosBuildCredentialsSchema.validate(rawCredentialsInput, {
const { value, error } = Ios.BuildCredentialsSchema.validate(rawCredentialsInput, {
stripUnknown: true,
convert: true,
abortEarly: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Ios } from '@expo/eas-build-job';
import {
BuildFunction,
BuildStepInput,
Expand All @@ -6,7 +7,6 @@ import {
} from '@expo/steps';

import IosCredentialsManager from '../utils/ios/credentials/manager';
import { IosBuildCredentialsSchema } from '../utils/ios/credentials/credentials';

export function resolveAppleTeamIdFromCredentialsFunction(): BuildFunction {
return new BuildFunction({
Expand All @@ -29,7 +29,7 @@ export function resolveAppleTeamIdFromCredentialsFunction(): BuildFunction {
],
fn: async (stepCtx, { inputs, outputs }) => {
const rawCredentialsInput = inputs.credentials.value as Record<string, any>;
const { value, error } = IosBuildCredentialsSchema.validate(rawCredentialsInput, {
const { value, error } = Ios.BuildCredentialsSchema.validate(rawCredentialsInput, {
stripUnknown: true,
convert: true,
abortEarly: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const iosCredentials: Ios.BuildCredentials = {
dataBase64: '',
password: '',
},
provisioningProfileType: Ios.ProvisioningProfileType.MOBILEPROVISION,
},
};

Expand Down Expand Up @@ -59,6 +60,7 @@ describe(IosCredentialsManager, () => {
[targetName]: {
distributionCertificate,
provisioningProfileBase64: provisioningProfile.dataBase64,
provisioningProfileType: Ios.ProvisioningProfileType.MOBILEPROVISION,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Ios } from '@expo/eas-build-job';
import { createLogger } from '@expo/logger';

import Keychain from '../keychain';
Expand All @@ -23,12 +24,13 @@ describe('ProvisioningProfile class', () => {
});

it("shouldn't throw any error if the provisioning profile and distribution certificate match", async () => {
const pp = new ProvisioningProfile(
Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychain.data.path,
'testapp',
'Abc 123'
);
const pp = new ProvisioningProfile({
profile: Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychainPath: keychain.data.path,
target: 'testapp',
certificateCommonName: 'Abc 123',
profileType: Ios.ProvisioningProfileType.MOBILEPROVISION,
});
try {
await pp.init(mockLogger);
expect(() => {
Expand All @@ -40,12 +42,13 @@ describe('ProvisioningProfile class', () => {
});

it("should throw an error if the provisioning profile and distribution certificate don't match", async () => {
const pp = new ProvisioningProfile(
Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychain.data.path,
'testapp',
'Abc 123'
);
const pp = new ProvisioningProfile({
profile: Buffer.from(provisioningProfile.dataBase64, 'base64'),
keychainPath: keychain.data.path,
target: 'testapp',
certificateCommonName: 'Abc 123',
profileType: Ios.ProvisioningProfileType.MOBILEPROVISION,
});

try {
await pp.init(mockLogger);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ export default class IosCredentialsManager {
);

logger.info('Initializing provisioning profile');
const provisioningProfile = new ProvisioningProfile(
Buffer.from(targetCredentials.provisioningProfileBase64, 'base64'),
this.keychain.data.path,
const provisioningProfile = new ProvisioningProfile({
profile: Buffer.from(targetCredentials.provisioningProfileBase64, 'base64'),
certificateCommonName,
keychainPath: this.keychain.data.path,
target,
certificateCommonName
);
profileType: targetCredentials.provisioningProfileType,
});
await provisioningProfile.init(logger);

logger.info('Validating whether distribution certificate has been imported successfully');
Expand Down
Loading
Loading