Skip to content

Commit

Permalink
feat: fail action if there are destructive changes
Browse files Browse the repository at this point in the history
  • Loading branch information
corymhall committed Oct 30, 2023
1 parent 3762896 commit fd6b6fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion action.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

9 changes: 9 additions & 0 deletions src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fd6b6fd

Please sign in to comment.