Skip to content

feat!: use toolkit-lib for diff#125

Merged
corymhall merged 13 commits intov2-betafrom
corymhall/use-toolkit
May 3, 2025
Merged

feat!: use toolkit-lib for diff#125
corymhall merged 13 commits intov2-betafrom
corymhall/use-toolkit

Conversation

@corymhall
Copy link
Owner

@corymhall corymhall commented Apr 27, 2025

This PR refactors the diff and assembly processing to use the new @aws-cdk/toolkit-lib library.

This allows us to greatly simplify the logic that we have to maintain and offload more work to the core library.
For example, this allows us to use the default CDK authentication instead of trying to replicate it ourselves (see #62).

Couple of other changes that I've included in this PR since v2 allows me a chance to make breaking changes.

BREAKING CHANGE: several breaking changes with details below

There are several breaking changes in this release.

  1. Replace noDiffForStages with stackSelectionStrategy & stackSelectorPatterns
    This uses the native selection stack filtering capability of toolkit-lib and should be a more robust option for users to filter stacks. stackSelectorPatterns also uses a multi-line input instead of a comma delimited string input. To migrate from noDiffForStages to stackSelectorPatterns you can do this:
# from this
- name: Diff
   uses: corymhall/cdk-diff-action@v1
   with:
     noDiffForStages: "Stage1,Stage2"
     githubToken: ${{ secrets.GITHUB_TOKEN }}

# to this
- name: Diff
   uses: corymhall/cdk-diff-action@v2-beta
   with:
     stackSelectorPatterns: |
       !Stage1/*
       !Stage2/*
     githubToken: ${{ secrets.GITHUB_TOKEN }}
  1. The default diffMethod is changed to change-set to match the cdk default behavior. This also changes the IAM Role used for diff from the lookup-role to the deploy-role. To keep the old behavior you can specify diffMethod: template-only
  2. allowDestroyTypes and noFailOnDestructiveChanges input types were changed from a comma delimited string to a multi-line string.
# from this
- name: Diff
   uses: corymhall/cdk-diff-action@v1
   with:
     noFailOnDestructiveChanges: "Stage1,Stage2"
     githubToken: ${{ secrets.GITHUB_TOKEN }}

# to this
- name: Diff
   uses: corymhall/cdk-diff-action@v2-beta
   with:
     noFailOnDestructiveChanges: |
       Stage1
       Stage2
     githubToken: ${{ secrets.GITHUB_TOKEN }}

Closes #44
Fixes #62

@corymhall corymhall requested a review from Copilot May 2, 2025 09:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the diff processing and assembly reading logic by migrating to the new toolkit‑lib API while updating tests and inputs accordingly. Key changes include:

  • Introducing a FakeIoHost and modifying test cases to use toolkit‑lib imports.
  • Renaming and refactoring the StageProcessor to AssemblyProcessor with updated diff handling.
  • Updating inputs and configuration files (action.yml/.projenrc.ts) to align with new stack selector patterns and diff methods.

Reviewed Changes

Copilot reviewed 17 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/util.ts Adds a FakeIoHost implementation with toolkit‑lib interfaces.
test/diff.test.ts Updates tests to use toolkit‑lib diff and stack selection, removing legacy AWS SDK mocks.
test/assembly.test.ts Adjusts manifest reader tests to work with CloudAssembly-based constructs.
src/stage-processor.ts Renames StageProcessor to AssemblyProcessor and updates diff processing logic.
src/inputs.ts Replaces noDiffForStages with stackSelectorPatterns and adds diffMethod.
src/diff.ts Removes legacy credential/environment validation and switches to diff-based changes.
src/assembly.ts Refactors AssemblyManifestReader to use CloudAssembly and filter stacks by diff presence.
src/action.ts Updates action inputs and instantiates AssemblyProcessor with toolkit‑lib.
action.yml Updates input definitions and defaults to support new diff method and stack selection.
.projenrc.ts Updates configuration for new input patterns and adjusts packaging command.
Files not reviewed (4)
  • .projen/deps.json: Language not supported
  • .projen/tasks.json: Language not supported
  • package.json: Language not supported
  • tsconfig.dev.json: Language not supported
Comments suppressed due to low confidence (2)

src/stage-processor.ts:137

  • Consider verifying that the 'await using' syntax is supported in your target Node.js version and document its intended resource management behavior for clarity.
await using cloudAssembly = await assemblySource.produce();

.projenrc.ts:251

  • [nitpick] Verify that 'src/index.ts' is intended as the main entry point for packaging, as the updated command differs from the previous configuration.
projenProject.packageTask.exec('cp node_modules/@aws-cdk/aws-service-spec/db.json.gz ./ && ncc build src/index.ts --source-map --transpile-only --license licenses.txt');

cdkOutDir: getInput('cdkOutDir', { required: true }),
diffMethod: getInput('diffMethod', { required: true }),
};

Copy link

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Add a code comment explaining why the stackSelectionStrategy is forcibly set to 'pattern-must-match' when stackSelectorPatterns are provided to clarify the design intent.

Suggested change
// If stackSelectorPatterns are provided, the stackSelectionStrategy must be set to 'pattern-must-match'
// to ensure that only stacks matching the specified patterns are selected. This overrides the default
// 'all-stacks' strategy to prevent unintended behavior.

Copilot uses AI. Check for mistakes.
@corymhall corymhall changed the base branch from main to v2-beta May 2, 2025 09:37
@corymhall corymhall force-pushed the corymhall/use-toolkit branch from 64c3251 to 3bcaa22 Compare May 2, 2025 12:00
corymhall and others added 2 commits May 3, 2025 05:26
Signed-off-by: github-actions <github-actions@github.com>
@corymhall corymhall marked this pull request as ready for review May 3, 2025 10:10
@corymhall corymhall enabled auto-merge (squash) May 3, 2025 10:14
@corymhall corymhall disabled auto-merge May 3, 2025 10:14
@corymhall corymhall merged commit 3ef1921 into v2-beta May 3, 2025
8 of 9 checks passed
@corymhall corymhall deleted the corymhall/use-toolkit branch May 3, 2025 10:15
corymhall added a commit that referenced this pull request Jun 20, 2025
This PR refactors the diff and assembly processing to use the new
`@aws-cdk/toolkit-lib` library.

This allows us to greatly simplify the logic that we have to maintain
and offload more work to the core library.
For example, this allows us to use the default CDK authentication
instead of trying to replicate it ourselves (see #62).

Couple of other changes that I've included in this PR since v2 allows me
a chance to make breaking changes.

BREAKING CHANGE: several breaking changes with details below

There are several breaking changes in this release.
1. Replace `noDiffForStages` with `stackSelectionStrategy` &
`stackSelectorPatterns`
This uses the native selection stack filtering capability of
`toolkit-lib` and should be a more robust option for users to filter
stacks. `stackSelectorPatterns` also uses a multi-line input instead of
a comma delimited string input. To migrate from `noDiffForStages` to
`stackSelectorPatterns` you can do this:
```yaml
- name: Diff
   uses: corymhall/cdk-diff-action@v1
   with:
     noDiffForStages: "Stage1,Stage2"
     githubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Diff
   uses: corymhall/cdk-diff-action@v2-beta
   with:
     stackSelectorPatterns: |
       !Stage1/*
       !Stage2/*
     githubToken: ${{ secrets.GITHUB_TOKEN }}
```
2. The default `diffMethod` is changed to `change-set` to match the cdk
default behavior. This also changes the IAM Role used for diff from the
`lookup-role` to the `deploy-role`. To keep the old behavior you can
specify `diffMethod: template-only`
3. `allowDestroyTypes` and `noFailOnDestructiveChanges` input types were
changed from a comma delimited string to a multi-line string.
```yaml
- name: Diff
   uses: corymhall/cdk-diff-action@v1
   with:
     noFailOnDestructiveChanges: "Stage1,Stage2"
     githubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Diff
   uses: corymhall/cdk-diff-action@v2-beta
   with:
     noFailOnDestructiveChanges: |
       Stage1
       Stage2
     githubToken: ${{ secrets.GITHUB_TOKEN }}
```

Closes #44
Fixes #62

---------

Signed-off-by: github-actions <github-actions@github.com>
Co-authored-by: github-actions <github-actions@github.com>
corymhall added a commit that referenced this pull request Jun 20, 2025
This PR refactors the diff and assembly processing to use the new
`@aws-cdk/toolkit-lib` library.

This allows us to greatly simplify the logic that we have to maintain
and offload more work to the core library.
For example, this allows us to use the default CDK authentication
instead of trying to replicate it ourselves (see #62).

Couple of other changes that I've included in this PR since v2 allows me
a chance to make breaking changes.

BREAKING CHANGE: several breaking changes with details below

There are several breaking changes in this release.
1. Replace `noDiffForStages` with `stackSelectionStrategy` &
`stackSelectorPatterns`
This uses the native selection stack filtering capability of
`toolkit-lib` and should be a more robust option for users to filter
stacks. `stackSelectorPatterns` also uses a multi-line input instead of
a comma delimited string input. To migrate from `noDiffForStages` to
`stackSelectorPatterns` you can do this:
```yaml
# from this
- name: Diff
   uses: corymhall/cdk-diff-action@v1
   with:
     noDiffForStages: "Stage1,Stage2"
     githubToken: ${{ secrets.GITHUB_TOKEN }}

# to this
- name: Diff
   uses: corymhall/cdk-diff-action@v2-beta
   with:
     stackSelectorPatterns: |
       !Stage1/*
       !Stage2/*
     githubToken: ${{ secrets.GITHUB_TOKEN }}
```
2. The default `diffMethod` is changed to `change-set` to match the cdk
default behavior. This also changes the IAM Role used for diff from the
`lookup-role` to the `deploy-role`. To keep the old behavior you can
specify `diffMethod: template-only`
3. `allowDestroyTypes` and `noFailOnDestructiveChanges` input types were
changed from a comma delimited string to a multi-line string.
```yaml
# from this
- name: Diff
   uses: corymhall/cdk-diff-action@v1
   with:
     noFailOnDestructiveChanges: "Stage1,Stage2"
     githubToken: ${{ secrets.GITHUB_TOKEN }}

# to this
- name: Diff
   uses: corymhall/cdk-diff-action@v2-beta
   with:
     noFailOnDestructiveChanges: |
       Stage1
       Stage2
     githubToken: ${{ secrets.GITHUB_TOKEN }}
```


Closes #44
Fixes #62

---------

Signed-off-by: github-actions <github-actions@github.com>
Co-authored-by: github-actions <github-actions@github.com>Fixes #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants