Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Generic provider template #1140

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion provider-ci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ format:
# files for other bridged provider repositories should be ephemeral.
.PHONY: test-providers test-provider/%

test-providers: test-provider/aws test-provider/docker test-provider/cloudflare test-provider/acme
test-providers: test-provider/aws test-provider/docker test-provider/cloudflare test-provider/acme test-provider/eks

# 1. Delete all files except the .ci-mgmt.yaml file and run the provider-ci generate command.
# 2. Copy the generated provider repository to a temporary git repo and run actionlint on it.
Expand Down
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