From 446db61be940dbb8caf1549ba8db665e30b2bfc4 Mon Sep 17 00:00:00 2001 From: Quinlan Jung Date: Thu, 30 Jan 2025 17:46:41 -0800 Subject: [PATCH] [eas-cli] add update group id for fingerprint:compare --- CHANGELOG.md | 1 + .../src/commands/fingerprint/compare.ts | 81 +++++++++++++++---- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7517e8f307..1a7d194f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This is the log of notable changes to EAS CLI and related packages. ### 🧹 Chores - Add update support for fingerprint:compare. ([#2850](https://github.com/expo/eas-cli/pull/2850) by [@quinlanj](https://github.com/quinlanj)) +- Add update group id support for fingerprint:compare. ([#2851](https://github.com/expo/eas-cli/pull/2851) by [@quinlanj](https://github.com/quinlanj)) ## [14.7.1](https://github.com/expo/eas-cli/releases/tag/v14.7.1) - 2025-01-31 diff --git a/packages/eas-cli/src/commands/fingerprint/compare.ts b/packages/eas-cli/src/commands/fingerprint/compare.ts index 55852664bc..704ac2bc07 100644 --- a/packages/eas-cli/src/commands/fingerprint/compare.ts +++ b/packages/eas-cli/src/commands/fingerprint/compare.ts @@ -2,6 +2,7 @@ import { Platform, Workflow } from '@expo/eas-build-job'; import { Flags } from '@oclif/core'; import chalk from 'chalk'; +import { getExpoWebsiteBaseUrl } from '../../api'; import EasCommand from '../../commandUtils/EasCommand'; import { fetchBuildsAsync, formatBuild } from '../../commandUtils/builds'; import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient'; @@ -14,6 +15,7 @@ import { UpdateFragment, } from '../../graphql/generated'; import { FingerprintMutation } from '../../graphql/mutations/FingerprintMutation'; +import { AppQuery } from '../../graphql/queries/AppQuery'; import { BuildQuery } from '../../graphql/queries/BuildQuery'; import { FingerprintQuery } from '../../graphql/queries/FingerprintQuery'; import { UpdateQuery } from '../../graphql/queries/UpdateQuery'; @@ -21,7 +23,10 @@ import Log from '../../log'; import { ora } from '../../ora'; import { RequestedPlatform } from '../../platform'; import { maybeUploadFingerprintAsync } from '../../project/maybeUploadFingerprintAsync'; -import { getDisplayNameForProjectIdAsync } from '../../project/projectUtils'; +import { + getDisplayNameForProjectIdAsync, + getOwnerAccountForProjectIdAsync, +} from '../../project/projectUtils'; import { resolveWorkflowPerPlatformAsync } from '../../project/workflow'; import { selectAsync } from '../../prompts'; import { Fingerprint, FingerprintDiffItem } from '../../utils/fingerprint'; @@ -230,6 +235,27 @@ function capitalizeFirstLetter(string: string): string { return string.charAt(0).toUpperCase() + string.slice(1); } +async function getFingerprintFromUpdateFragmentAsync( + updateWithFingerprint: UpdateFragment +): Promise<{ fingerprint: Fingerprint; platforms?: AppPlatform[]; origin: FingerprintOrigin }> { + if (!updateWithFingerprint.fingerprint) { + throw new Error(`Fingerprint for update ${updateWithFingerprint.id} was not computed.`); + } else if (!updateWithFingerprint.fingerprint.debugInfoUrl) { + throw new Error(`Fingerprint source for update ${updateWithFingerprint.id} was not computed.`); + } + + return { + fingerprint: await getFingerprintFromFingerprintFragmentAsync( + updateWithFingerprint.fingerprint + ), + platforms: [stringToAppPlatform(updateWithFingerprint.platform)], + origin: { + type: FingerprintOriginType.Update, + update: updateWithFingerprint, + }, + }; +} + async function getFirstFingerprintInfoAsync( graphqlClient: ExpoGraphqlClient, projectId: string, @@ -265,25 +291,46 @@ async function getFirstFingerprintInfoAsync( } if (updateIdFromArg) { + // Some people may pass in update group id instead of update id, so add interactive support for that + try { + const maybeUpdateGroupId = updateIdFromArg; + const updateGroup = await UpdateQuery.viewUpdateGroupAsync(graphqlClient, { + groupId: maybeUpdateGroupId, + }); + if (updateGroup.length === 1) { + const update = updateGroup[0]; + return await getFingerprintFromUpdateFragmentAsync(update); + } + if (nonInteractive) { + const [accountName, project] = await Promise.all([ + (await getOwnerAccountForProjectIdAsync(graphqlClient, projectId)).name, + AppQuery.byIdAsync(graphqlClient, projectId), + ]); + const updateUrl = + getExpoWebsiteBaseUrl() + + `/accounts/${accountName}/projects/${project.name}/updates/${updateIdFromArg}`; + throw new Error( + `Please pass in your update ID from ${updateUrl} or use interactive mode to select the update ID.` + ); + } + const update = await selectAsync( + 'Select a platform to compute the fingerprint from', + updateGroup.map(update => ({ + title: update.platform, + value: update, + })) + ); + return await getFingerprintFromUpdateFragmentAsync(update); + } catch (error: any) { + if (!error?.message.includes('Could not find any updates with group ID')) { + throw error; + } + } + const updateWithFingerprint = await UpdateQuery.viewByUpdateAsync(graphqlClient, { updateId: updateIdFromArg, }); - if (!updateWithFingerprint.fingerprint) { - throw new Error(`Fingerprint for update ${updateIdFromArg} was not computed.`); - } else if (!updateWithFingerprint.fingerprint.debugInfoUrl) { - throw new Error(`Fingerprint source for update ${updateIdFromArg} was not computed.`); - } - - return { - fingerprint: await getFingerprintFromFingerprintFragmentAsync( - updateWithFingerprint.fingerprint - ), - platforms: [stringToAppPlatform(updateWithFingerprint.platform)], - origin: { - type: FingerprintOriginType.Update, - update: updateWithFingerprint, - }, - }; + return await getFingerprintFromUpdateFragmentAsync(updateWithFingerprint); } let buildId: string | null = buildIdFromArg ?? null;