feat: add ignoreAssetChanges input to drop asset-hash-only changes#163
Open
laazyj wants to merge 1 commit into
Open
feat: add ignoreAssetChanges input to drop asset-hash-only changes#163laazyj wants to merge 1 commit into
laazyj wants to merge 1 commit into
Conversation
CDK references bundled assets by content hash, so rebuilding an asset changes the synthesized template even when no infrastructure changed. For apps that deploy content via BucketDeployment, ship Lambda code as assets, or use custom-resource providers, every content change shows up as an update -- and because cloudformation-diff classifies an asset replacement as MAY_REPLACE, it trips the destructive-changes gate on routine content PRs. The existing AWS::Lambda::Function Code/Metadata exemption in evaluateDiff only adjusts the counts; the comment body is still rendered from the raw TemplateDiff, and no equivalent exists for Custom::CDKBucketDeployment. This generalizes that idea into an opt-in input applied to the TemplateDiff itself. When ignoreAssetChanges is true, any resource whose property updates are entirely asset hashes (Code, Metadata, SourceObjectKeys, CodeHash) is removed before counting, rendering, and destructive classification. Resources with any non-asset change are left fully intact. Refs corymhall#162.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #162.
Problem
A
Custom::CDKBucketDeployment'sSourceObjectKeyschanges on every content rebuild — the everyday case for a static site.cloudformation-diffclassifies that custom-resource property change asMAY_REPLACE, so by default it is reported as an update and a destructive change. With the defaultfailOnDestructiveChanges: true, that fails the job on every content-only PR, making the destructive gate unusable for any app that ships content viaBucketDeployment(or otherwise has asset-hash-only churn).This is also inconsistent today:
evaluateDiffalready exemptsAWS::Lambda::Functionwhose only changes areCode/Metadata— but only for the counts (the comment body is still rendered from the rawTemplateDiff), and there is no equivalent forCustom::CDKBucketDeployment. See also #161 and #4.What this adds
An opt-in
ignoreAssetChangesinput (defaultfalse). Whentrue, any resource difference whose property updates are entirely asset hashes —Code,Metadata,SourceObjectKeys,CodeHash— is dropped from theTemplateDiffup front, so it is absent from the change counts, the rendered comment, and the destructive-change classification alike. Resources with any non-asset change are left fully intact.The filter is applied once to
templateDiff.resources(viaDifferenceCollection.filter) beforeevaluateDiff/render, generalizing the existing hard-coded Lambda special-case into a documented option that also fixes the rendered body and the destructive gate.Changes
inputs.ts/.projenrc.ts(→ regeneratedaction.yml): newignoreAssetChangesinputaction.ts: read it viagetBooleanInputdiff.ts:isAssetOnlyChange()predicate +dropAssetOnlyChanges(), gated on the flag indiffStack()stage-processor.ts: thread the option intoStackDiffREADME.md: new "Ignore asset-only changes" sectiontest/diff.test.ts: 3 tests — asset-only change present by default, dropped when enabled, and a mixed-change resource left intactnpx projen buildpasses (compile + eslint + 31 tests + bundle).Live example
Dogfooded on a real repo. Same PR, toggling only this flag (identical content, identical deployed baseline):
ignoreAssetChanges: false→JasonDuffettNetSiteStack — 0 to add, 1 to update, 0 to destroy❌, 1 Destructive Change (MAY_REPLACEon the BucketDeployment),SourceObjectKeysdiff shown.ignoreAssetChanges: true→JasonDuffettNetSiteStack — 0 to add, 0 to update, 0 to destroy✅, no destructive changes,SourceObjectKeysfiltered — while an unrelatedDescriptionchange is retained (the filter is selective).Before/after captured here: laazyj/jasonduffett.net#48
Notes / open questions
Code/Metadatacount exemption untouched to avoid changing default behavior — happy to fold it into this mechanism in a follow-up if you'd prefer.