From 4d5cced77e391ada841072f008ed89f4e69cc2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 18 Jun 2023 18:35:11 +0200 Subject: [PATCH] deploy: Fix deploy defaults for non-zero flag values (e.g. maxDeletes, invalidateCDN) This was broken in the config rewrite in Hugo 0.112.0. The workaround is to be explicit about setting these flag values (even if just using the defaults), e.g.: ``` hugo deploy --invalidateCDN --maxDeletes 256 ``` Fixes #11127 --- commands/deploy.go | 2 ++ deploy/deployConfig.go | 11 ++++++++--- testscripts/commands/deploy.txt | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/commands/deploy.go b/commands/deploy.go index 82127adf4c7..4f850201ede 100644 --- a/commands/deploy.go +++ b/commands/deploy.go @@ -59,6 +59,8 @@ documentation. return deployer.Deploy(ctx) }, withc: func(cmd *cobra.Command, r *rootCommand) { + // Note that the default values for the non-zero values are set in deploy/deployConfig.go. + // The flag values will only be used if set by the user. cmd.Flags().String("target", "", "target deployment from deployments section in config file; defaults to the first one") cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target") cmd.Flags().Bool("dryRun", false, "dry run") diff --git a/deploy/deployConfig.go b/deploy/deployConfig.go index 3f54651711a..37d10911e39 100644 --- a/deploy/deployConfig.go +++ b/deploy/deployConfig.go @@ -127,11 +127,16 @@ func (m *Matcher) Matches(path string) bool { return m.re.MatchString(path) } +var defaultConfig = DeployConfig{ + Workers: 10, + InvalidateCDN: true, + MaxDeletes: 256, +} + // DecodeConfig creates a config from a given Hugo configuration. func DecodeConfig(cfg config.Provider) (DeployConfig, error) { - var ( - dcfg DeployConfig - ) + + dcfg := defaultConfig if !cfg.IsSet(deploymentConfigKey) { return dcfg, nil diff --git a/testscripts/commands/deploy.txt b/testscripts/commands/deploy.txt index b21bf0b38e7..0afe1fc44ef 100644 --- a/testscripts/commands/deploy.txt +++ b/testscripts/commands/deploy.txt @@ -3,10 +3,10 @@ hugo deploy -h stdout 'Deploy your site to a Cloud provider\.' mkdir mybucket -hugo deploy --target mydeployment +hugo deploy --target mydeployment --invalidateCDN=false grep 'hello' mybucket/index.html replace public/index.html 'hello' 'changed' -hugo deploy --target mydeployment --invalidateCDN --dryRun +hugo deploy --target mydeployment --dryRun stdout 'Would upload: index.html' stdout 'Would invalidate CloudFront CDN with ID foobar' -- hugo.toml --