From effad1cf8a854789070e963691b30fadf1597afb Mon Sep 17 00:00:00 2001 From: SankyRed <121981451+SankyRed@users.noreply.github.com> Date: Mon, 11 Mar 2024 21:07:58 -0500 Subject: [PATCH 1/3] fix(cli): `cdk ls` returns stack id instead of stack display name (#29447) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Issue # (if applicable) Closes #29420 ### Reason for this change The `cdk list` functionality displays the stacks . For instance ``` > cdk ls producer consumer ``` With the latest changes for list stack dependencies we did add a new flag `-d` to show the dependencies. The dependencies between stacks can be established in 2 ways: 1. Using the resource defined from one stack in another. 2. Using `addDependency()` to add dependency among stacks. Current we are fetching the dependency details through the `CloudStackArtifact`. * Establishing the dependency between stacks through the first method would have the same `displayName` and `id` for the stacks. Using the `-d` flag to display dependencies - ``` ❯ cdk list --show-dependencies - id: producer dependencies: [] - id: consumer dependencies: - id: producer dependencies: [] ``` * Establishing the dependency through `addDependency()` will create a different `displayName` and `id`. In such a case when a user runs `cdk ls` we would want to show the `displayName` and if not present then use the `id` For instance: ``` > cdk ls producer producer/consumer ``` With the `-d` flag we would want to display something like: ``` > cdk ls -d - id: producer dependencies: [] - id: producer/consumer dependencies: - id: producer dependencies: [] ``` With our previous change we didn't consider `displayName` and just fetched `id`s which changes the previous functionality and caused a regression. ### Description of changes With the new changes we are looking out for `displayName` first and if it does not exist we fetch the `id`. ### Description of how you validated changes Added a new unit test and updated integ tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../cli-regression-patches/v2.132.0/NOTES.md | 1 + .../v2.132.0/skip-tests.txt | 4 + .../tests/cli-integ-tests/cli.integtest.ts | 8 +- packages/aws-cdk/lib/list-stacks.ts | 4 +- packages/aws-cdk/test/list-stacks.test.ts | 92 ++++++++++++++++++- 5 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md create mode 100644 packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md new file mode 100644 index 0000000000000..6f59e64a3b0b7 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md @@ -0,0 +1 @@ +This patch brings the [fix](https://github.com/aws/aws-cdk/issues/29420) into the regression suite. \ No newline at end of file diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt new file mode 100644 index 0000000000000..744f3c3396861 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt @@ -0,0 +1,4 @@ +# Skipping the test to fix issue https://github.com/aws/aws-cdk/issues/29420. +# cli-integ tests failing for the old tests with the new cli changes for list stacks. + +cdk ls --show-dependencies --json \ No newline at end of file diff --git a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts index d3d5b12d94154..3c69673e775ba 100644 --- a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts +++ b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts @@ -886,10 +886,10 @@ integTest('cdk ls --show-dependencies --json', withDefaultFixture(async (fixture id: 'list-stacks', dependencies: [ { - id: 'liststacksDependentStack', + id: 'list-stacks/DependentStack', dependencies: [ { - id: 'liststacksDependentStackInnerDependentStack', + id: 'list-stacks/DependentStack/InnerDependentStack', dependencies: [], }, ], @@ -900,11 +900,11 @@ integTest('cdk ls --show-dependencies --json', withDefaultFixture(async (fixture id: 'list-multiple-dependent-stacks', dependencies: [ { - id: 'listmultipledependentstacksDependentStack1', + id: 'list-multiple-dependent-stacks/DependentStack1', dependencies: [], }, { - id: 'listmultipledependentstacksDependentStack2', + id: 'list-multiple-dependent-stacks/DependentStack2', dependencies: [], }, ], diff --git a/packages/aws-cdk/lib/list-stacks.ts b/packages/aws-cdk/lib/list-stacks.ts index e76a1f393a0a9..dddf6fda3613e 100644 --- a/packages/aws-cdk/lib/list-stacks.ts +++ b/packages/aws-cdk/lib/list-stacks.ts @@ -56,7 +56,7 @@ export async function listStacks(toolkit: CdkToolkit, options: ListStacksOptions for (const stack of collectionOfStacks.stackArtifacts) { const data: StackDetails = { - id: stack.id, + id: stack.displayName ?? stack.id, name: stack.stackName, environment: stack.environment, dependencies: [], @@ -82,7 +82,7 @@ export async function listStacks(toolkit: CdkToolkit, options: ListStacksOptions } } else { data.dependencies.push({ - id: depStack.stackArtifacts[0].id, + id: depStack.stackArtifacts[0].displayName ?? depStack.stackArtifacts[0].id, dependencies: [], }); } diff --git a/packages/aws-cdk/test/list-stacks.test.ts b/packages/aws-cdk/test/list-stacks.test.ts index e36081e99c1d2..016a7160549a7 100644 --- a/packages/aws-cdk/test/list-stacks.test.ts +++ b/packages/aws-cdk/test/list-stacks.test.ts @@ -171,7 +171,7 @@ describe('list', () => { dependencies: [], }, { - id: 'Test-Stack-B', + id: 'Test-Stack-A/Test-Stack-B', name: 'Test-Stack-B', environment: { account: '123456789012', @@ -185,7 +185,7 @@ describe('list', () => { }])); }); - test('stacks with nested dependencies', async () => { + test('stacks with display names and have nested dependencies', async () => { let cloudExecutable = new MockCloudExecutable({ stacks: [ MockStack.MOCK_STACK_A, @@ -201,9 +201,84 @@ describe('list', () => { ], }, depends: ['Test-Stack-A'], + displayName: 'Test-Stack-A/Test-Stack-B', }, { stackName: 'Test-Stack-C', + template: { Resources: { TemplateName: 'Test-Stack-C' } }, + env: 'aws://123456789012/bermuda-triangle-1', + metadata: { + '/Test-Stack-C': [ + { + type: cxschema.ArtifactMetadataEntryType.STACK_TAGS, + }, + ], + }, + depends: ['Test-Stack-B'], + displayName: 'Test-Stack-A/Test-Stack-B/Test-Stack-C', + }, + ], + }); + + // GIVEN + const toolkit = new CdkToolkit({ + cloudExecutable, + configuration: cloudExecutable.configuration, + sdkProvider: cloudExecutable.sdkProvider, + deployments: cloudFormation, + }); + + // WHEN + const workflow = await listStacks( toolkit, { selectors: ['Test-Stack-A', 'Test-Stack-A/Test-Stack-B', 'Test-Stack-A/Test-Stack-B/Test-Stack-C'] }); + + // THEN + expect(JSON.stringify(workflow)).toEqual(JSON.stringify([{ + id: 'Test-Stack-A', + name: 'Test-Stack-A', + environment: { + account: '123456789012', + region: 'bermuda-triangle-1', + name: 'aws://123456789012/bermuda-triangle-1', + }, + dependencies: [], + }, + { + id: 'Test-Stack-A/Test-Stack-B', + name: 'Test-Stack-B', + environment: { + account: '123456789012', + region: 'bermuda-triangle-1', + name: 'aws://123456789012/bermuda-triangle-1', + }, + dependencies: [{ + id: 'Test-Stack-A', + dependencies: [], + }], + }, + { + id: 'Test-Stack-A/Test-Stack-B/Test-Stack-C', + name: 'Test-Stack-C', + environment: { + account: '123456789012', + region: 'bermuda-triangle-1', + name: 'aws://123456789012/bermuda-triangle-1', + }, + dependencies: [{ + id: 'Test-Stack-A/Test-Stack-B', + dependencies: [{ + id: 'Test-Stack-A', + dependencies: [], + }], + }], + }])); + }); + + test('stacks with nested dependencies', async () => { + let cloudExecutable = new MockCloudExecutable({ + stacks: [ + MockStack.MOCK_STACK_A, + { + stackName: 'Test-Stack-B', template: { Resources: { TemplateName: 'Test-Stack-B' } }, env: 'aws://123456789012/bermuda-triangle-1', metadata: { @@ -213,6 +288,19 @@ describe('list', () => { }, ], }, + depends: ['Test-Stack-A'], + }, + { + stackName: 'Test-Stack-C', + template: { Resources: { TemplateName: 'Test-Stack-C' } }, + env: 'aws://123456789012/bermuda-triangle-1', + metadata: { + '/Test-Stack-C': [ + { + type: cxschema.ArtifactMetadataEntryType.STACK_TAGS, + }, + ], + }, depends: ['Test-Stack-B'], }, ], From cac419929ef693922987e6f3a7c9ba48d150a241 Mon Sep 17 00:00:00 2001 From: SankyRed Date: Mon, 11 Mar 2024 22:20:24 -0500 Subject: [PATCH 2/3] chore(release): 2.132.1 --- CHANGELOG.v2.alpha.md | 2 ++ CHANGELOG.v2.md | 7 +++++++ version.v2.json | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.v2.alpha.md b/CHANGELOG.v2.alpha.md index 80d4811c7e8fd..65a6fe0616826 100644 --- a/CHANGELOG.v2.alpha.md +++ b/CHANGELOG.v2.alpha.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.132.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.132.0-alpha.0...v2.132.1-alpha.0) (2024-03-12) + ## [2.132.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.131.0-alpha.0...v2.132.0-alpha.0) (2024-03-08) diff --git a/CHANGELOG.v2.md b/CHANGELOG.v2.md index 98fcef35a476f..c1a7bbc1e3a26 100644 --- a/CHANGELOG.v2.md +++ b/CHANGELOG.v2.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.132.1](https://github.com/aws/aws-cdk/compare/v2.132.0...v2.132.1) (2024-03-12) + + +### Bug Fixes + +* **cli:** `cdk ls` returns stack id instead of stack display name ([#29447](https://github.com/aws/aws-cdk/issues/29447)) ([effad1c](https://github.com/aws/aws-cdk/commit/effad1cf8a854789070e963691b30fadf1597afb)), closes [#29420](https://github.com/aws/aws-cdk/issues/29420) + ## [2.132.0](https://github.com/aws/aws-cdk/compare/v2.131.0...v2.132.0) (2024-03-08) diff --git a/version.v2.json b/version.v2.json index 176e52d9a2492..213eefdc1ca87 100644 --- a/version.v2.json +++ b/version.v2.json @@ -1,4 +1,4 @@ { - "version": "2.132.0", - "alphaVersion": "2.132.0-alpha.0" + "version": "2.132.1", + "alphaVersion": "2.132.1-alpha.0" } \ No newline at end of file From 79730e6acc1f3883c2c93f3439879271f81fdbf7 Mon Sep 17 00:00:00 2001 From: SankyRed Date: Mon, 11 Mar 2024 22:47:38 -0500 Subject: [PATCH 3/3] chore: update changelog --- CHANGELOG.v2.alpha.md | 2 +- CHANGELOG.v2.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.v2.alpha.md b/CHANGELOG.v2.alpha.md index 65a6fe0616826..c65bc01de5f12 100644 --- a/CHANGELOG.v2.alpha.md +++ b/CHANGELOG.v2.alpha.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -### [2.132.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.132.0-alpha.0...v2.132.1-alpha.0) (2024-03-12) +## [2.132.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.132.0-alpha.0...v2.132.1-alpha.0) (2024-03-12) ## [2.132.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.131.0-alpha.0...v2.132.0-alpha.0) (2024-03-08) diff --git a/CHANGELOG.v2.md b/CHANGELOG.v2.md index c1a7bbc1e3a26..bf338bfa1ad6d 100644 --- a/CHANGELOG.v2.md +++ b/CHANGELOG.v2.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -### [2.132.1](https://github.com/aws/aws-cdk/compare/v2.132.0...v2.132.1) (2024-03-12) +## [2.132.1](https://github.com/aws/aws-cdk/compare/v2.132.0...v2.132.1) (2024-03-12) ### Bug Fixes