Skip to content

Commit

Permalink
[eas-cli[eas-update] Change behavior of roll-back-to-embedded to not …
Browse files Browse the repository at this point in the history
…use current project state
  • Loading branch information
wschurman committed Nov 22, 2024
1 parent 48ebd9b commit c6c0de0
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 146 deletions.
62 changes: 27 additions & 35 deletions packages/eas-cli/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions packages/eas-cli/src/branch/queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from 'chalk';
import { print } from 'graphql';
import gql from 'graphql-tag';

import { BranchNotFoundError } from './utils';
Expand All @@ -8,10 +9,11 @@ import { withErrorHandlingAsync } from '../graphql/client';
import {
CreateUpdateBranchForAppMutation,
CreateUpdateBranchForAppMutationVariables,
UpdateBranch,
UpdateBranchBasicInfoFragment,
UpdateBranchFragment,
} from '../graphql/generated';
import { BranchQuery } from '../graphql/queries/BranchQuery';
import { UpdateBranchBasicInfoFragmentNode } from '../graphql/types/UpdateBranchBasicInfo';
import Log from '../log';
import { formatBranch, getBranchDescription } from '../update/utils';
import { printJsonOnlyOutput } from '../utils/json';
Expand Down Expand Up @@ -126,7 +128,7 @@ function renderPageOfBranches(
export async function createUpdateBranchOnAppAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, name }: CreateUpdateBranchForAppMutationVariables
): Promise<Pick<UpdateBranch, 'id' | 'name'>> {
): Promise<UpdateBranchBasicInfoFragment> {
const result = await withErrorHandlingAsync(
graphqlClient
.mutation<CreateUpdateBranchForAppMutation, CreateUpdateBranchForAppMutationVariables>(
Expand All @@ -135,15 +137,17 @@ export async function createUpdateBranchOnAppAsync(
updateBranch {
createUpdateBranchForApp(appId: $appId, name: $name) {
id
name
...UpdateBranchBasicInfoFragment
}
}
}
${print(UpdateBranchBasicInfoFragmentNode)}
`,
{
appId,
name,
}
},
{ additionalTypenames: ['UpdateBranch'] }
)
.toPromise()
);
Expand All @@ -163,22 +167,21 @@ export async function ensureBranchExistsAsync(
appId: string;
branchName: string;
}
): Promise<{ branchId: string; createdBranch: boolean }> {
): Promise<{ branch: UpdateBranchBasicInfoFragment; createdBranch: boolean }> {
try {
const updateBranch = await BranchQuery.getBranchByNameAsync(graphqlClient, {
appId,
name: branchName,
});

const { id } = updateBranch;
return { branchId: id, createdBranch: false };
return { branch: updateBranch, createdBranch: false };
} catch (error) {
if (error instanceof BranchNotFoundError) {
const newUpdateBranch = await createUpdateBranchOnAppAsync(graphqlClient, {
appId,
name: branchName,
});
return { branchId: newUpdateBranch.id, createdBranch: true };
return { branch: newUpdateBranch, createdBranch: true };
} else {
throw error;
}
Expand Down
15 changes: 12 additions & 3 deletions packages/eas-cli/src/commands/update/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ describe(UpdatePublish.name, () => {
const { platforms, runtimeVersion } = mockTestExport();

jest.mocked(ensureBranchExistsAsync).mockResolvedValue({
branchId: 'branch123',
branch: {
id: 'branch123',
name: 'wat',
},
createdBranch: false,
});

Expand All @@ -111,7 +114,10 @@ describe(UpdatePublish.name, () => {
.mocked(getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync)
.mockResolvedValue({ branchId: 'branch123', branchName: 'branchFromChannel' });
jest.mocked(ensureBranchExistsAsync).mockResolvedValue({
branchId: 'branch123',
branch: {
id: 'branch123',
name: 'wat',
},
createdBranch: false,
});

Expand Down Expand Up @@ -146,7 +152,10 @@ describe(UpdatePublish.name, () => {

// Mock an existing branch, so we don't create a new one
jest.mocked(ensureBranchExistsAsync).mockResolvedValue({
branchId: 'branch123',
branch: {
id: 'branch123',
name: 'wat',
},
createdBranch: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ describe(UpdateRollBackToEmbedded.name, () => {
jest.mocked(Updates.getRuntimeVersionAsync).mockResolvedValue(runtimeVersion);

jest.mocked(ensureBranchExistsAsync).mockResolvedValue({
branchId: 'branch123',
branch: {
id: 'branch123',
name: 'wat',
},
createdBranch: false,
});

Expand All @@ -116,7 +119,10 @@ describe(UpdateRollBackToEmbedded.name, () => {
.mocked(getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync)
.mockResolvedValue({ branchId: updateStub.branch.id, branchName: 'branchFromChannel' });
jest.mocked(ensureBranchExistsAsync).mockResolvedValue({
branchId: 'branch123',
branch: {
id: 'branch123',
name: 'wat',
},
createdBranch: false,
});

Expand Down Expand Up @@ -153,7 +159,10 @@ describe(UpdateRollBackToEmbedded.name, () => {

// Mock an existing branch, so we don't create a new one
jest.mocked(ensureBranchExistsAsync).mockResolvedValue({
branchId: 'branch123',
branch: {
id: 'branch123',
name: 'wat',
},
createdBranch: false,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export default class UpdatePublish extends EasCommand {
runtimeVersionInfoObjects
);

const { branchId } = await ensureBranchExistsAsync(graphqlClient, {
const { branch } = await ensureBranchExistsAsync(graphqlClient, {
appId: projectId,
branchName,
});
Expand Down Expand Up @@ -482,7 +482,7 @@ export default class UpdatePublish extends EasCommand {
);

return {
branchId,
branchId: branch.id,
updateInfoGroup: localUpdateInfoGroup,
rolloutInfoGroup: localRolloutInfoGroup,
runtimeFingerprintSource: fingerprintSource
Expand Down
Loading

0 comments on commit c6c0de0

Please sign in to comment.