Skip to content

Commit

Permalink
[eas-cli] [ENG-11843] Change default appVersionSource to REMOTE (#…
Browse files Browse the repository at this point in the history
…2411)

* [eas-cli] Update tests

Updated the tests to reflect the change of the default `appVersionSource` value

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update remote version handling

Updated the logic for REMOTE version source to treat undefined `appVersionSource` as REMOTE instead of LOCAL

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Refactor tests

Extracted the helper functions overriding the `appVersionSource` in eas.json to utils.ts

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update version source when running builds

Applied the same change to the build command as was applied to version commands

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* update CHANGELOG.md

* [eas-cli] Adjust changelog

After it was correctly pointed out by @sjchmiela, the changelog has been amended to list the current changes not as chores and as breaking change instead

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Prompt the user

The user is now prompted when they don't specify `appVersionSource` to either set it automatically to LOCAL/REMOTE or abort the command and configure it manually. This removes the default behaviour alltogether and avoids a situation where some users have been relying on the old default and would now be surprised

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update message

Updated the message displayed to the user when prompting for selection after the review

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update message

Updated the message displayed to the user when prompting for selection after the review

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update default eas.json

Updated the default eas.json created with `configure` command

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update default eas.json

Updated the default eas.json created with `onboarding` command

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Check for non-interactive

Made the function prompting the user for selection on what to do with appVersionSource to respect the non-interactive flag, and abort the operation in non-interactive mode since the user can't make a selection

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Remove code duplication

Moved the setting of appVersionSource in easJsonCliConfig into the function prompting the user, which allows for implementing that in one place instead of 3

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Fix circular dependency

There was a circular dependency introduced with passing of the flags into a function. The definition of the build flags has been moved into the types.ts file to avoid itĻ

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* Update packages/eas-cli/src/project/remoteVersionSource.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* [eas-cli] Adjust wording

Changed the wording of the message displayed to the user to more accurately describe how app versions are handled

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update default eas.json

Added autoIncrement: true when creating the default eas.json with remote appVersionSource

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Don't implicitly assume remote appVersionSource

The user is required to set appVersionSource in interactive mode so it should always be set. In non-interactive mode it can be not set, and in that case the default remains the same as it was, which is local

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Don't implicitly assume remote appVersionSource

The user is required to set appVersionSource in interactive mode so it should always be set. In non-interactive mode it can be not set, and in that case the default remains the same as it was, which is local

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Set autoIncrement

When creating the default eas.json set autoIncrement: true

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Set appVersionSource to local for non-interactive

To not break CIs that the users built for their apps in non-interactive mode we need to select the appVersionSource automatically in those cases. And since they may be counting on it being local since that was the previous default we need to keep setting it to local even if the new default is remote

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Handle autoIncrement != true

Do not ensure `appVersionSource` is set if the user has `autoIncrement: 'veresion'`. Display a message if the user doesn't have `autoIncrement: true` but don't prompt them to set `appVersionSource`

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Add missing quote

Added missing quote sign in the log message

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Add comma

Added comma to the log message

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Tweak message

Tweaked the log message according to the review comment

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* Update packages/eas-cli/src/build/runBuildAndSubmit.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* [eas-cli] Don't change eas.json in non-interactive mode

When defaulting the value of `appVersionSource` for commands executed in non-interactive mode the eas.json is not modified and the value is assumed only at runtime. This removes the need to commit changes, which in turn eliminates the risk of mistakenly committing working changes the user might have when executing the command

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update message

Updated the message to correctly state how the version are handled with local appversionsource

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update message

Updated the message to correctly state how the version are handled with remote appversionsource

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update message

Updated the message based on review suggestions

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* Update packages/eas-cli/src/project/remoteVersionSource.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* [eas-cli] Reformat

Improved formatting

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* Update packages/eas-cli/src/project/remoteVersionSource.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* Update packages/eas-cli/src/project/remoteVersionSource.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* Update packages/eas-cli/src/build/runBuildAndSubmit.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* [eas-cli] Reformat

Improved formatting

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* Update packages/eas-cli/src/project/remoteVersionSource.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* [eas-cli] Reformat

Improved formatting

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* Update packages/eas-cli/src/project/remoteVersionSource.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* [eas-cli] Post-merge fix

Fixed issues after merging in the main branch

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* [eas-cli] Update version mentioned

Updated the version number that includes the current changes after a new major version had been released in the meantime

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

* Update packages/eas-cli/src/project/remoteVersionSource.ts

Co-authored-by: Szymon Dziedzic <[email protected]>

* [eas-cli] Lint

Fixed linting error

See: https://linear.app/expo/issue/ENG-11843/change-default-appversionsource-to-remote

---------

Co-authored-by: Szymon Dziedzic <[email protected]>
  • Loading branch information
radoslawkrzemien and szdziedzic authored Sep 3, 2024
1 parent fbc3924 commit 8c31825
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🛠 Breaking changes

- Prompt the users to set `appVersionSource`, while mentioning that `remote` is the default. ([#2411](https://github.com/expo/eas-cli/pull/2411) by [@radoslawkrzemien](https://github.com/radoslawkrzemien))

### 🎉 New features

- Add support for syncing Journaling Suggestions, Managed App Installation UI, and 5G Network Slicing capabilities. ([#2525](https://github.com/expo/eas-cli/pull/2525) by [@szdziedzic](https://github.com/szdziedzic))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BuildVersionGetView reading version aborts when the appVersionSource is not specified and the user chooses to set it to LOCAL 1`] = `"Aborting..."`;

exports[`BuildVersionGetView reading version when appVersionSource is set to local 1`] = `"This project is not configured for using remote version source. Add {"cli": { "appVersionSource": "remote" }} in eas.json or re-run this command without "--non-interactive" flag."`;
97 changes: 84 additions & 13 deletions packages/eas-cli/src/__tests__/commands/build-version-get-test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { AppVersionSource, EasJson } from '@expo/eas-json';
import chalk from 'chalk';

import { getMockEasJson, mockCommandContext, mockProjectId, mockTestCommand } from './utils';
import {
getMockEasJson,
mockCommandContext,
mockProjectId,
mockTestCommand,
withLocalVersionSource,
withRemoteVersionSource,
} from './utils';
import BuildVersionGetView from '../../commands/build/version/get';
import { AppVersionQuery } from '../../graphql/queries/AppVersionQuery';
import Log from '../../log';
import { AppVersionSourceUpdateOption } from '../../project/remoteVersionSource';
import * as prompts from '../../prompts';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';

jest.mock('../../project/applicationIdentifier');
jest.mock('fs');
jest.mock('../../log');
jest.mock('../../utils/json');
jest.mock('../../graphql/queries/AppVersionQuery');

function withRemoteVersionSource(easJson: EasJson): EasJson {
return {
...easJson,
cli: {
...easJson.cli,
appVersionSource: AppVersionSource.REMOTE,
},
};
}
jest.mock('../../prompts');

describe(BuildVersionGetView, () => {
afterEach(() => {
Expand Down Expand Up @@ -49,6 +48,29 @@ describe(BuildVersionGetView, () => {
expect(printJsonOnlyOutput).not.toHaveBeenCalled();
});

test('reading version for platform android when the appVersionSource is not specified and the user chooses to set it to REMOTE', async () => {
const ctx = mockCommandContext(BuildVersionGetView, {});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({
buildVersion: '100',
storeVersion: '1.0.0',
}));
const cmd = mockTestCommand(BuildVersionGetView, ['--platform=android'], ctx);
jest
.mocked(prompts.selectAsync)
.mockImplementationOnce(async () => AppVersionSourceUpdateOption.SET_TO_REMOTE);

await cmd.run();
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith(
ctx.loggedIn.graphqlClient,
mockProjectId,
'ANDROID',
'eas.test.com'
);
expect(Log.log).toHaveBeenCalledWith(`Android versionCode - ${chalk.bold('100')}`);
expect(enableJsonOutput).not.toHaveBeenCalled();
expect(printJsonOnlyOutput).not.toHaveBeenCalled();
});

test('reading version for platform android when no remote version is set', async () => {
const ctx = mockCommandContext(BuildVersionGetView, {
easJson: withRemoteVersionSource(getMockEasJson()),
Expand Down Expand Up @@ -145,7 +167,9 @@ describe(BuildVersionGetView, () => {
});

test('reading version when appVersionSource is set to local ', async () => {
const ctx = mockCommandContext(BuildVersionGetView, {});
const ctx = mockCommandContext(BuildVersionGetView, {
easJson: withLocalVersionSource(getMockEasJson()),
});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({
buildVersion: '100',
storeVersion: '1.0.0',
Expand All @@ -158,4 +182,51 @@ describe(BuildVersionGetView, () => {
);
await expect(cmd.run()).rejects.toThrowErrorMatchingSnapshot();
});

test('reading version aborts when the appVersionSource is not specified and the user chooses to set it to LOCAL', async () => {
const ctx = mockCommandContext(BuildVersionGetView, {});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({
buildVersion: '100',
storeVersion: '1.0.0',
}));
jest
.mocked(prompts.selectAsync)
.mockImplementationOnce(async () => AppVersionSourceUpdateOption.SET_TO_LOCAL);

const cmd = mockTestCommand(BuildVersionGetView, ['--platform=android'], ctx);
await expect(cmd.run()).rejects.toThrowErrorMatchingSnapshot();
});

test('reading version aborts when the appVersionSource is not specified and the user chooses to configure it manually', async () => {
const ctx = mockCommandContext(BuildVersionGetView, {});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({
buildVersion: '100',
storeVersion: '1.0.0',
}));
jest
.mocked(prompts.selectAsync)
.mockImplementationOnce(async () => AppVersionSourceUpdateOption.ABORT);

const cmd = mockTestCommand(BuildVersionGetView, ['--platform=android'], ctx);
await expect(cmd.run()).rejects.toThrowError('Aborted.');
});

test('reading version sets appVersionSource to LOCAL and aborts when the appVersionSource is not specified and is run in non-interactive mode', async () => {
const ctx = mockCommandContext(BuildVersionGetView, {});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({
buildVersion: '100',
storeVersion: '1.0.0',
}));

const cmd = mockTestCommand(
BuildVersionGetView,
['--non-interactive', '--json', '--platform=android'],
ctx
);
await expect(cmd.run()).rejects.toThrowError(
`This project is not configured for using remote version source. Add ${chalk.bold(
'{"cli": { "appVersionSource": "remote" }}'
)} in eas.json or re-run this command without "--non-interactive" flag.`
);
});
});
93 changes: 80 additions & 13 deletions packages/eas-cli/src/__tests__/commands/build-version-set-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AppVersionSource, EasJson } from '@expo/eas-json';
import fs from 'fs-extra';
import path from 'path';

Expand All @@ -8,12 +7,15 @@ import {
mockCommandContext,
mockProjectId,
mockTestCommand,
withLocalVersionSource,
withRemoteVersionSource,
} from './utils';
import BuildVersionSetView from '../../commands/build/version/set';
import { AppVersionMutation } from '../../graphql/mutations/AppVersionMutation';
import { AppQuery } from '../../graphql/queries/AppQuery';
import { AppVersionQuery } from '../../graphql/queries/AppVersionQuery';
import Log from '../../log';
import { AppVersionSourceUpdateOption } from '../../project/remoteVersionSource';
import * as prompts from '../../prompts';

jest.mock('../../project/applicationIdentifier');
Expand All @@ -25,16 +27,6 @@ jest.mock('../../log');
jest.mock('../../prompts');
jest.mock('../../utils/json');

function withRemoteVersionSource(easJson: EasJson): EasJson {
return {
...easJson,
cli: {
...easJson.cli,
appVersionSource: AppVersionSource.REMOTE,
},
};
}

describe(BuildVersionSetView, () => {
afterEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -67,6 +59,34 @@ describe(BuildVersionSetView, () => {
);
});

test('setting version for platform android when the appVersionSource is not specified and the user chooses to set it to REMOTE', async () => {
const ctx = mockCommandContext(BuildVersionSetView, {});
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment());
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null);
jest.mocked(prompts.promptAsync).mockImplementationOnce(async () => ({
version: '1000',
}));
jest
.mocked(prompts.selectAsync)
.mockImplementationOnce(async () => AppVersionSourceUpdateOption.SET_TO_REMOTE);

const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx);
await cmd.run();
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith(
ctx.loggedIn.graphqlClient,
mockProjectId,
'ANDROID',
'eas.test.com'
);
expect(AppVersionMutation.createAppVersionAsync).toHaveBeenCalledWith(
ctx.loggedIn.graphqlClient,
expect.objectContaining({
buildVersion: '1000',
storeVersion: '1.0.0',
})
);
});

test('printing current remote version before prompting for a new one', async () => {
const ctx = mockCommandContext(BuildVersionSetView, {
easJson: withRemoteVersionSource(getMockEasJson()),
Expand Down Expand Up @@ -115,7 +135,9 @@ describe(BuildVersionSetView, () => {
});

test('setting version aborts when appVersionSource is set to local and users refuse auto configuration', async () => {
const ctx = mockCommandContext(BuildVersionSetView, {});
const ctx = mockCommandContext(BuildVersionSetView, {
easJson: withLocalVersionSource(getMockEasJson()),
});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null);
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment());
jest.mocked(prompts.confirmAsync).mockImplementation(async () => false);
Expand All @@ -125,10 +147,26 @@ describe(BuildVersionSetView, () => {
expect(AppVersionMutation.createAppVersionAsync).not.toHaveBeenCalledWith();
});

test('setting version when appVersionSource is set to local and user allows auto configuration', async () => {
test('setting version aborts when the appVersionSource is not specified and the user chooses to set it to LOCAL, and they refuse auto configuration', async () => {
const ctx = mockCommandContext(BuildVersionSetView, {});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null);
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment());
jest
.mocked(prompts.selectAsync)
.mockImplementationOnce(async () => AppVersionSourceUpdateOption.SET_TO_LOCAL);
jest.mocked(prompts.confirmAsync).mockImplementationOnce(async () => false);

const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx);
await expect(cmd.run()).rejects.toThrowError('Aborting...');
expect(AppVersionMutation.createAppVersionAsync).not.toHaveBeenCalledWith();
});

test('setting version when appVersionSource is set to local and user allows auto configuration', async () => {
const ctx = mockCommandContext(BuildVersionSetView, {
easJson: withLocalVersionSource(getMockEasJson()),
});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null);
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment());
jest.mocked(prompts.confirmAsync).mockImplementation(async () => true);

const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx);
Expand All @@ -137,4 +175,33 @@ describe(BuildVersionSetView, () => {
const easJsonAfterCmd = await fs.readJson(path.join(ctx.projectDir, 'eas.json'));
expect(easJsonAfterCmd.cli.appVersionSource).toBe('remote');
});

test('setting version when the appVersionSource is not specified and the user chooses to set it to LOCAL, and they allow auto configuration', async () => {
const ctx = mockCommandContext(BuildVersionSetView, {});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null);
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment());
jest
.mocked(prompts.selectAsync)
.mockImplementationOnce(async () => AppVersionSourceUpdateOption.SET_TO_LOCAL);
jest.mocked(prompts.confirmAsync).mockImplementationOnce(async () => true);

const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx);
await cmd.run();

const easJsonAfterCmd = await fs.readJson(path.join(ctx.projectDir, 'eas.json'));
expect(easJsonAfterCmd.cli.appVersionSource).toBe('remote');
});

test('setting version aborts when the appVersionSource is not specified and the user chooses to configure manually', async () => {
const ctx = mockCommandContext(BuildVersionSetView, {});
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null);
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment());
jest
.mocked(prompts.selectAsync)
.mockImplementationOnce(async () => AppVersionSourceUpdateOption.ABORT);

const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx);
await expect(cmd.run()).rejects.toThrowError('Aborted.');
expect(AppVersionMutation.createAppVersionAsync).not.toHaveBeenCalledWith();
});
});
Loading

0 comments on commit 8c31825

Please sign in to comment.