Skip to content

Commit 3f565b4

Browse files
fix: iOS resigning script (#1655)
1 parent 719c3f9 commit 3f565b4

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

src/CapabilityManager.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IDevice } from './interfaces/IDevice';
55
import { prisma } from './prisma';
66
import { DevicePlugin } from './plugin';
77
import log from './logger';
8+
import { updatedAllocatedDevice } from './data-service/device-service';
89

910
export enum DEVICE_FARM_CAPABILITIES {
1011
BUILD_NAME = 'build',
@@ -79,18 +80,7 @@ export async function androidCapabilities(
7980

8081
export async function iOSCapabilities(
8182
caps: ISessionCapability,
82-
freeDevice: {
83-
webDriverAgentUrl?: any;
84-
udid: any;
85-
name: string;
86-
realDevice: boolean;
87-
sdk: string;
88-
mjpegServerPort?: number;
89-
wdaLocalPort?: number;
90-
derivedDataPath?: string;
91-
wdaBundleId?: string;
92-
webDriverAgentHost?: string;
93-
},
83+
freeDevice: IDevice,
9484
options: { liveVideo: boolean },
9585
) {
9686
if (!process.env.GO_IOS) {
@@ -134,6 +124,11 @@ export async function iOSCapabilities(
134124
deleteMatch.push('appium:mjpegServerPort');
135125
}
136126
deleteMatch.forEach((value) => deleteAlwaysMatch(caps, value));
127+
await updatedAllocatedDevice(freeDevice, {
128+
wdaLocalPort: freeDevice.wdaLocalPort,
129+
mjpegServerPort: freeDevice.mjpegServerPort,
130+
webDriverAgentUrl: freeDevice.webDriverAgentUrl,
131+
});
137132
}
138133

139134
export function getDeviceFarmCapabilities(caps: ISessionCapability) {

src/device-utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export async function allocateDeviceForSession(
144144
delete filterCopy.userBlocked;
145145

146146
const possibleDevice = await getDevice(filterCopy);
147+
if (possibleDevice && possibleDevice.busy == true && !possibleDevice?.session_id) {
148+
await unblockDevice(possibleDevice.udid, possibleDevice.host);
149+
}
147150

148151
let failureReason = 'No device matching request.';
149152
if (possibleDevice?.busy || possibleDevice?.userBlocked) {

src/modules

src/scripts/ios-sign.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { select } from '@inquirer/prompts';
1818

1919
const execAsync = util.promisify(exec);
2020
const WDA_BUILD_PATH = '/appium_wda_ios/Build/Products/Debug-iphoneos';
21+
let bundleIdName: { uuid: string; name: string }[] | null = null;
22+
let freeBundleID: { uuid: string; name: string } | null = null;
2123

2224
async function getXcodeMajorVersion(): Promise<number> {
2325
const { stdout } = await execAsync('xcodebuild -version');
@@ -97,6 +99,23 @@ const getMobileProvisioningFile = async (mobileProvisioningFile?: string) => {
9799
})),
98100
});
99101

102+
const isFreeAccount = await select({
103+
message: 'Is this a free or enterprise account provisioning profile?',
104+
choices: [
105+
{ value: true, name: 'Free Account' },
106+
{ value: false, name: 'Enterprise Account' },
107+
],
108+
});
109+
if (isFreeAccount) {
110+
bundleIdName = provisioningFiles.map((file) => {
111+
return { uuid: file.UUID, name: `${file.Name.split(':')[1] || file.Name}` };
112+
});
113+
}
114+
freeBundleID =
115+
bundleIdName?.find((d: any) => {
116+
return d.uuid === prompt;
117+
}) || null;
118+
100119
return path.join(await getProvisioningProfilePath(), `${prompt}.mobileprovision`);
101120
}
102121
};
@@ -220,10 +239,21 @@ async function zipPayloadDirectory(
220239
task: async (context, task) => {
221240
const wdaBuildPath = path.join(context.wdaProjectPath, WDA_BUILD_PATH);
222241
const ipaPath = `${wdaBuildPath}/wda-resign.ipa`;
223-
const as = new Applesign({
224-
mobileprovision: mobileProvisioningFile,
225-
outfile: ipaPath,
226-
});
242+
243+
let appleOptions: any;
244+
if (freeBundleID) {
245+
appleOptions = {
246+
mobileprovision: mobileProvisioningFile,
247+
outfile: ipaPath,
248+
bundleId: freeBundleID.name.replace(/^\s+|\s+$/g, ''),
249+
};
250+
} else {
251+
appleOptions = {
252+
mobileprovision: mobileProvisioningFile,
253+
outfile: ipaPath,
254+
};
255+
}
256+
const as = new Applesign(appleOptions);
227257
await as.signIPA(path.join(wdaBuildPath, 'wda-resign.zip'));
228258
task.title = `Successfully signed WebDriverAgent file ${ipaPath}`;
229259
},

0 commit comments

Comments
 (0)