Skip to content

Commit

Permalink
services diff gha
Browse files Browse the repository at this point in the history
  • Loading branch information
BBBmau committed Feb 15, 2024
1 parent cacc4c8 commit b053787
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/teamcity-services-diff-check.yml
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
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")
}
}

0 comments on commit b053787

Please sign in to comment.