Skip to content

Commit 0257eb5

Browse files
committed
Avoid impporting deploy from config when nodeploy tag is set
Test: ``` go list -tags nodeploy ./... | grep deploy ``` Fixes gohugoio#12009
1 parent a65622a commit 0257eb5

File tree

8 files changed

+65
-60
lines changed

8 files changed

+65
-60
lines changed

commands/deploy.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ package commands
3232
import (
3333
"context"
3434

35-
"github.com/bep/simplecobra"
3635
"github.com/gohugoio/hugo/deploy"
36+
"github.com/gohugoio/hugo/deploy/deployconfig"
37+
38+
"github.com/bep/simplecobra"
3739
"github.com/spf13/cobra"
3840
)
3941

@@ -62,9 +64,9 @@ documentation.
6264
cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
6365
cmd.Flags().Bool("dryRun", false, "dry run")
6466
cmd.Flags().Bool("force", false, "force upload of all files")
65-
cmd.Flags().Bool("invalidateCDN", deploy.DefaultConfig.InvalidateCDN, "invalidate the CDN cache listed in the deployment target")
66-
cmd.Flags().Int("maxDeletes", deploy.DefaultConfig.MaxDeletes, "maximum # of files to delete, or -1 to disable")
67-
cmd.Flags().Int("workers", deploy.DefaultConfig.Workers, "number of workers to transfer files. defaults to 10")
67+
cmd.Flags().Bool("invalidateCDN", deployconfig.DefaultConfig.InvalidateCDN, "invalidate the CDN cache listed in the deployment target")
68+
cmd.Flags().Int("maxDeletes", deployconfig.DefaultConfig.MaxDeletes, "maximum # of files to delete, or -1 to disable")
69+
cmd.Flags().Int("workers", deployconfig.DefaultConfig.Workers, "number of workers to transfer files. defaults to 10")
6870
},
6971
}
7072
}

config/allconfig/allconfig.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"github.com/gohugoio/hugo/config/privacy"
3838
"github.com/gohugoio/hugo/config/security"
3939
"github.com/gohugoio/hugo/config/services"
40-
"github.com/gohugoio/hugo/deploy"
40+
"github.com/gohugoio/hugo/deploy/deployconfig"
4141
"github.com/gohugoio/hugo/helpers"
4242
"github.com/gohugoio/hugo/langs"
4343
"github.com/gohugoio/hugo/markup/markup_config"
@@ -141,8 +141,8 @@ type Config struct {
141141
// <docsmeta>{"refs": ["config:languages:menus"] }</docsmeta>
142142
Menus *config.ConfigNamespace[map[string]navigation.MenuConfig, navigation.Menus] `mapstructure:"-"`
143143

144-
// The deployment configuration section contains for hugo deploy.
145-
Deployment deploy.DeployConfig `mapstructure:"-"`
144+
// The deployment configuration section contains for hugo deployconfig.
145+
Deployment deployconfig.DeployConfig `mapstructure:"-"`
146146

147147
// Module configuration.
148148
Module modules.Config `mapstructure:"-"`

config/allconfig/alldecoders.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/gohugoio/hugo/config/privacy"
2626
"github.com/gohugoio/hugo/config/security"
2727
"github.com/gohugoio/hugo/config/services"
28-
"github.com/gohugoio/hugo/deploy"
28+
"github.com/gohugoio/hugo/deploy/deployconfig"
2929
"github.com/gohugoio/hugo/langs"
3030
"github.com/gohugoio/hugo/markup/markup_config"
3131
"github.com/gohugoio/hugo/media"
@@ -333,7 +333,7 @@ var allDecoderSetups = map[string]decodeWeight{
333333
key: "deployment",
334334
decode: func(d decodeWeight, p decodeConfig) error {
335335
var err error
336-
p.c.Deployment, err = deploy.DecodeConfig(p.p)
336+
p.c.Deployment, err = deployconfig.DecodeConfig(p.p)
337337
return err
338338
},
339339
},

deploy/cloudfront.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/aws/aws-sdk-go-v2/aws"
2525
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
2626
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
27+
"github.com/gohugoio/hugo/deploy/deployconfig"
2728
gcaws "gocloud.dev/aws"
2829
)
2930

@@ -38,7 +39,7 @@ var v2ConfigValidParams = map[string]bool{
3839

3940
// InvalidateCloudFront invalidates the CloudFront cache for distributionID.
4041
// Uses AWS credentials config from the bucket URL.
41-
func InvalidateCloudFront(ctx context.Context, target *Target) error {
42+
func InvalidateCloudFront(ctx context.Context, target *deployconfig.Target) error {
4243
u, err := url.Parse(target.URL)
4344
if err != nil {
4445
return err

deploy/deploy.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/gobwas/glob"
3939
"github.com/gohugoio/hugo/common/loggers"
4040
"github.com/gohugoio/hugo/config"
41+
"github.com/gohugoio/hugo/deploy/deployconfig"
4142
"github.com/gohugoio/hugo/media"
4243
"github.com/spf13/afero"
4344
"golang.org/x/text/unicode/norm"
@@ -57,10 +58,10 @@ type Deployer struct {
5758
mediaTypes media.Types // Hugo's MediaType to guess ContentType
5859
quiet bool // true reduces STDOUT // TODO(bep) remove, this is a global feature.
5960

60-
cfg DeployConfig
61+
cfg deployconfig.DeployConfig
6162
logger loggers.Logger
6263

63-
target *Target // the target to deploy to
64+
target *deployconfig.Target // the target to deploy to
6465

6566
// For tests...
6667
summary deploySummary // summary of latest Deploy results
@@ -74,7 +75,7 @@ const metaMD5Hash = "md5chksum" // the meta key to store md5hash in
7475

7576
// New constructs a new *Deployer.
7677
func New(cfg config.AllProvider, logger loggers.Logger, localFs afero.Fs) (*Deployer, error) {
77-
dcfg := cfg.GetConfigSection(deploymentConfigKey).(DeployConfig)
78+
dcfg := cfg.GetConfigSection(deployconfig.DeploymentConfigKey).(deployconfig.DeployConfig)
7879
targetName := dcfg.Target
7980

8081
if len(dcfg.Targets) == 0 {
@@ -83,7 +84,7 @@ func New(cfg config.AllProvider, logger loggers.Logger, localFs afero.Fs) (*Depl
8384
mediaTypes := cfg.GetConfigSection("mediaTypes").(media.Types)
8485

8586
// Find the target to deploy to.
86-
var tgt *Target
87+
var tgt *deployconfig.Target
8788
if targetName == "" {
8889
// Default to the first target.
8990
tgt = dcfg.Targets[0]
@@ -133,7 +134,7 @@ func (d *Deployer) Deploy(ctx context.Context) error {
133134
// Load local files from the source directory.
134135
var include, exclude glob.Glob
135136
if d.target != nil {
136-
include, exclude = d.target.includeGlob, d.target.excludeGlob
137+
include, exclude = d.target.IncludeGlob, d.target.ExcludeGlob
137138
}
138139
local, err := d.walkLocal(d.localFs, d.cfg.Matchers, include, exclude, d.mediaTypes)
139140
if err != nil {
@@ -178,7 +179,7 @@ func (d *Deployer) Deploy(ctx context.Context) error {
178179

179180
// Order the uploads. They are organized in groups; all uploads in a group
180181
// must be complete before moving on to the next group.
181-
uploadGroups := applyOrdering(d.cfg.ordering, uploads)
182+
uploadGroups := applyOrdering(d.cfg.Ordering, uploads)
182183

183184
nParallel := d.cfg.Workers
184185
var errs []error
@@ -343,14 +344,14 @@ type localFile struct {
343344
UploadSize int64
344345

345346
fs afero.Fs
346-
matcher *Matcher
347+
matcher *deployconfig.Matcher
347348
md5 []byte // cache
348349
gzipped bytes.Buffer // cached of gzipped contents if gzipping
349350
mediaTypes media.Types
350351
}
351352

352353
// newLocalFile initializes a *localFile.
353-
func newLocalFile(fs afero.Fs, nativePath, slashpath string, m *Matcher, mt media.Types) (*localFile, error) {
354+
func newLocalFile(fs afero.Fs, nativePath, slashpath string, m *deployconfig.Matcher, mt media.Types) (*localFile, error) {
354355
f, err := fs.Open(nativePath)
355356
if err != nil {
356357
return nil, err
@@ -482,7 +483,7 @@ func knownHiddenDirectory(name string) bool {
482483

483484
// walkLocal walks the source directory and returns a flat list of files,
484485
// using localFile.SlashPath as the map keys.
485-
func (d *Deployer) walkLocal(fs afero.Fs, matchers []*Matcher, include, exclude glob.Glob, mediaTypes media.Types) (map[string]*localFile, error) {
486+
func (d *Deployer) walkLocal(fs afero.Fs, matchers []*deployconfig.Matcher, include, exclude glob.Glob, mediaTypes media.Types) (map[string]*localFile, error) {
486487
retval := map[string]*localFile{}
487488
err := afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
488489
if err != nil {
@@ -521,7 +522,7 @@ func (d *Deployer) walkLocal(fs afero.Fs, matchers []*Matcher, include, exclude
521522
}
522523

523524
// Find the first matching matcher (if any).
524-
var m *Matcher
525+
var m *deployconfig.Matcher
525526
for _, cur := range matchers {
526527
if cur.Matches(slashpath) {
527528
m = cur

deploy/deploy_test.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"testing"
3232

3333
"github.com/gohugoio/hugo/common/loggers"
34+
"github.com/gohugoio/hugo/deploy/deployconfig"
3435
"github.com/gohugoio/hugo/hugofs"
3536
"github.com/gohugoio/hugo/media"
3637
"github.com/google/go-cmp/cmp"
@@ -110,7 +111,7 @@ func TestFindDiffs(t *testing.T) {
110111
{
111112
Description: "local == remote with route.Force true -> diffs",
112113
Local: []*localFile{
113-
{NativePath: "aaa", SlashPath: "aaa", UploadSize: 1, matcher: &Matcher{Force: true}, md5: hash1},
114+
{NativePath: "aaa", SlashPath: "aaa", UploadSize: 1, matcher: &deployconfig.Matcher{Force: true}, md5: hash1},
114115
makeLocal("bbb", 2, hash1),
115116
},
116117
Remote: []*blob.ListObject{
@@ -293,7 +294,7 @@ func TestLocalFile(t *testing.T) {
293294
tests := []struct {
294295
Description string
295296
Path string
296-
Matcher *Matcher
297+
Matcher *deployconfig.Matcher
297298
MediaTypesConfig map[string]any
298299
WantContent []byte
299300
WantSize int64
@@ -319,7 +320,7 @@ func TestLocalFile(t *testing.T) {
319320
{
320321
Description: "CacheControl from matcher",
321322
Path: "foo.txt",
322-
Matcher: &Matcher{CacheControl: "max-age=630720000"},
323+
Matcher: &deployconfig.Matcher{CacheControl: "max-age=630720000"},
323324
WantContent: contentBytes,
324325
WantSize: contentLen,
325326
WantMD5: contentMD5[:],
@@ -328,7 +329,7 @@ func TestLocalFile(t *testing.T) {
328329
{
329330
Description: "ContentEncoding from matcher",
330331
Path: "foo.txt",
331-
Matcher: &Matcher{ContentEncoding: "foobar"},
332+
Matcher: &deployconfig.Matcher{ContentEncoding: "foobar"},
332333
WantContent: contentBytes,
333334
WantSize: contentLen,
334335
WantMD5: contentMD5[:],
@@ -337,7 +338,7 @@ func TestLocalFile(t *testing.T) {
337338
{
338339
Description: "ContentType from matcher",
339340
Path: "foo.txt",
340-
Matcher: &Matcher{ContentType: "foo/bar"},
341+
Matcher: &deployconfig.Matcher{ContentType: "foo/bar"},
341342
WantContent: contentBytes,
342343
WantSize: contentLen,
343344
WantMD5: contentMD5[:],
@@ -346,7 +347,7 @@ func TestLocalFile(t *testing.T) {
346347
{
347348
Description: "gzipped content",
348349
Path: "foo.txt",
349-
Matcher: &Matcher{Gzip: true},
350+
Matcher: &deployconfig.Matcher{Gzip: true},
350351
WantContent: gzBytes,
351352
WantSize: gzLen,
352353
WantMD5: gzMD5[:],
@@ -560,7 +561,7 @@ func TestEndToEndSync(t *testing.T) {
560561
localFs: test.fs,
561562
bucket: test.bucket,
562563
mediaTypes: media.DefaultTypes,
563-
cfg: DeployConfig{MaxDeletes: -1},
564+
cfg: deployconfig.DeployConfig{MaxDeletes: -1},
564565
}
565566

566567
// Initial deployment should sync remote with local.
@@ -643,7 +644,7 @@ func TestMaxDeletes(t *testing.T) {
643644
localFs: test.fs,
644645
bucket: test.bucket,
645646
mediaTypes: media.DefaultTypes,
646-
cfg: DeployConfig{MaxDeletes: -1},
647+
cfg: deployconfig.DeployConfig{MaxDeletes: -1},
647648
}
648649

649650
// Sync remote with local.
@@ -764,16 +765,16 @@ func TestIncludeExclude(t *testing.T) {
764765
if err != nil {
765766
t.Fatal(err)
766767
}
767-
tgt := &Target{
768+
tgt := &deployconfig.Target{
768769
Include: test.Include,
769770
Exclude: test.Exclude,
770771
}
771-
if err := tgt.parseIncludeExclude(); err != nil {
772+
if err := tgt.ParseIncludeExclude(); err != nil {
772773
t.Error(err)
773774
}
774775
deployer := &Deployer{
775776
localFs: fsTest.fs,
776-
cfg: DeployConfig{MaxDeletes: -1}, bucket: fsTest.bucket,
777+
cfg: deployconfig.DeployConfig{MaxDeletes: -1}, bucket: fsTest.bucket,
777778
target: tgt,
778779
mediaTypes: media.DefaultTypes,
779780
}
@@ -830,7 +831,7 @@ func TestIncludeExcludeRemoteDelete(t *testing.T) {
830831
}
831832
deployer := &Deployer{
832833
localFs: fsTest.fs,
833-
cfg: DeployConfig{MaxDeletes: -1}, bucket: fsTest.bucket,
834+
cfg: deployconfig.DeployConfig{MaxDeletes: -1}, bucket: fsTest.bucket,
834835
mediaTypes: media.DefaultTypes,
835836
}
836837

@@ -848,11 +849,11 @@ func TestIncludeExcludeRemoteDelete(t *testing.T) {
848849
}
849850

850851
// Second sync
851-
tgt := &Target{
852+
tgt := &deployconfig.Target{
852853
Include: test.Include,
853854
Exclude: test.Exclude,
854855
}
855-
if err := tgt.parseIncludeExclude(); err != nil {
856+
if err := tgt.ParseIncludeExclude(); err != nil {
856857
t.Error(err)
857858
}
858859
deployer.target = tgt
@@ -882,7 +883,7 @@ func TestCompression(t *testing.T) {
882883
deployer := &Deployer{
883884
localFs: test.fs,
884885
bucket: test.bucket,
885-
cfg: DeployConfig{MaxDeletes: -1, Matchers: []*Matcher{{Pattern: ".*", Gzip: true, re: regexp.MustCompile(".*")}}},
886+
cfg: deployconfig.DeployConfig{MaxDeletes: -1, Matchers: []*deployconfig.Matcher{{Pattern: ".*", Gzip: true, Re: regexp.MustCompile(".*")}}},
886887
mediaTypes: media.DefaultTypes,
887888
}
888889

@@ -937,7 +938,7 @@ func TestMatching(t *testing.T) {
937938
deployer := &Deployer{
938939
localFs: test.fs,
939940
bucket: test.bucket,
940-
cfg: DeployConfig{MaxDeletes: -1, Matchers: []*Matcher{{Pattern: "^subdir/aaa$", Force: true, re: regexp.MustCompile("^subdir/aaa$")}}},
941+
cfg: deployconfig.DeployConfig{MaxDeletes: -1, Matchers: []*deployconfig.Matcher{{Pattern: "^subdir/aaa$", Force: true, Re: regexp.MustCompile("^subdir/aaa$")}}},
941942
mediaTypes: media.DefaultTypes,
942943
}
943944

@@ -962,7 +963,7 @@ func TestMatching(t *testing.T) {
962963
}
963964

964965
// Repeat with a matcher that should now match 3 files.
965-
deployer.cfg.Matchers = []*Matcher{{Pattern: "aaa", Force: true, re: regexp.MustCompile("aaa")}}
966+
deployer.cfg.Matchers = []*deployconfig.Matcher{{Pattern: "aaa", Force: true, Re: regexp.MustCompile("aaa")}}
966967
if err := deployer.Deploy(ctx); err != nil {
967968
t.Errorf("no-op deploy with triple force matcher: %v", err)
968969
}

0 commit comments

Comments
 (0)