From 360d411552680d460bb98174e0292b68aa732345 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 4 Aug 2022 07:15:08 +0200 Subject: [PATCH] automation: support for auto-Service and Client registration This also adds a GitHub Action enabling Pull Requests to be opened as required --- .../automation-open-pull-request.yaml | 26 +++++++++++++++++++ .golangci.yml | 2 ++ GNUmakefile | 6 +++++ internal/clients/client.go | 7 +++++ internal/clients/client_gen.go | 14 ++++++++++ internal/provider/services.go | 4 ++- internal/provider/services_gen.go | 9 +++++++ 7 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/automation-open-pull-request.yaml create mode 100644 internal/clients/client_gen.go create mode 100644 internal/provider/services_gen.go diff --git a/.github/workflows/automation-open-pull-request.yaml b/.github/workflows/automation-open-pull-request.yaml new file mode 100644 index 000000000000..3b676178642a --- /dev/null +++ b/.github/workflows/automation-open-pull-request.yaml @@ -0,0 +1,26 @@ +name: Open Pull Request when an `auto-pr` is pushed +on: + push: + branches: + - 'auto-pr/**' + +jobs: + open-pull-request: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v3 + + - name: "open a pull request" + id: open-pr + run: | + # this runs everytime the PR gets pushed too, whilst you can only create a PR a single time + # so we should be smarter, but piping this to /dev/null is a fine workaround for MVP + gh pr create --title "$PR_TITLE" --body "$PR_BODY" -B "$PR_TARGET" > /dev/null + + env: + PR_TITLE: "Auto PR: Regenerating based on (${{ github.sha }})" + PR_BODY: "Regenerating the Terraform Provider based on the latest changes" + PR_TARGET: "main" + GITHUB_TOKEN: ${{ secrets.SERVICE_ACCOUNT_TERRAFORM_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml index 8fc5a65a7b82..06699ad2ad16 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,8 @@ run: modules-download-mode: vendor skip-dirs: - /sdk/ # Excluding sdk folders as these are externally generated + skip-files: + - ".*\\*_gen.go$" issues: max-per-linter: 0 diff --git a/GNUmakefile b/GNUmakefile index d92c31760291..a5a6cf1ed7bf 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -102,6 +102,12 @@ acctests: fmtcheck debugacc: fmtcheck TF_ACC=1 dlv test $(TEST) --headless --listen=:2345 --api-version=2 -- -test.v $(TESTARGS) +prepare: + @echo "==> Preparing the repository (removing all '*_gen.go' files)..." + @find . -iname \*_gen.go -type f -delete + @echo "==> Preparing the repository (removing all '*_gen_test.go' files)..." + @find . -iname \*_gen_test.go -type f -delete + website-lint: @echo "==> Checking documentation for .html.markdown extension present" @if ! find website/docs -type f -not -name "*.html.markdown" -print -exec false {} +; then \ diff --git a/internal/clients/client.go b/internal/clients/client.go index ae90f9cbbd01..cf0e104a218c 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -2,6 +2,7 @@ package clients import ( "context" + "fmt" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/validation" @@ -117,6 +118,8 @@ import ( ) type Client struct { + autoClient + // StopContext is used for propagating control from Terraform Core (e.g. Ctrl/Cmd+C) StopContext context.Context @@ -238,6 +241,10 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error // Disable the Azure SDK for Go's validation since it's unhelpful for our use-case validation.Disabled = true + if err := buildAutoClients(&client.autoClient, o); err != nil { + return fmt.Errorf("building auto-sdk clients: %+v", err) + } + client.Features = o.Features client.StopContext = ctx diff --git a/internal/clients/client_gen.go b/internal/clients/client_gen.go new file mode 100644 index 000000000000..c452e6da7368 --- /dev/null +++ b/internal/clients/client_gen.go @@ -0,0 +1,14 @@ +package clients + +// NOTE: this file is generated - manual changes will be overwritten. + +import ( + "github.com/hashicorp/terraform-provider-azurerm/internal/common" +) + +type autoClient struct { +} + +func buildAutoClients(client *autoClient, o *common.ClientOptions) error { + return nil +} diff --git a/internal/provider/services.go b/internal/provider/services.go index 171ee4cc227e..7da424445896 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -114,7 +114,7 @@ import ( //go:generate go run ../tools/generator-services/main.go -path=../../ func SupportedTypedServices() []sdk.TypedServiceRegistration { - return []sdk.TypedServiceRegistration{ + services := []sdk.TypedServiceRegistration{ aadb2c.Registration{}, apimanagement.Registration{}, appconfiguration.Registration{}, @@ -151,6 +151,8 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration { search.Registration{}, web.Registration{}, } + services = append(services, autoRegisteredTypedServices()...) + return services } func SupportedUntypedServices() []sdk.UntypedServiceRegistration { diff --git a/internal/provider/services_gen.go b/internal/provider/services_gen.go new file mode 100644 index 000000000000..7c7d3f3fd17c --- /dev/null +++ b/internal/provider/services_gen.go @@ -0,0 +1,9 @@ +package provider + +// NOTE: this file is generated - manual changes will be overwritten. + +import "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + +func autoRegisteredTypedServices() []sdk.TypedServiceRegistration { + return []sdk.TypedServiceRegistration{} +}