From b0537879b3fb18d74913f4e176e25f9af0213b4d Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 13:59:49 -0800 Subject: [PATCH 01/14] services diff gha --- .../teamcity-services-diff-check.yml | 47 +++++++++++ .../.teamcity/components/inputs/diff_check.go | 82 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 .github/workflows/teamcity-services-diff-check.yml create mode 100644 mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml new file mode 100644 index 000000000000..ad4eb032dbdd --- /dev/null +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -0,0 +1,47 @@ +name: TeamCity Services Diff Check +permissions: read-all + +on: + workflow_dispatch: + pull_request: + paths: + - '.github/workflows/teamcity-services-diff-check.yml' + - 'mmv1/third_party/terraform/!.teamcity' +jobs: + terraform-provider-google: + uses: ./.github/workflows/build-downstream.yml + with: + repo: 'terraform-provider-google' + + teamcity-services-diff-check-ga: + runs-on: ubuntu-22.04 + steps: + - name: Checkout Repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '^1.20.1' + + - 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 mmv1/third_party/terraform/.teamcity/components/inputs + go run diff_check.go \ No newline at end of file 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..987b8763a579 --- /dev/null +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go @@ -0,0 +1,82 @@ +// 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() + fmt.Println(stdout) + 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") + } +} From 15b29ce705053b4a32d87efdaa20ddb28150ffbc Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 14:30:08 -0800 Subject: [PATCH 02/14] add needs --- .github/workflows/teamcity-services-diff-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index ad4eb032dbdd..c62de51daecc 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -14,6 +14,7 @@ jobs: repo: 'terraform-provider-google' teamcity-services-diff-check-ga: + needs: terraform-provider-google runs-on: ubuntu-22.04 steps: - name: Checkout Repository From bf4d864c3b2fa2969f6e43f93633dcda99c89378 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 14:41:08 -0800 Subject: [PATCH 03/14] use setup-go@v3 --- .github/workflows/teamcity-services-diff-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index c62de51daecc..0570384bab13 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -23,9 +23,9 @@ jobs: fetch-depth: 0 - name: Setup Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v3 with: - go-version: '^1.20.1' + go-version: '^1.20' - name: Cache Go modules and build cache uses: actions/cache@v3 From 1b02395503288d8eed1d7f063d195f12260a45f0 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 15:16:42 -0800 Subject: [PATCH 04/14] add artifacts --- .github/workflows/teamcity-services-diff-check.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index 0570384bab13..317730b963a3 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -22,6 +22,17 @@ jobs: with: fetch-depth: 0 + - 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: From 2e46cd832d6b0647531b3bd8242e6480ab332eab Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 15:27:29 -0800 Subject: [PATCH 05/14] remove checkout --- .github/workflows/teamcity-services-diff-check.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index 317730b963a3..2a5eca429bda 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -17,11 +17,6 @@ jobs: needs: terraform-provider-google runs-on: ubuntu-22.04 steps: - - name: Checkout Repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - fetch-depth: 0 - - name: Download built artifacts uses: actions/download-artifact@v2 with: From 39f413d3144d1c56b99a9cb7fef23e9bf622de2c Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 16:05:13 -0800 Subject: [PATCH 06/14] update directory --- .github/workflows/teamcity-services-diff-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index 2a5eca429bda..a0a1cfb16082 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -50,5 +50,5 @@ jobs: - name: Diff Check run: | - cd mmv1/third_party/terraform/.teamcity/components/inputs + cd .teamcity/components/inputs go run diff_check.go \ No newline at end of file From 4f4fd37bdf9d9d2bb454a571842da751be4064b5 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 16:34:18 -0800 Subject: [PATCH 07/14] update common-copy.yaml --- mmv1/provider/terraform/common~copy.yaml | 4 ++++ .../terraform/.teamcity/components/inputs/diff_check.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/mmv1/provider/terraform/common~copy.yaml b/mmv1/provider/terraform/common~copy.yaml index 1409c612a3f6..7c93312a77c6 100644 --- a/mmv1/provider/terraform/common~copy.yaml +++ b/mmv1/provider/terraform/common~copy.yaml @@ -145,6 +145,10 @@ Dir["third_party/terraform/.teamcity/**/*.kt"].each do |file_path| fname = file_path.delete_prefix("third_party/terraform/") -%> +<% + Dir["third_party/terraform/.teamcity/**/*.go"].each do |file_path| + fname = file_path.delete_prefix("third_party/terraform/") +-%> '<%= fname -%>': '<%= file_path -%>' <% end -%> <% diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go index 987b8763a579..c4715d126f60 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go @@ -1,3 +1,8 @@ +/* + * 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 From ae84cde7a97b822ff0410a9f278e8f2d553706a7 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 16:39:33 -0800 Subject: [PATCH 08/14] update common-copy.yaml --- mmv1/provider/terraform/common~copy.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mmv1/provider/terraform/common~copy.yaml b/mmv1/provider/terraform/common~copy.yaml index 7c93312a77c6..6b7d551d2e2e 100644 --- a/mmv1/provider/terraform/common~copy.yaml +++ b/mmv1/provider/terraform/common~copy.yaml @@ -145,6 +145,8 @@ Dir["third_party/terraform/.teamcity/**/*.kt"].each do |file_path| fname = file_path.delete_prefix("third_party/terraform/") -%> +'<%= fname -%>': '<%= file_path -%>' +<% end -%> <% Dir["third_party/terraform/.teamcity/**/*.go"].each do |file_path| fname = file_path.delete_prefix("third_party/terraform/") From 4cbb81350ca916de4939884f3f719f4e0a05bfbd Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 16:47:26 -0800 Subject: [PATCH 09/14] remove data print --- .../terraform/.teamcity/components/inputs/diff_check.go | 1 - 1 file changed, 1 deletion(-) diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go index c4715d126f60..54d3ebba6bc4 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go @@ -20,7 +20,6 @@ import ( func main() { cmd := exec.Command("go", "list", "../../../google/services/...") stdout, err := cmd.Output() - fmt.Println(stdout) if err != nil { fmt.Println(err.Error()) return From e3114e8bb328be328d7bcaa08e6a7fb7f073140c Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 16:50:25 -0800 Subject: [PATCH 10/14] add pull-request check on teamcitydiff --- .github/workflows/teamcity-services-diff-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index a0a1cfb16082..80301137c74f 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -4,6 +4,7 @@ permissions: read-all on: workflow_dispatch: pull_request: + types: [opened, edited] paths: - '.github/workflows/teamcity-services-diff-check.yml' - 'mmv1/third_party/terraform/!.teamcity' From 205b5507d88ff86a35dde8710a02a9ac08aaf3c3 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 17:00:17 -0800 Subject: [PATCH 11/14] update paths in GHA --- .github/workflows/teamcity-services-diff-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index 80301137c74f..a76ad51306a6 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -7,7 +7,7 @@ on: types: [opened, edited] paths: - '.github/workflows/teamcity-services-diff-check.yml' - - 'mmv1/third_party/terraform/!.teamcity' + - 'mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt' jobs: terraform-provider-google: uses: ./.github/workflows/build-downstream.yml From 3c16df3e1a4308a7327d0ca767fe95290935a626 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 18:07:53 -0800 Subject: [PATCH 12/14] add exit code in diff_check --- .../terraform/.teamcity/components/inputs/diff_check.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go index 54d3ebba6bc4..8e6608e7664f 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go @@ -78,9 +78,8 @@ func main() { teamcityServices = pattern.Expand(teamcityServices, template, bs, submatches) } - if bytes.Equal(googleServices, teamcityServices) { - fmt.Println("No Changes!") - } else { - fmt.Println("Diff") + if !bytes.Equal(googleServices, teamcityServices) { + fmt.Fprintf(os.Stderr, "error: diff in services_ga.kt") + os.Exit(1) } } From b1cd675fe5c325f16792a670404b5a3052a3c0ba Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 18:18:02 -0800 Subject: [PATCH 13/14] update exit output --- .../terraform/.teamcity/components/inputs/diff_check.go | 1 - 1 file changed, 1 deletion(-) diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go index 8e6608e7664f..28da2c6c20b2 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go @@ -80,6 +80,5 @@ func main() { if !bytes.Equal(googleServices, teamcityServices) { fmt.Fprintf(os.Stderr, "error: diff in services_ga.kt") - os.Exit(1) } } From ff06b765ccce5f2907dc5f7de484973186fd1dd4 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 15 Feb 2024 18:19:07 -0800 Subject: [PATCH 14/14] update services --- .../terraform/.teamcity/components/inputs/services_ga.kt | 5 +++++ 1 file changed, 5 insertions(+) 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",