diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml new file mode 100644 index 000000000000..a76ad51306a6 --- /dev/null +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -0,0 +1,55 @@ +name: TeamCity Services Diff Check +permissions: read-all + +on: + workflow_dispatch: + pull_request: + types: [opened, edited] + paths: + - '.github/workflows/teamcity-services-diff-check.yml' + - 'mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt' +jobs: + terraform-provider-google: + uses: ./.github/workflows/build-downstream.yml + with: + repo: 'terraform-provider-google' + + teamcity-services-diff-check-ga: + needs: terraform-provider-google + runs-on: ubuntu-22.04 + steps: + - name: Download built artifacts + uses: actions/download-artifact@v2 + with: + name: artifact-terraform-provider-google + path: artifacts + + - name: Unzip the artifacts and delete the zip + run: | + unzip artifacts/output.zip -d ./ + rm artifacts/output.zip + + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: '^1.20' + + - name: Cache Go modules and build cache + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-test-terraform-provider-google-${{hashFiles('go.sum','google-*/transport/**','google-*/tpgresource/**','google-*/acctest/**','google-*/envvar/**','google-*/sweeper/**','google-*/verify/**') }} + restore-keys: | + ${{ runner.os }}-test-terraform-provider-google-${{ hashFiles('go.sum') }} + ${{ runner.os }}-test-terraform-provider-google- + + - name: Build Provider + run: | + go build + + - name: Diff Check + run: | + cd .teamcity/components/inputs + go run diff_check.go \ No newline at end of file diff --git a/mmv1/provider/terraform/common~copy.yaml b/mmv1/provider/terraform/common~copy.yaml index 1409c612a3f6..6b7d551d2e2e 100644 --- a/mmv1/provider/terraform/common~copy.yaml +++ b/mmv1/provider/terraform/common~copy.yaml @@ -147,6 +147,12 @@ -%> '<%= fname -%>': '<%= file_path -%>' <% end -%> +<% + Dir["third_party/terraform/.teamcity/**/*.go"].each do |file_path| + fname = file_path.delete_prefix("third_party/terraform/") +-%> +'<%= fname -%>': '<%= file_path -%>' +<% end -%> <% Dir["third_party/terraform/.teamcity/**/*.md"].each do |file_path| fname = file_path.delete_prefix("third_party/terraform/") diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go new file mode 100644 index 000000000000..54d3ebba6bc4 --- /dev/null +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go @@ -0,0 +1,86 @@ +/* + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +// This file is controlled by MMv1, any changes made here will be overwritten + +package main + +import ( + "bufio" + "bytes" + "fmt" + "io" + "os" + "os/exec" + "regexp" +) + +func main() { + cmd := exec.Command("go", "list", "../../../google/services/...") + stdout, err := cmd.Output() + if err != nil { + fmt.Println(err.Error()) + return + } + + pattern := regexp.MustCompile(`github\.com\/hashicorp\/terraform-provider-google\/google\/services\/(?P\w+)`) + + // Template to convert "key: value" to "key=value" by + // referencing the values captured by the regex pattern. + template := []byte("$service\n") + + googleServices := []byte{} + + // For each match of the regex in the content. + for _, submatches := range pattern.FindAllSubmatchIndex(stdout, -1) { + // Apply the captured submatches to the template and append the output + // to the result. + googleServices = pattern.Expand(googleServices, template, stdout, submatches) + } + + //////////////////////////////////////////////////////////////////////////////// + + f, err := os.Open("services_ga.kt") + if err != nil { + panic(err) + } + + // Get the file size + stat, err := f.Stat() + if err != nil { + fmt.Println(err) + return + } + + // Read the file into a byte slice + bs := make([]byte, stat.Size()) + _, err = bufio.NewReader(f).Read(bs) + if err != nil && err != io.EOF { + fmt.Println(err) + return + } + + // Regex pattern captures "key: value" pair from the content. + pattern = regexp.MustCompile(`(?m)"(?P\w+)"\sto\s+mapOf`) + + // Template to convert "key: value" to "key=value" by + // referencing the values captured by the regex pattern. + template = []byte("$service\n") + + teamcityServices := []byte{} + + // For each match of the regex in the content. + for _, submatches := range pattern.FindAllSubmatchIndex(bs, -1) { + // Apply the captured submatches to the template and append the output + // to the result. + teamcityServices = pattern.Expand(teamcityServices, template, bs, submatches) + } + + if bytes.Equal(googleServices, teamcityServices) { + fmt.Println("No Changes!") + } else { + fmt.Println("Diff") + } +} diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt index 51f98ed08a05..42f295f13a24 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt @@ -13,6 +13,11 @@ var ServicesListGa = mapOf( "displayName" to "Accessapproval", "path" to "./google/services/accessapproval" ), + "supersql" to mapOf( + "name" to "accessapproval", + "displayName" to "Accessapproval", + "path" to "./google/services/accessapproval" + ), "accesscontextmanager" to mapOf( "name" to "accesscontextmanager", "displayName" to "Accesscontextmanager",