Skip to content

Commit

Permalink
[eas-cli] skip creation of testflight group when there are already ex…
Browse files Browse the repository at this point in the history
…isitng testflight groups + allow to opt out of the behavior by setting env var
  • Loading branch information
szdziedzic committed Feb 3, 2025
1 parent 77423d1 commit e1f9794
Showing 1 changed file with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,40 @@ const AUTO_GROUP_NAME = 'Team (Expo)';
* This allows users to instantly access their builds from TestFlight after it finishes processing.
*/
export async function ensureTestFlightGroupExistsAsync(app: App): Promise<void> {
const group = await ensureInternalGroupAsync(app);
const users = await User.getAsync(app.context);
const admins = users.filter(user => user.attributes.roles?.includes(UserRole.ADMIN));

await addAllUsersToInternalGroupAsync(group, admins);
}
if (process.env.EXPO_SKIP_TESTFLIGHT_SETUP) {
Log.debug('EXPO_SKIP_TESTFLIGHT_SETUP is set, skipping TestFlight setup');
return;
}

async function ensureInternalGroupAsync(app: App): Promise<BetaGroup> {
const groups = await app.getBetaGroupsAsync({
query: {
includes: ['betaTesters'],
},
});

if (groups.length > 0) {
Log.debug(`Found ${groups.length} TestFlight groups`);
Log.debug('Skipping creating a new TestFlight group');
return;
}

const group = await ensureInternalGroupAsync({
app,
groups,
});
const users = await User.getAsync(app.context);
const admins = users.filter(user => user.attributes.roles?.includes(UserRole.ADMIN));

await addAllUsersToInternalGroupAsync(group, admins);
}

async function ensureInternalGroupAsync({
groups,
app,
}: {
groups: BetaGroup[];
app: App;
}): Promise<BetaGroup> {
let betaGroup = groups.find(group => group.attributes.name === AUTO_GROUP_NAME);
if (!betaGroup) {
const spinner = ora().start('Creating TestFlight group...');
Expand Down Expand Up @@ -76,7 +96,14 @@ async function ensureInternalGroupAsync(app: App): Promise<BetaGroup> {
})
) {
await BetaGroup.deleteAsync(app.context, { id: betaGroup.id });
return await ensureInternalGroupAsync(app);
return await ensureInternalGroupAsync({
app,
groups: await app.getBetaGroupsAsync({
query: {
includes: ['betaTesters'],
},
}),
});
}
}

Expand Down

0 comments on commit e1f9794

Please sign in to comment.