Skip to content

Commit 3ef1921

Browse files
corymhallgithub-actions
andauthored
feat!: use toolkit-lib for diff (#125)
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>
1 parent 2f4259c commit 3ef1921

35 files changed

+405458
-68949
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/deps.json

Lines changed: 2 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,52 +47,89 @@ const project = new GitHubActionTypeScriptProject({
4747
required: false,
4848
default: 'true',
4949
},
50-
noDiffForStages: {
51-
description: 'List of stages to ignore and not show a diff for',
50+
stackSelectorPatterns: {
51+
description: 'Comma delimited list of stack selector patterns. Use this to control which stages/stacks to diff. By default all stages & stacks are diffed\n\n'+
52+
'@see https://github.com/aws/aws-cdk-cli/tree/main/packages/%40aws-cdk/toolkit-lib#stack-selection',
5253
required: false,
5354
default: '',
5455
},
56+
stackSelectionStrategy: {
57+
description: [
58+
'Used in combination with "stackSelectorPatterns" to control which stacks to diff.',
59+
'',
60+
'Valid values are "all-stacks", "main-assembly", "only-single", "pattern-match",',
61+
'"pattern-must-match", "pattern-must-match-single"',
62+
'',
63+
'@default pattern-must-match if "stackSelectorPatterns" is provided, otherwise "all-stacks"',
64+
'@see https://github.com/aws/aws-cdk-cli/tree/main/packages/%40aws-cdk/toolkit-lib#stack-selection',
65+
].join('\n'),
66+
default: 'all-stacks',
67+
required: false,
68+
},
5569
noFailOnDestructiveChanges: {
56-
description: '',
70+
description: 'List of stages where breaking changes will not fail the build',
5771
required: false,
58-
default: 'List of stages where breaking changes will not fail the build',
72+
default: '',
5973
},
6074
cdkOutDir: {
6175
description: 'The location of the CDK output directory',
6276
required: false,
6377
default: 'cdk.out',
6478
},
79+
diffMethod: {
80+
description: ['The method to create a stack diff.',
81+
'',
82+
"Valid values are 'change-set' or 'template-only'.",
83+
'',
84+
'Use changeset diff for the highest fidelity, including analyze resource replacements.',
85+
'In this method, diff will use the deploy role instead of the lookup role.',
86+
'',
87+
"Use template-only diff for a faster, less accurate diff that doesn't require",
88+
'permissions to create a change-set.'].join('\n'),
89+
required: false,
90+
default: 'change-set',
91+
},
6592
},
6693
runs: {
6794
using: RunsUsing.NODE_20,
6895
main: 'dist/index.js',
6996
},
7097
},
7198
deps: [
72-
'@octokit/webhooks-definitions',
7399
'@aws-cdk/cloudformation-diff',
100+
'@aws-cdk/cx-api',
101+
'@aws-cdk/toolkit-lib',
102+
'@octokit/webhooks-definitions',
74103
'@aws-cdk/cloud-assembly-schema',
75104
'@actions/exec@^1.1.1',
76105
'@actions/io@^1.1.3',
77106
'@actions/tool-cache@^2.0.0',
78107
'fs-extra',
79-
'@aws-sdk/client-cloudformation',
80-
'@aws-sdk/client-sts',
81-
'@smithy/types',
82108
'chalk@^4',
83-
'@aws-sdk/credential-providers',
84109
],
85110
devDeps: [
86-
'aws-sdk',
87111
'mock-fs@^5',
88-
'aws-sdk-client-mock',
89112
'@types/mock-fs@^4',
90113
'projen-github-action-typescript',
91114
'@types/fs-extra',
92115
'action-docs',
93116
'@swc/core',
94117
'@swc/jest',
95118
],
119+
tsconfig: {
120+
compilerOptions: {
121+
lib: ['es2022', 'esnext'],
122+
// TODO: https://github.com/aws/aws-cdk-cli/issues/418
123+
skipLibCheck: true,
124+
},
125+
},
126+
tsconfigDev: {
127+
compilerOptions: {
128+
lib: ['es2022', 'esnext'],
129+
// TODO: https://github.com/aws/aws-cdk-cli/issues/418
130+
skipLibCheck: true,
131+
},
132+
},
96133
jestOptions: {
97134
configFilePath: 'jest.config.json',
98135
},
@@ -215,6 +252,6 @@ workflow?.on({
215252
});
216253

217254
projenProject.packageTask.reset();
218-
projenProject.packageTask.exec('cp node_modules/@aws-cdk/aws-service-spec/db.json.gz ./ && ncc build --source-map --license licenses.txt');
255+
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');
219256
workflow?.addJobs({ enableAutoMerge: autoMergeJob });
220257
project.synth();

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
role-to-assume: arn:aws:iam::1234567891012:role/cdk_github_actions
5454
role-session-name: github
5555
- name: Diff
56-
uses: corymhall/cdk-diff-action@v1
56+
uses: corymhall/cdk-diff-action@v2-beta
5757
with:
5858
githubToken: ${{ secrets.GITHUB_TOKEN }}
5959
```
@@ -82,25 +82,33 @@ jobs:
8282
Synth:
8383
steps:
8484
- name: Diff
85-
uses: corymhall/cdk-diff-action@v1
85+
uses: corymhall/cdk-diff-action@v2-beta
8686
with:
87-
allowedDestroyTypes: "AWS::ECS::TaskDefinition,AWS::CloudWatch::Dashboard"
87+
allowedDestroyTypes: |
88+
AWS::ECS::TaskDefinition
89+
AWS::CloudWatch::Dashboard
8890
githubToken: ${{ secrets.GITHUB_TOKEN }}
8991
9092
```
9193

9294
### Disable showing diff for stages
9395

94-
You can disable displaying the diff for certain stages by using `noDiffForStages`
96+
You can disable displaying the diff for certain stages or stacks by using
97+
`stackSelectorPatterns`. `stackSelectorPatterns` using `glob` patterns to filter
98+
which stacks to diff. To exclude stacks you can use an exclude pattern (e.g.
99+
`!SomeStage/SampleStack`). To exclude an entire stage you would provide
100+
`!SomeStage/*`.
95101

96102
```yml
97103
jobs:
98104
Synth:
99105
steps:
100106
- name: Diff
101-
uses: corymhall/cdk-diff-action@v1
107+
uses: corymhall/cdk-diff-action@v2-beta
102108
with:
103-
noDiffForStages: "Stage1,Stage2"
109+
StackSelectorPatterns: |
110+
!Stage1/*
111+
!Stage2/*
104112
githubToken: ${{ secrets.GITHUB_TOKEN }}
105113
```
106114

@@ -114,9 +122,11 @@ jobs:
114122
Synth:
115123
steps:
116124
- name: Diff
117-
uses: corymhall/cdk-diff-action@v1
125+
uses: corymhall/cdk-diff-action@v2-beta
118126
with:
119-
noFailOnDestructiveChanges: "Stage1,Stage2"
127+
noFailOnDestructiveChanges: |
128+
Stage1
129+
Stage2
120130
githubToken: ${{ secrets.GITHUB_TOKEN }}
121131
```
122132

@@ -130,7 +140,7 @@ jobs:
130140
Synth:
131141
steps:
132142
- name: Diff
133-
uses: corymhall/cdk-diff-action@v1
143+
uses: corymhall/cdk-diff-action@v2-beta
134144
with:
135145
failOnDestructiveChanges: false
136146
githubToken: ${{ secrets.GITHUB_TOKEN }}

action.yml

Lines changed: 31 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bin/cdk-assets

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bin/cdk-assets.d.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bin/cdk-assets.js

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bin/docker-credential-cdk-assets

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)