diff --git a/internal/cmd/provider/create_version.go b/internal/cmd/provider/create_version.go index 5306b2c..f4558e3 100644 --- a/internal/cmd/provider/create_version.go +++ b/internal/cmd/provider/create_version.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "slices" "github.com/pkg/errors" "github.com/shurcooL/graphql" @@ -19,7 +20,12 @@ func createVersion() cli.ActionFunc { dir := cliCtx.String(flagGoReleaserDir.Name) providerType := cliCtx.String(flagProviderType.Name) - useRegisterPlatformV2 := cliCtx.Bool(flagUseRegisterPlatformV2.Name) + var useRegisterPlatformV2 bool + if types, err := mutationTypes(cliCtx.Context); err == nil { + useRegisterPlatformV2 = types.hasTerraformProviderVersionRegisterPlatformV2Mutation() + } else { + fmt.Println("Failed to check for presence of terraformProviderVersionRegisterPlatformV2Mutation ", err.Error()) + } fmt.Println("Retrieving release data from ", dir) versionData, err := internal.BuildGoReleaserVersionData(dir) @@ -163,6 +169,33 @@ func registerPlatform(ctx context.Context, dir string, versionID string, artifac return nil } +type mutationTypesQuery struct { + Schema struct { + MutationType struct { + Fields []mutationTypeField + } + } `graphql:"__schema"` +} + +type mutationTypeField struct { + Name string +} + +func (q mutationTypesQuery) hasTerraformProviderVersionRegisterPlatformV2Mutation() bool { + return slices.ContainsFunc(q.Schema.MutationType.Fields, func(field mutationTypeField) bool { + return field.Name == "terraformProviderVersionRegisterPlatformV2" + }) +} + +func mutationTypes(ctx context.Context) (mutationTypesQuery, error) { + query := mutationTypesQuery{} + err := authenticated.Client.Query(ctx, &query, nil) + if err != nil { + return mutationTypesQuery{}, err + } + return query, nil +} + func registerPlatformV2(ctx context.Context, dir string, versionID string, artifact *internal.GoReleaserArtifact) error { var mutation struct { RegisterTerraformProviderVersionPlatform struct { diff --git a/internal/cmd/provider/flags.go b/internal/cmd/provider/flags.go index 45eb885..e50f4a1 100644 --- a/internal/cmd/provider/flags.go +++ b/internal/cmd/provider/flags.go @@ -42,11 +42,6 @@ var flagProviderType = &cli.StringFlag{ Required: true, } -var flagUseRegisterPlatformV2 = &cli.BoolFlag{ - Name: "use-register-platform-v2", - Usage: "Use register platform v2 mutation", -} - var flagProviderVersionProtocols = &cli.StringSliceFlag{ Name: "protocols", Usage: "Terraform plugin protocols supported by the provider", diff --git a/internal/cmd/provider/provider.go b/internal/cmd/provider/provider.go index c2b7397..7302e22 100644 --- a/internal/cmd/provider/provider.go +++ b/internal/cmd/provider/provider.go @@ -54,7 +54,6 @@ func Command() *cli.Command { flagProviderVersionProtocols, flagGoReleaserDir, flagGPGKeyID, - flagUseRegisterPlatformV2, }, Action: createVersion(), Before: authenticated.Ensure,