Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service diff teamcity ga and beta #10

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b053787
services diff gha
BBBmau Feb 15, 2024
15b29ce
add needs
BBBmau Feb 15, 2024
bf4d864
use setup-go@v3
BBBmau Feb 15, 2024
1b02395
add artifacts
BBBmau Feb 15, 2024
2e46cd8
remove checkout
BBBmau Feb 15, 2024
39f413d
update directory
BBBmau Feb 16, 2024
4f4fd37
update common-copy.yaml
BBBmau Feb 16, 2024
ae84cde
update common-copy.yaml
BBBmau Feb 16, 2024
4cbb813
remove data print
BBBmau Feb 16, 2024
e3114e8
add pull-request check on teamcitydiff
BBBmau Feb 16, 2024
205b550
update paths in GHA
BBBmau Feb 16, 2024
3c16df3
add exit code in diff_check
BBBmau Feb 16, 2024
b1cd675
update exit output
BBBmau Feb 16, 2024
5971c66
add exit code diff_check.go
BBBmau Feb 16, 2024
38cfdb1
services_beta diff check support
BBBmau Feb 16, 2024
3e0e56b
beta services support args
BBBmau Feb 16, 2024
590b54b
add arg for services kt file
BBBmau Feb 16, 2024
a9e631f
services_ga.kt in gha
BBBmau Feb 16, 2024
25819d8
move diff_check to tools folder
BBBmau Feb 16, 2024
8604188
remove go command
BBBmau Feb 16, 2024
fdcc36e
provide path for artifacts download
BBBmau Feb 16, 2024
96a8d3d
add cd in Build Provider
BBBmau Feb 16, 2024
dcde4c7
update diff_check_beta.yml
BBBmau Feb 16, 2024
71b7997
fix paths
BBBmau Feb 16, 2024
8d1a003
yml typo beta
BBBmau Feb 16, 2024
95ad364
directory testing
BBBmau Feb 16, 2024
af8422e
directory testing
BBBmau Feb 16, 2024
8ef04c9
fix directory issues with commands
BBBmau Feb 17, 2024
d1f73ba
refactor tools/teamcity-diff-check/main.go
BBBmau Feb 17, 2024
8567836
directory check
BBBmau Feb 18, 2024
63c8c08
typo
BBBmau Feb 18, 2024
3ae5129
remove common copy
BBBmau Feb 18, 2024
36ceb3b
generate both providers into one gha
BBBmau Feb 18, 2024
136bd4b
type artifacts name
BBBmau Feb 18, 2024
6177b5c
add -o flag into artifacts download
BBBmau Feb 18, 2024
f461781
use merge multiple artifacts
BBBmau Feb 19, 2024
88c2054
use artifact@v4
BBBmau Feb 19, 2024
4b1d6d8
use mmv1 directory for services file
BBBmau Feb 20, 2024
a977f86
remove .zip
BBBmau Feb 20, 2024
8578505
output missing services from diff
BBBmau Feb 20, 2024
7d7026c
find artifacts folder
BBBmau Feb 20, 2024
4ba11ee
use beta provider as only artifact
BBBmau Feb 20, 2024
94912ce
include google ga and beta in gha
BBBmau Feb 20, 2024
cd2dd3f
artifact name
BBBmau Feb 20, 2024
6f0a087
-o flag in artifacts
BBBmau Feb 20, 2024
c8806a4
output stdout from go list command
BBBmau Feb 20, 2024
0836e95
diff test
BBBmau Feb 20, 2024
04a3fe5
output beta main.go
BBBmau Feb 20, 2024
8b95460
remove err check
BBBmau Feb 20, 2024
00ce67a
remove services print / refactor for final review
BBBmau Feb 20, 2024
1dc7380
service diff
BBBmau Feb 20, 2024
f417f55
output cleanup
BBBmau Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/teamcity-services-diff-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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'
- 'mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt'
jobs:
terraform-provider-google:
uses: ./.github/workflows/build-downstream.yml
with:
repo: 'terraform-provider-google'

terraform-provider-google-beta:
uses: ./.github/workflows/build-downstream.yml
with:
repo: 'terraform-provider-google-beta'

teamcity-services-diff-check:
needs: [terraform-provider-google, terraform-provider-google-beta]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- 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 -o artifacts/output.zip -d ./provider
rm artifacts/output.zip

- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: artifact-terraform-provider-google-beta
path: artifacts

- name: Unzip the artifacts and delete the zip
run: |
unzip -o artifacts/output.zip -d ./provider
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: Diff Check
run: |
cd tools/teamcity-diff-check
go run main.go
go run main.go -provider=google-beta -service_file=services_beta.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ var ServicesListBeta = mapOf(
"displayName" to "Accessapproval",
"path" to "./google-beta/services/accessapproval"
),
"supersql" to mapOf(
"name" to "accessapproval",
"displayName" to "Accessapproval",
"path" to "./google-beta/services/accessapproval"
),
"accesscontextmanager" to mapOf(
"name" to "accesscontextmanager",
"displayName" to "Accesscontextmanager",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
111 changes: 111 additions & 0 deletions tools/teamcity-diff-check/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
/*
* 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"
"flag"
"fmt"
"io"
"os"
"os/exec"
"regexp"
)

var serviceFile = flag.String("service_file", "services_ga.kt", "kotlin service file to be parsed")
var provider = flag.String("provider", "google", "Specify which provider to run diff_check on")

func serviceDifference(gS, tS []string) []string {
g := make(map[string]struct{}, len(gS))
for _, s := range gS {
g[s] = struct{}{}
}

var diff []string
for _, s := range tS {
if _, found := g[s]; !found {
diff = append(diff, s)
}
}

return diff
}

func main() {
flag.Parse()

servicesPath := fmt.Sprintf("../../provider/%s/services/", *provider)
cmd := exec.Command("go", "list", "./...")
cmd.Dir = servicesPath
stdout, err := cmd.Output()
// if err != nil {
// fmt.Println(string(stdout))
// fmt.Println(err.Error())
// return
// }

// Regex pattern captures "services" from `go list ../../provider/{{*provider}}/services/..`
pattern := regexp.MustCompile(`github\.com\/hashicorp\/terraform-provider-(google|google-beta)\/(google|google-beta)\/services\/(?P<service>\w+)`)

template := []byte("$service")
dst := []byte{}

googleServices := []string{}

// For each match of the regex in the content.
for _, submatches := range pattern.FindAllSubmatchIndex(stdout, -1) {
service := pattern.Expand(dst, template, stdout, submatches)
googleServices = append(googleServices, string(service))
}

////////////////////////////////////////////////////////////////////////////////

f, err := os.Open(fmt.Sprintf("../../mmv1/third_party/terraform/.teamcity/components/inputs/%s", *serviceFile))
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 "services" from *serviceFile.
pattern = regexp.MustCompile(`(?m)"(?P<service>\w+)"\sto\s+mapOf`)

template = []byte("$service")

dst = []byte{}
teamcityServices := []string{}

// For each match of the regex in the content.
for _, submatches := range pattern.FindAllSubmatchIndex(bs, -1) {
service := pattern.Expand(dst, template, bs, submatches)
teamcityServices = append(teamcityServices, string(service))
}

if diff := serviceDifference(googleServices, teamcityServices); len(diff) != 0 {
fmt.Fprintf(os.Stderr, "error: diff in %s\n", *serviceFile)
fmt.Fprintf(os.Stderr, "Missing Services: %s\n", diff)
os.Exit(1)
}

fmt.Printf("No Diff in %s provider\n", *provider)
}
Loading