Skip to content

Commit 56a3435

Browse files
zemanelbep
authored andcommitted
deploy: Do not call CDN service invalidation when executing a dry run deployment
Currently, if cache invalidation is enabled when running `hugo deploy --dryRun` with , the deployer does not take the dry run flag into consideration and triggers CloudFront/GoogleCloudCDN cache invalidation if any of those services are configured. This change will instead print a feedback message if a dry run is in effect and quiet mode is not enabled. Fixes #7884
1 parent d48a98c commit 56a3435

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

deploy/deploy.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,29 @@ func (d *Deployer) Deploy(ctx context.Context) error {
262262

263263
if d.invalidateCDN {
264264
if d.target.CloudFrontDistributionID != "" {
265-
jww.FEEDBACK.Println("Invalidating CloudFront CDN...")
266-
if err := InvalidateCloudFront(ctx, d.target.CloudFrontDistributionID); err != nil {
267-
jww.FEEDBACK.Printf("Failed to invalidate CloudFront CDN: %v\n", err)
268-
return err
265+
if d.dryRun {
266+
if !d.quiet {
267+
jww.FEEDBACK.Printf("[DRY RUN] Would invalidate CloudFront CDN with ID %s\n", d.target.CloudFrontDistributionID)
268+
}
269+
} else {
270+
jww.FEEDBACK.Println("Invalidating CloudFront CDN...")
271+
if err := InvalidateCloudFront(ctx, d.target.CloudFrontDistributionID); err != nil {
272+
jww.FEEDBACK.Printf("Failed to invalidate CloudFront CDN: %v\n", err)
273+
return err
274+
}
269275
}
270276
}
271277
if d.target.GoogleCloudCDNOrigin != "" {
272-
jww.FEEDBACK.Println("Invalidating Google Cloud CDN...")
273-
if err := InvalidateGoogleCloudCDN(ctx, d.target.GoogleCloudCDNOrigin); err != nil {
274-
jww.FEEDBACK.Printf("Failed to invalidate Google Cloud CDN: %v\n", err)
275-
return err
278+
if d.dryRun {
279+
if !d.quiet {
280+
jww.FEEDBACK.Printf("[DRY RUN] Would invalidate Google Cloud CDN with origin %s\n", d.target.GoogleCloudCDNOrigin)
281+
}
282+
} else {
283+
jww.FEEDBACK.Println("Invalidating Google Cloud CDN...")
284+
if err := InvalidateGoogleCloudCDN(ctx, d.target.GoogleCloudCDNOrigin); err != nil {
285+
jww.FEEDBACK.Printf("Failed to invalidate Google Cloud CDN: %v\n", err)
286+
return err
287+
}
276288
}
277289
}
278290
jww.FEEDBACK.Println("Success!")

0 commit comments

Comments
 (0)