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

fix: check for register platform v2 mutation #277

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
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
33 changes: 33 additions & 0 deletions internal/cmd/provider/create_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"slices"

"github.com/pkg/errors"
"github.com/shurcooL/graphql"
Expand All @@ -20,6 +21,11 @@ func createVersion() cli.ActionFunc {

providerType := cliCtx.String(flagProviderType.Name)
useRegisterPlatformV2 := cliCtx.Bool(flagUseRegisterPlatformV2.Name)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably we can remove this flag, I think it wasnt released

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote on removing it in this PR

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)
Expand Down Expand Up @@ -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 {
Expand Down
Loading