-
Notifications
You must be signed in to change notification settings - Fork 233
[Phase 0] Deprecate --force on app deploy and app release #6993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
df0107f
ef78588
eaed367
4d1eb41
0861abf
8889ed3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@shopify/app': patch | ||
| --- | ||
|
|
||
| Deprecation warning for `--force` flag on `app deploy` and `app release`. The flag will be removed in the next major release. Use `--allow-updates` for CI/CD environments, or `--allow-updates --allow-deletes` if you also want to allow removals. The `SHOPIFY_FLAG_FORCE` environment variable is also deprecated. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import Deploy from './deploy.js' | ||
| import {testAppLinked, testDeveloperPlatformClient, testOrganizationApp} from '../../models/app/app.test-data.js' | ||
| import {OrganizationSource} from '../../models/organization.js' | ||
| import {describe, expect, test, vi, beforeEach} from 'vitest' | ||
| import {renderWarning} from '@shopify/cli-kit/node/ui' | ||
|
|
||
| vi.mock('../../services/deploy.js') | ||
| vi.mock('../../services/app-context.js') | ||
| vi.mock('../../metadata.js', () => ({default: {addPublicMetadata: vi.fn()}})) | ||
| vi.mock('@shopify/cli-kit/node/metadata', () => ({addPublicMetadata: vi.fn()})) | ||
| vi.mock('../../validations/version-name.js', () => ({validateVersion: vi.fn()})) | ||
| vi.mock('../../validations/message.js', () => ({validateMessage: vi.fn()})) | ||
| vi.mock('@shopify/cli-kit/node/ui', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('@shopify/cli-kit/node/ui')>() | ||
| return {...actual, renderWarning: vi.fn()} | ||
| }) | ||
|
|
||
| describe('app deploy --force deprecation warning', () => { | ||
| beforeEach(async () => { | ||
| const {linkedAppContext} = await import('../../services/app-context.js') | ||
| const {deploy} = await import('../../services/deploy.js') | ||
| vi.mocked(linkedAppContext).mockResolvedValue({ | ||
| app: testAppLinked(), | ||
| remoteApp: testOrganizationApp(), | ||
| developerPlatformClient: testDeveloperPlatformClient(), | ||
| organization: { | ||
| id: '1', | ||
| businessName: 'test', | ||
| source: OrganizationSource.Partners, | ||
| }, | ||
| specifications: [], | ||
| }) | ||
| vi.mocked(deploy).mockResolvedValue({app: testAppLinked()}) | ||
| }) | ||
|
|
||
| test('shows deprecation warning when --force is passed', async () => { | ||
| await Deploy.run(['--force']) | ||
|
|
||
| expect(renderWarning).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| headline: expect.arrayContaining(['The']), | ||
| body: expect.arrayContaining(['Use']), | ||
| }), | ||
| ) | ||
| const call = vi.mocked(renderWarning).mock.calls[0]![0] | ||
| expect(JSON.stringify(call)).toContain('--force') | ||
| expect(JSON.stringify(call)).toContain('next major release') | ||
| }) | ||
|
|
||
| test('shows deprecation warning when SHOPIFY_FLAG_FORCE env var is set', async () => { | ||
| vi.stubEnv('SHOPIFY_FLAG_FORCE', '1') | ||
|
|
||
| await Deploy.run([]) | ||
|
|
||
| expect(renderWarning).toHaveBeenCalled() | ||
| const call = vi.mocked(renderWarning).mock.calls[0]![0] | ||
| expect(JSON.stringify(call)).toContain('--force') | ||
|
|
||
| vi.unstubAllEnvs() | ||
| }) | ||
|
|
||
| test('does not show deprecation warning when only --allow-updates is passed', async () => { | ||
| await Deploy.run(['--allow-updates']) | ||
|
|
||
| expect(renderWarning).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('does not show deprecation warning when --allow-updates and --allow-deletes are passed', async () => { | ||
| await Deploy.run(['--allow-updates', '--allow-deletes']) | ||
alfonso-noriega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| expect(renderWarning).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('does not show deprecation warning when only --allow-deletes is passed', async () => { | ||
| await Deploy.run(['--allow-deletes']) | ||
|
|
||
| expect(renderWarning).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import {linkedAppContext} from '../../services/app-context.js' | |
| import {Flags} from '@oclif/core' | ||
| import {globalFlags} from '@shopify/cli-kit/node/cli' | ||
| import {addPublicMetadata} from '@shopify/cli-kit/node/metadata' | ||
| import {renderWarning} from '@shopify/cli-kit/node/ui' | ||
|
|
||
| export default class Deploy extends AppLinkedCommand { | ||
| static summary = 'Deploy your Shopify app.' | ||
|
|
@@ -27,7 +28,7 @@ export default class Deploy extends AppLinkedCommand { | |
| force: Flags.boolean({ | ||
| hidden: false, | ||
| description: | ||
| 'Deploy without asking for confirmation. Equivalent to --allow-updates --allow-deletes. For CI/CD environments, the recommended flag is --allow-updates.', | ||
| '[Deprecated] Deploy without asking for confirmation. Equivalent to --allow-updates --allow-deletes. Use --allow-updates for CI/CD environments instead.', | ||
| env: 'SHOPIFY_FLAG_FORCE', | ||
| char: 'f', | ||
| }), | ||
|
Comment on lines
30
to
34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A flag in Oclif can be marked as deprecated natively. deprecated: true
// or
deprecated: {message....}not sure how it looks like, but worth checking it out
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Investigated it — oclif's native
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, wonder if this is something that can be generalized in the BaseCommand though! dynamically look if you are using deprecated flags and show a custom message.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 This extraction would be a good follow-up. |
||
|
|
@@ -79,6 +80,19 @@ export default class Deploy extends AppLinkedCommand { | |
| async run(): Promise<AppLinkedCommandOutput> { | ||
| const {flags} = await this.parse(Deploy) | ||
|
|
||
| if (flags.force) { | ||
| renderWarning({ | ||
| headline: ['The', {command: '--force'}, 'flag is deprecated and will be removed in the next major release.'], | ||
| body: [ | ||
| 'Use', | ||
| {command: '--allow-updates'}, | ||
| 'for CI/CD environments, or', | ||
| {command: '--allow-updates --allow-deletes'}, | ||
| 'if you also want to allow removals.', | ||
| ], | ||
| }) | ||
| } | ||
|
|
||
| await metadata.addPublicMetadata(() => ({ | ||
| cmd_deploy_flag_message_used: Boolean(flags.message), | ||
| cmd_deploy_flag_version_used: Boolean(flags.version), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import Release from './release.js' | ||
| import {testAppLinked, testDeveloperPlatformClient, testOrganizationApp} from '../../models/app/app.test-data.js' | ||
| import {OrganizationSource} from '../../models/organization.js' | ||
| import {describe, expect, test, vi, beforeEach} from 'vitest' | ||
| import {renderWarning} from '@shopify/cli-kit/node/ui' | ||
|
|
||
| vi.mock('../../services/release.js') | ||
| vi.mock('../../services/app-context.js') | ||
| vi.mock('@shopify/cli-kit/node/metadata', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('@shopify/cli-kit/node/metadata')>() | ||
| return {...actual, addPublicMetadata: vi.fn()} | ||
| }) | ||
| vi.mock('@shopify/cli-kit/node/ui', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('@shopify/cli-kit/node/ui')>() | ||
| return {...actual, renderWarning: vi.fn()} | ||
| }) | ||
|
|
||
| describe('app release --force deprecation warning', () => { | ||
| beforeEach(async () => { | ||
| const {linkedAppContext} = await import('../../services/app-context.js') | ||
| const {release} = await import('../../services/release.js') | ||
| vi.mocked(linkedAppContext).mockResolvedValue({ | ||
| app: testAppLinked(), | ||
| remoteApp: testOrganizationApp(), | ||
| developerPlatformClient: testDeveloperPlatformClient(), | ||
| organization: { | ||
| id: '1', | ||
| businessName: 'test', | ||
| source: OrganizationSource.Partners, | ||
| }, | ||
| specifications: [], | ||
| }) | ||
| vi.mocked(release).mockResolvedValue(undefined) | ||
| }) | ||
|
|
||
| test('shows deprecation warning when --force is passed', async () => { | ||
| await Release.run(['--version', 'v1.0.0', '--force']) | ||
|
|
||
| expect(renderWarning).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| headline: expect.arrayContaining(['The']), | ||
| body: expect.arrayContaining(['Use']), | ||
| }), | ||
| ) | ||
| const call = vi.mocked(renderWarning).mock.calls[0]![0] | ||
| expect(JSON.stringify(call)).toContain('--force') | ||
| expect(JSON.stringify(call)).toContain('next major release') | ||
| }) | ||
|
|
||
| test('shows deprecation warning when SHOPIFY_FLAG_FORCE env var is set', async () => { | ||
| vi.stubEnv('SHOPIFY_FLAG_FORCE', '1') | ||
|
|
||
| await Release.run(['--version', 'v1.0.0']) | ||
|
|
||
| expect(renderWarning).toHaveBeenCalled() | ||
| const call = vi.mocked(renderWarning).mock.calls[0]![0] | ||
| expect(JSON.stringify(call)).toContain('--force') | ||
|
|
||
| vi.unstubAllEnvs() | ||
| }) | ||
|
|
||
| test('does not show deprecation warning when only --allow-updates is passed', async () => { | ||
| await Release.run(['--version', 'v1.0.0', '--allow-updates']) | ||
|
|
||
| expect(renderWarning).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('does not show deprecation warning when --allow-updates and --allow-deletes are passed', async () => { | ||
| await Release.run(['--version', 'v1.0.0', '--allow-updates', '--allow-deletes']) | ||
|
|
||
| expect(renderWarning).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('does not show deprecation warning when only --allow-deletes is passed', async () => { | ||
| await Release.run(['--version', 'v1.0.0', '--allow-deletes']) | ||
|
|
||
| expect(renderWarning).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.