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

teamcity gha pass #6

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
55 changes: 55 additions & 0 deletions .github/workflows/teamcity-services-diff-check.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions mmv1/provider/terraform/common~copy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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<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.Fprintf(os.Stderr, "error: diff in services_ga.kt")
}
}
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
Loading