Skip to content

Commit

Permalink
Typed provider configuration (#1126)
Browse files Browse the repository at this point in the history
This adds strong typing around our CI configuration options.

Currently our config is just a bag of values, which has led to repos
specifying options which have no effect on CI (e.g. `parallel:`,
`makeTemplate:` etc.).

This adds types for all of our available options and will fail if
`ci-mgmt.yml` specifies an unrecognized option. For backwards
compatibility we continue to allow existing no-op params in order to not
break existing providers.
  • Loading branch information
blampe authored Nov 15, 2024
1 parent 6de05d1 commit a599655
Show file tree
Hide file tree
Showing 64 changed files with 758 additions and 429 deletions.
2 changes: 1 addition & 1 deletion provider-ci/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/imdario/mergo v0.3.16
github.com/spf13/cobra v1.7.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -15,6 +14,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand Down
25 changes: 9 additions & 16 deletions provider-ci/internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,26 @@ var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate repository files.",
RunE: func(cmd *cobra.Command, args []string) error {
localConfig, err := pkg.LoadLocalConfig(generateArgs.ConfigPath)
if err != nil {
return err
}
// Merge local config with template defaults
mergedConfig, err := localConfig.WithTemplateDefaults()
config, err := pkg.LoadLocalConfig(generateArgs.ConfigPath)
if err != nil {
return err
}

// Template name priority: CLI flag > config file
if generateArgs.TemplateName == "" {
if templateName, ok := mergedConfig["template"].(string); ok {
generateArgs.TemplateName = templateName
if config.Template != "" {
generateArgs.TemplateName = config.Template
}
}

// Name priority: CLI flag > config file ("repository", then "name" field)
if generateArgs.RepositoryName == "" {
if repositoryName, ok := mergedConfig["repository"].(string); ok {
generateArgs.RepositoryName = repositoryName
} else if name, ok := mergedConfig["name"].(string); ok {
generateArgs.RepositoryName = name
if config.Repository != "" {
generateArgs.RepositoryName = config.Repository
} else {
providerName, providerOk := mergedConfig["provider"].(string)
organizationName, organizationOk := mergedConfig["organization"].(string)
if providerOk && organizationOk {
providerName := config.Provider
organizationName := config.Organization
if providerName != "" && organizationName != "" {
generateArgs.RepositoryName = fmt.Sprintf("%s/pulumi-%s", organizationName, providerName)
}
}
Expand All @@ -61,7 +54,7 @@ var generateCmd = &cobra.Command{
RepositoryName: generateArgs.RepositoryName,
OutDir: generateArgs.OutDir,
TemplateName: generateArgs.TemplateName,
Config: mergedConfig,
Config: config,
})
return err
},
Expand Down
Loading

0 comments on commit a599655

Please sign in to comment.