Skip to content

Commit

Permalink
[eas-cli] [ENG-10555] Fix device provsioning (#2119)
Browse files Browse the repository at this point in the history
* [eas-cli] Fix provisioning

Updates provisioning profile in EAS before using it if the profile id matches the one from apple but the list of devices does not

See: https://linear.app/expo/issue/ENG-10555/ios-devices-get-stuck-in-failed-to-provision-state-until-the-developer

* [eas-cli] Add test

Added test for a newly added case

See: https://linear.app/expo/issue/ENG-10555/ios-devices-get-stuck-in-failed-to-provision-state-until-the-developer

* update CHANGELOG.md

* [eas-cli] Remove unused import

Remove unused import

See: https://linear.app/expo/issue/ENG-10555/ios-devices-get-stuck-in-failed-to-provision-state-until-the-developer
  • Loading branch information
radoslawkrzemien authored Nov 13, 2023
1 parent cd6a0c4 commit 8e7c668
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🐛 Bug fixes

- Fixed provisioning of new devices into an existing profile. ([#2119](https://github.com/expo/eas-cli/pull/2119) by [@radoslawkrzemien](https://github.com/radoslawkrzemien))

### 🧹 Chores

- Update `@expo/package-manager` to `1.1.2` to change package manager resolution order. ([#2118](https://github.com/expo/eas-cli/pull/2118) by [@szdziedzic](https://github.com/szdziedzic))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import nullthrows from 'nullthrows';

import DeviceCreateAction, { RegistrationMethod } from '../../../devices/actions/create/action';
import {
AppleAppIdentifierFragment,
AppleDevice,
AppleDeviceFragment,
AppleDistributionCertificateFragment,
AppleProvisioningProfileFragment,
Expand All @@ -19,6 +21,7 @@ import differenceBy from '../../../utils/expodash/differenceBy';
import { CredentialsContext } from '../../context';
import { MissingCredentialsNonInteractiveError } from '../../errors';
import { AppLookupParams } from '../api/graphql/types/AppLookupParams';
import { ProvisioningProfile } from '../appstore/Credentials.types';
import { ApplePlatform } from '../appstore/constants';
import { Target } from '../types';
import { validateProvisioningProfileAsync } from '../validators/validateProvisioningProfile';
Expand Down Expand Up @@ -146,25 +149,14 @@ export class SetUpAdhocProvisioningProfile {
);
let appleProvisioningProfile: AppleProvisioningProfileFragment | null = null;
if (currentBuildCredentials?.provisioningProfile) {
if (
currentBuildCredentials.provisioningProfile.developerPortalIdentifier !==
provisioningProfileStoreInfo.provisioningProfileId
) {
await ctx.ios.deleteProvisioningProfilesAsync(ctx.graphqlClient, [
currentBuildCredentials.provisioningProfile.id,
]);
appleProvisioningProfile = await ctx.ios.createProvisioningProfileAsync(
ctx.graphqlClient,
app,
appleAppIdentifier,
{
appleProvisioningProfile: provisioningProfileStoreInfo.provisioningProfile,
developerPortalIdentifier: provisioningProfileStoreInfo.provisioningProfileId,
}
);
} else {
appleProvisioningProfile = currentBuildCredentials.provisioningProfile;
}
appleProvisioningProfile = await this.reuseCurrentProvisioningProfileAsync(
currentBuildCredentials.provisioningProfile,
provisioningProfileStoreInfo,
ctx,
app,
appleAppIdentifier,
chosenDevices
);
} else {
appleProvisioningProfile = await ctx.ios.createProvisioningProfileAsync(
ctx.graphqlClient,
Expand All @@ -183,7 +175,7 @@ export class SetUpAdhocProvisioningProfile {
appleProvisioningProfile.appleDevices,
'identifier'
);
if (diffList && diffList.length > 0) {
if (diffList.length > 0) {
Log.warn(`Failed to provision ${diffList.length} of the selected devices:`);
for (const missingDevice of diffList) {
Log.warn(`- ${formatDeviceLabel(missingDevice)}`);
Expand All @@ -205,6 +197,49 @@ export class SetUpAdhocProvisioningProfile {
);
}

private async reuseCurrentProvisioningProfileAsync(
currentProvisioningProfile: AppleProvisioningProfileFragment,
provisioningProfileStoreInfo: ProvisioningProfile,
ctx: CredentialsContext,
app: AppLookupParams,
appleAppIdentifier: AppleAppIdentifierFragment,
chosenDevices: AppleDevice[]
): Promise<AppleProvisioningProfileFragment> {
if (
currentProvisioningProfile.developerPortalIdentifier !==
provisioningProfileStoreInfo.provisioningProfileId
) {
// If IDs don't match, the profile needs to be deleted and re-created
await ctx.ios.deleteProvisioningProfilesAsync(ctx.graphqlClient, [
currentProvisioningProfile.id,
]);
return await ctx.ios.createProvisioningProfileAsync(
ctx.graphqlClient,
app,
appleAppIdentifier,
{
appleProvisioningProfile: provisioningProfileStoreInfo.provisioningProfile,
developerPortalIdentifier: provisioningProfileStoreInfo.provisioningProfileId,
}
);
} else if (
differenceBy(chosenDevices, currentProvisioningProfile.appleDevices, 'identifier').length > 0
) {
// If IDs match, but the devices lists don't, the profile needs to be updated first
return await ctx.ios.updateProvisioningProfileAsync(
ctx.graphqlClient,
currentProvisioningProfile.id,
{
appleProvisioningProfile: provisioningProfileStoreInfo.provisioningProfile,
developerPortalIdentifier: provisioningProfileStoreInfo.provisioningProfileId,
}
);
} else {
// Otherwise the current profile can be reused
return currentProvisioningProfile;
}
}

private async areBuildCredentialsSetupAsync(ctx: CredentialsContext): Promise<boolean> {
const { app, target } = this.options;
const buildCredentials = await getBuildCredentialsAsync(ctx, app, IosDistributionType.AdHoc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,63 @@ describe('runWithDistributionCertificateAsync', () => {
});
describe('compare chosen and provisioned devices', () => {
describe('not all devices provisioned', () => {
it('displays warning to the user and lists the missing devices', async () => {
const { ctx, distCert } = setUpTest();
jest.mocked(getBuildCredentialsAsync).mockResolvedValue({
provisioningProfile: {
describe('still not provisioned after an update', () => {
it('displays warning to the user and lists the missing devices', async () => {
const { ctx, distCert } = setUpTest();
jest.mocked(getBuildCredentialsAsync).mockResolvedValue({
provisioningProfile: {
appleTeam: {},
appleDevices: [{ identifier: 'id1' }],
developerPortalIdentifier: 'provisioningProfileId',
},
} as IosAppBuildCredentialsFragment);
ctx.ios.updateProvisioningProfileAsync = jest.fn().mockResolvedValue({
appleTeam: {},
appleDevices: [{ identifier: 'id1' }],
developerPortalIdentifier: 'provisioningProfileId',
},
} as IosAppBuildCredentialsFragment);
const LogWarnSpy = jest.spyOn(Log, 'warn');
const LogLogSpy = jest.spyOn(Log, 'log');
const result = await setUpAdhocProvisioningProfile.runWithDistributionCertificateAsync(
ctx,
distCert
);
expect(result).toEqual({} as IosAppBuildCredentialsFragment);
expect(LogWarnSpy).toHaveBeenCalledTimes(3);
expect(LogWarnSpy).toHaveBeenCalledWith('Failed to provision 2 of the selected devices:');
expect(LogWarnSpy).toHaveBeenCalledWith('- id2 (iPhone) (Device 2)');
expect(LogWarnSpy).toHaveBeenCalledWith('- id3 (Mac) (Device 3)');
expect(LogLogSpy).toHaveBeenCalledTimes(1);
expect(LogLogSpy).toHaveBeenCalledWith(
'Most commonly devices fail to to be provisioned while they are still being processed by Apple, which can take up to 24-72 hours. Check your Apple Developer Portal page at https://developer.apple.com/account/resources/devices/list, the devices in "Processing" status cannot be provisioned yet'
);
});
const LogWarnSpy = jest.spyOn(Log, 'warn');
const LogLogSpy = jest.spyOn(Log, 'log');
const result = await setUpAdhocProvisioningProfile.runWithDistributionCertificateAsync(
ctx,
distCert
);
expect(result).toEqual({} as IosAppBuildCredentialsFragment);
expect(LogWarnSpy).toHaveBeenCalledTimes(3);
expect(LogWarnSpy).toHaveBeenCalledWith('Failed to provision 2 of the selected devices:');
expect(LogWarnSpy).toHaveBeenCalledWith('- id2 (iPhone) (Device 2)');
expect(LogWarnSpy).toHaveBeenCalledWith('- id3 (Mac) (Device 3)');
expect(LogLogSpy).toHaveBeenCalledTimes(1);
expect(LogLogSpy).toHaveBeenCalledWith(
'Most commonly devices fail to to be provisioned while they are still being processed by Apple, which can take up to 24-72 hours. Check your Apple Developer Portal page at https://developer.apple.com/account/resources/devices/list, the devices in "Processing" status cannot be provisioned yet'
);
});
});
describe('all devices provisioned after an update', () => {
it('does not display warning', async () => {
const { ctx, distCert } = setUpTest();
jest.mocked(getBuildCredentialsAsync).mockResolvedValue({
provisioningProfile: {
appleTeam: {},
appleDevices: [{ identifier: 'id1' }],
developerPortalIdentifier: 'provisioningProfileId',
},
} as IosAppBuildCredentialsFragment);
ctx.ios.updateProvisioningProfileAsync = jest.fn().mockResolvedValue({
appleTeam: {},
appleDevices: [{ identifier: 'id1' }, { identifier: 'id2' }, { identifier: 'id3' }],
developerPortalIdentifier: 'provisioningProfileId',
});
const LogWarnSpy = jest.spyOn(Log, 'warn');
const LogLogSpy = jest.spyOn(Log, 'log');
const result = await setUpAdhocProvisioningProfile.runWithDistributionCertificateAsync(
ctx,
distCert
);
expect(result).toEqual({} as IosAppBuildCredentialsFragment);
expect(LogWarnSpy).not.toHaveBeenCalled();
expect(LogLogSpy).not.toHaveBeenCalled();
});
});
});
describe('all devices provisioned', () => {
Expand Down

0 comments on commit 8e7c668

Please sign in to comment.