diff --git a/.projenrc.ts b/.projenrc.ts index 5be2935..2dc8c43 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -73,5 +73,5 @@ jestConfig?.patch(JsonPatch.add('/transform', { '^.+\\.(t|j)sx?$': new Transform('@swc/jest'), })); const actionYml = project.tryFindObjectFile('action.yml'); -actionYml?.addOverride('runs.using', 'node18'); +actionYml?.addOverride('runs.using', 'node20'); project.synth(); diff --git a/action.yml b/action.yml index d489e83..f79c8c2 100644 --- a/action.yml +++ b/action.yml @@ -3,7 +3,7 @@ name: cdk-diff-action description: The CDK Diff GitHub Action allows you to run CDK diff as part of your CI/CD workflow. runs: - using: node18 + using: node20 main: dist/index.js author: Cory Hall inputs: diff --git a/src/action.ts b/src/action.ts index 83af964..f16ced0 100644 --- a/src/action.ts +++ b/src/action.ts @@ -26,6 +26,9 @@ export async function run() { const processor = new StageProcessor(stages, inputs.allowedDestroyTypes); await processor.processStages(); await processor.commentStages(comments); + if (processor.hasDestructiveChanges && inputs.failOnDestructiveChanges) { + throw new Error('There are destructive changes! See PR comment for details.'); + } return; } diff --git a/src/diff.ts b/src/diff.ts index be12c88..d1a022f 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -137,6 +137,15 @@ export class StageProcessor { } } + public get hasDestructiveChanges(): boolean { + for (const comments of Object.values(this.stageComments)) { + if (comments.destructiveChanges) { + return true; + } + } + return false; + } + private async diffStack(stack: StackInfo): Promise<{comment: string[]; changes: number}> { const stackDiff = new StackDiff(stack, this.allowedDestroyTypes); const { diff, destructiveChanges } = await stackDiff.diffStack();