forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
82 changes: 82 additions & 0 deletions
82
mmv1/third_party/terraform/.teamcity/components/inputs/diff_check.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<service>\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<service>\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") | ||
} | ||
} |