Skip to content

Commit

Permalink
fix: provisioning profile file path after Xcode 16 (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoodahun authored Dec 13, 2024
1 parent 72af42d commit 3114a4d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
7 changes: 6 additions & 1 deletion documentation/docs/ios-signing.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ If you want to provide the custom path of WebDriverAgent project then set _WDA_P
appium plugin run device-farm prepare-wda --wda-project-path=<path-to-WDA-project> --mobile-provisioning-file=<path-to-provision-profile>
```

You should have all the provision certificates installed on your machine to build the WebDriverAgent from source in path.
You should have all the provision certificates installed on your machine before building the WebDriverAgent from source. For Xcode versions 15 or below, ensure they are located in:
```
~/Library/MobileDevice/Provisioning\ Profiles
```

For Xcode versions 16 and above, place them in:
```
~/Library/Developer/Xcode/UserData/Provisioning\ Profiles
```
49 changes: 42 additions & 7 deletions src/scripts/ios-sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,31 @@ import { select } from '@inquirer/prompts';

const execAsync = util.promisify(exec);
const WDA_BUILD_PATH = '/appium_wda_ios/Build/Products/Debug-iphoneos';
const PROVISION_FILE_PATH_PREFIX = path.join(
os.homedir(),
'Library/MobileDevice/Provisioning Profiles',
);

async function getXcodeMajorVersion(): Promise<number> {
const { stdout } = await execAsync('xcodebuild -version');
const match = stdout.match(/Xcode (\d+)\./);
if (!match) {
throw new Error('Unable to determine Xcode version');
}
return parseInt(match[1], 10);
}

async function getProvisioningProfilePath(): Promise<string> {
const xcodeVersion = await getXcodeMajorVersion();

if (xcodeVersion <= 15) {
return path.join(
os.homedir(),
'Library/MobileDevice/Provisioning Profiles'
);
} else {
return path.join(
os.homedir(),
'Library/Developer/Xcode/UserData/Provisioning Profiles'
);
}
}

type Context = ListrContext & CliOptions;

Expand Down Expand Up @@ -55,7 +76,21 @@ const getMobileProvisioningFile = async (mobileProvisioningFile?: string) => {
}
return mobileProvisioningFile;
} else {
const provisioningFiles = provision.read();
const provisionFileDir = await getProvisioningProfilePath();

if (!fs.existsSync(provisionFileDir)) {
throw new Error(`Provisioning directory does not exist: ${provisionFileDir}`);
}

const files = fs.readdirSync(provisionFileDir, { encoding: 'utf8' })
.filter(file => file.endsWith('.mobileprovision'));

const provisioningFiles = files.map(file => {
const fullPath = path.join(provisionFileDir, file);
const mp = provision.readFromFile(fullPath);
return { ...mp, _filePath: fullPath };
});

if (!provisioningFiles || !provisioningFiles.length) {
throw new Error('No mobileprovision file found on the machine');
}
Expand All @@ -66,8 +101,8 @@ const getMobileProvisioningFile = async (mobileProvisioningFile?: string) => {
name: `${file.Name.split(':')[1] || file.Name} (Team: ${file.TeamName}) (${file.UUID})`,
})),
});

return path.join(PROVISION_FILE_PATH_PREFIX, `${prompt}.mobileprovision`);
return path.join(await getProvisioningProfilePath(), `${prompt}.mobileprovision`);
}
};

Expand Down

0 comments on commit 3114a4d

Please sign in to comment.