From d373ab365c7e32b9eb1e4741270b3c4cd6b8537c Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 1 Jan 2025 14:04:06 +0800 Subject: [PATCH 1/7] Update config.go --- pkg/config/config.go | 77 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 5c7fc0946..93bd1b593 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -492,6 +492,49 @@ func (c *config) Load(path string, fsys fs.FS) error { if version, err := fs.ReadFile(fsys, builder.PgmetaVersionPath); err == nil && len(version) > 0 { c.Studio.PgmetaImage = replaceImageTag(pgmetaImage, string(version)) } + if err := c.baseConfig.resolve(builder, fsys); err != nil { + return err + } + if err := c.baseConfig.Validate(fsys); err != nil { + return err + } + idToName := map[string]string{} + c.Remotes = make(map[string]baseConfig, len(c.Overrides)) + for name, remote := range c.Overrides { + base := c.baseConfig.Clone() + // On remotes branches set seed as disabled by default + base.Db.Seed.Enabled = false + // Encode a toml file with only config overrides + var buf bytes.Buffer + if err := toml.NewEncoder(&buf).Encode(remote); err != nil { + return errors.Errorf("failed to encode map to TOML: %w", err) + } + // Decode overrides using base config as defaults + if metadata, err := toml.NewDecoder(&buf).Decode(&base); err != nil { + return errors.Errorf("failed to decode remote config: %w", err) + } else if undecoded := metadata.Undecoded(); len(undecoded) > 0 { + fmt.Fprintf(os.Stderr, "WARN: unknown config fields: %+v\n", undecoded) + } + // Cross validate remote project id + if base.ProjectId == c.baseConfig.ProjectId { + fmt.Fprintf(os.Stderr, "WARN: project_id is missing for [remotes.%s]\n", name) + } else if other, exists := idToName[base.ProjectId]; exists { + return errors.Errorf("duplicate project_id for [remotes.%s] and [remotes.%s]", other, name) + } else { + idToName[base.ProjectId] = name + } + if err := c.baseConfig.resolve(builder, fsys); err != nil { + return err + } + if err := base.Validate(fsys); err != nil { + return errors.Errorf("invalid config for [remotes.%s]: %w", name, err) + } + c.Remotes[name] = base + } + return nil +} + +func (c *baseConfig) resolve(builder PathBuilder, fsys fs.FS) error { // Update content paths for name, tmpl := range c.Auth.Email.Template { // FIXME: only email template is relative to repo directory @@ -537,40 +580,6 @@ func (c *config) Load(path string, fsys fs.FS) error { if err := c.Db.Seed.loadSeedPaths(builder.SupabaseDirPath, fsys); err != nil { return err } - if err := c.baseConfig.Validate(fsys); err != nil { - return err - } - idToName := map[string]string{} - c.Remotes = make(map[string]baseConfig, len(c.Overrides)) - for name, remote := range c.Overrides { - base := c.baseConfig.Clone() - // On remotes branches set seed as disabled by default - base.Db.Seed.Enabled = false - // Encode a toml file with only config overrides - var buf bytes.Buffer - if err := toml.NewEncoder(&buf).Encode(remote); err != nil { - return errors.Errorf("failed to encode map to TOML: %w", err) - } - // Decode overrides using base config as defaults - if metadata, err := toml.NewDecoder(&buf).Decode(&base); err != nil { - return errors.Errorf("failed to decode remote config: %w", err) - } else if undecoded := metadata.Undecoded(); len(undecoded) > 0 { - fmt.Fprintf(os.Stderr, "WARN: unknown config fields: %+v\n", undecoded) - } - // Cross validate remote project id - if base.ProjectId == c.baseConfig.ProjectId { - fmt.Fprintf(os.Stderr, "WARN: project_id is missing for [remotes.%s]\n", name) - } else if other, exists := idToName[base.ProjectId]; exists { - return errors.Errorf("duplicate project_id for [remotes.%s] and [remotes.%s]", other, name) - } else { - idToName[base.ProjectId] = name - } - if err := base.Validate(fsys); err != nil { - return errors.Errorf("invalid config for [remotes.%s]: %w", name, err) - } - c.Remotes[name] = base - } - return nil } func (c *baseConfig) Validate(fsys fs.FS) error { From 4a3d5b457ef833d92a0e74c62ceae42c9ac10911 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 1 Jan 2025 14:05:19 +0800 Subject: [PATCH 2/7] Update config.go --- pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 93bd1b593..5823d78a1 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -534,7 +534,7 @@ func (c *config) Load(path string, fsys fs.FS) error { return nil } -func (c *baseConfig) resolve(builder PathBuilder, fsys fs.FS) error { +func (c *baseConfig) resolve(builder pathBuilder, fsys fs.FS) error { // Update content paths for name, tmpl := range c.Auth.Email.Template { // FIXME: only email template is relative to repo directory From 4b01723985fac3b73b87e96dc697ea77f3bf6c82 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 1 Jan 2025 14:17:24 +0800 Subject: [PATCH 3/7] Update config.go --- pkg/config/config.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 5823d78a1..35b24adc5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -577,9 +577,7 @@ func (c *baseConfig) resolve(builder pathBuilder, fsys fs.FS) error { } c.Functions[slug] = function } - if err := c.Db.Seed.loadSeedPaths(builder.SupabaseDirPath, fsys); err != nil { - return err - } + return c.Db.Seed.loadSeedPaths(builder.SupabaseDirPath, fsys) } func (c *baseConfig) Validate(fsys fs.FS) error { From fe598c3d104088fa9870e3c08ff55d69ada7f627 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 1 Jan 2025 14:36:22 +0800 Subject: [PATCH 4/7] Update config.go --- pkg/config/config.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 35b24adc5..e2389bf3f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -492,12 +492,7 @@ func (c *config) Load(path string, fsys fs.FS) error { if version, err := fs.ReadFile(fsys, builder.PgmetaVersionPath); err == nil && len(version) > 0 { c.Studio.PgmetaImage = replaceImageTag(pgmetaImage, string(version)) } - if err := c.baseConfig.resolve(builder, fsys); err != nil { - return err - } - if err := c.baseConfig.Validate(fsys); err != nil { - return err - } + // Resolve and validate remote config idToName := map[string]string{} c.Remotes = make(map[string]baseConfig, len(c.Overrides)) for name, remote := range c.Overrides { @@ -531,7 +526,10 @@ func (c *config) Load(path string, fsys fs.FS) error { } c.Remotes[name] = base } - return nil + if err := c.baseConfig.resolve(builder, fsys); err != nil { + return err + } + return c.baseConfig.Validate(fsys) } func (c *baseConfig) resolve(builder pathBuilder, fsys fs.FS) error { From e99319cdf94726779024f4668df1ac3617e696af Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 1 Jan 2025 14:37:18 +0800 Subject: [PATCH 5/7] Update config.go --- pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index e2389bf3f..47902639c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -518,7 +518,7 @@ func (c *config) Load(path string, fsys fs.FS) error { } else { idToName[base.ProjectId] = name } - if err := c.baseConfig.resolve(builder, fsys); err != nil { + if err := base.resolve(builder, fsys); err != nil { return err } if err := base.Validate(fsys); err != nil { From d8edfdd3436bdc87f424c7a61063c50921c93880 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 1 Jan 2025 18:05:35 +0800 Subject: [PATCH 6/7] Update config.go --- pkg/config/config.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 47902639c..848da5a2e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -492,7 +492,7 @@ func (c *config) Load(path string, fsys fs.FS) error { if version, err := fs.ReadFile(fsys, builder.PgmetaVersionPath); err == nil && len(version) > 0 { c.Studio.PgmetaImage = replaceImageTag(pgmetaImage, string(version)) } - // Resolve and validate remote config + // Resolve remote config, then base config idToName := map[string]string{} c.Remotes = make(map[string]baseConfig, len(c.Overrides)) for name, remote := range c.Overrides { @@ -521,15 +521,21 @@ func (c *config) Load(path string, fsys fs.FS) error { if err := base.resolve(builder, fsys); err != nil { return err } - if err := base.Validate(fsys); err != nil { - return errors.Errorf("invalid config for [remotes.%s]: %w", name, err) - } c.Remotes[name] = base } if err := c.baseConfig.resolve(builder, fsys); err != nil { return err } - return c.baseConfig.Validate(fsys) + // Validate base config, then remote config + if err := c.baseConfig.Validate(fsys); err != nil { + return err + } + for _, base := range c.Remotes { + if err := base.Validate(fsys); err != nil { + return errors.Errorf("invalid config for [remotes.%s]: %w", name, err) + } + } + return nil } func (c *baseConfig) resolve(builder pathBuilder, fsys fs.FS) error { From 6277f28721cbfdaa26e165b186daeeba40eb3eb0 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 1 Jan 2025 18:17:25 +0800 Subject: [PATCH 7/7] Update config.go --- pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 848da5a2e..6903b6b24 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -530,7 +530,7 @@ func (c *config) Load(path string, fsys fs.FS) error { if err := c.baseConfig.Validate(fsys); err != nil { return err } - for _, base := range c.Remotes { + for name, base := range c.Remotes { if err := base.Validate(fsys); err != nil { return errors.Errorf("invalid config for [remotes.%s]: %w", name, err) }