Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
arnabadg-google authored Jan 16, 2024
2 parents 9b831a9 + 167cbbe commit 6bc0236
Show file tree
Hide file tree
Showing 206 changed files with 7,577 additions and 1,931 deletions.
13 changes: 0 additions & 13 deletions .ci/containers/go-plus/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,3 @@ RUN wget https://releases.hashicorp.com/terraform/1.2.5/terraform_1.2.5_linux_am
&& unzip terraform_1.2.5_linux_amd64.zip \
&& rm terraform_1.2.5_linux_amd64.zip \
&& mv ./terraform /bin/terraform

### the following version of terraform are required for
### terraform-validator-tester-integration
RUN wget https://releases.hashicorp.com/terraform/0.13.7/terraform_0.13.7_linux_amd64.zip \
&& unzip terraform_0.13.7_linux_amd64.zip \
&& rm terraform_0.13.7_linux_amd64.zip \
&& mkdir /terraform \
&& mv terraform /terraform/0.13.7

RUN wget https://releases.hashicorp.com/terraform/0.12.31/terraform_0.12.31_linux_amd64.zip \
&& unzip terraform_0.12.31_linux_amd64.zip \
&& rm terraform_0.12.31_linux_amd64.zip \
&& mv terraform /terraform/0.12.31
27 changes: 4 additions & 23 deletions .ci/gcb-generate-diffs-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,12 @@ steps:
- PR_NUMBER=$_PR_NUMBER

- name: 'gcr.io/graphite-docker-images/go-plus'
id: tgc-test-integration-0.12.31
id: tgc-test-integration
entrypoint: '/workspace/.ci/scripts/go-plus/tgc-tester-integration/test_tgc_integration.sh'
allowFailure: true
secretEnv: ["GITHUB_TOKEN"]
waitFor: ["tpgb-head", "tpgb-base", "tgc-head", "tgc-base"]
env:
- TERRAFORM_VERSION=0.12.31
- TEST_PROJECT=$_VALIDATOR_TEST_PROJECT
- TEST_FOLDER_ID=$_VALIDATOR_TEST_FOLDER
- TEST_ANCESTRY=$_VALIDATOR_TEST_ANCESTRY
Expand All @@ -213,26 +212,6 @@ steps:
- "18" # Build step
- terraform-google-conversion

- name: 'gcr.io/graphite-docker-images/go-plus'
id: tgc-test-integration-0.13.7
entrypoint: '/workspace/.ci/scripts/go-plus/tgc-tester-integration/test_tgc_integration.sh'
allowFailure: true
secretEnv: ["GITHUB_TOKEN"]
waitFor: ["tpgb-head", "tpgb-base", "tgc-head", "tgc-base"]
env:
- TERRAFORM_VERSION=0.13.7
- TEST_PROJECT=$_VALIDATOR_TEST_PROJECT
- TEST_FOLDER_ID=$_VALIDATOR_TEST_FOLDER
- TEST_ANCESTRY=$_VALIDATOR_TEST_ANCESTRY
- TEST_ORG_ID=$_VALIDATOR_TEST_ORG
args:
- $_PR_NUMBER
- $COMMIT_SHA
- $BUILD_ID
- $PROJECT_ID
- "19" # Build step
- terraform-google-conversion

- name: 'gcr.io/graphite-docker-images/go-plus'
id: tpgb-test
allowFailure: true
Expand Down Expand Up @@ -262,7 +241,7 @@ steps:
- name: 'gcr.io/graphite-docker-images/go-plus'
id: gcb-tpg-vcr-test
entrypoint: '/workspace/.ci/scripts/go-plus/gcb-terraform-vcr-tester/test_terraform_vcr.sh'
secretEnv: ["GITHUB_TOKEN", "GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION"]
secretEnv: ["GITHUB_TOKEN", "GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION", "GOOGLE_TPU_V2_VM_RUNTIME_VERSION"]
waitFor: ["diff"]
env:
- BASE_BRANCH=$_BASE_BRANCH
Expand Down Expand Up @@ -316,3 +295,5 @@ availableSecrets:
env: SA_KEY
- versionName: projects/673497134629/secrets/ci-test-public-advertised-prefix-description/versions/latest
env: GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION
- versionName: projects/673497134629/secrets/ci-test-tpu-v2-vm-runtime-version/versions/latest
env: GOOGLE_TPU_V2_VM_RUNTIME_VERSION
3 changes: 3 additions & 0 deletions .ci/gcb-push-downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ steps:
- "GOOGLE_SERVICE_ACCOUNT"
- "SA_KEY"
- "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION"
- "GOOGLE_TPU_V2_VM_RUNTIME_VERSION"
env:
- "COMMIT_SHA=$COMMIT_SHA"
- "GOOGLE_REGION=us-central1"
Expand Down Expand Up @@ -245,3 +246,5 @@ availableSecrets:
env: SA_KEY
- versionName: projects/673497134629/secrets/ci-test-public-advertised-prefix-description/versions/latest
env: GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION
- versionName: projects/673497134629/secrets/ci-test-tpu-v2-vm-runtime-version/versions/latest
env: GOOGLE_TPU_V2_VM_RUNTIME_VERSION
4 changes: 3 additions & 1 deletion .ci/gcb-vcr-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ steps:
- name: 'gcr.io/graphite-docker-images/go-plus'
id: gcb-vcr-nightly
entrypoint: '/workspace/.ci/scripts/go-plus/vcr-cassette-update/vcr_cassette_update.sh'
secretEnv: ["GITHUB_TOKEN", "GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION"]
secretEnv: ["GITHUB_TOKEN", "GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION", "GOOGLE_TPU_V2_VM_RUNTIME_VERSION"]
args:
- $BUILD_ID

Expand Down Expand Up @@ -43,3 +43,5 @@ availableSecrets:
env: SA_KEY
- versionName: projects/673497134629/secrets/ci-test-public-advertised-prefix-description/versions/latest
env: GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION
- versionName: projects/673497134629/secrets/ci-test-tpu-v2-vm-runtime-version/versions/latest
env: GOOGLE_TPU_V2_VM_RUNTIME_VERSION
1 change: 1 addition & 0 deletions .ci/magician/cmd/check_cassettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var environmentVariables = [...]string{
"GOOGLE_REGION",
"GOOGLE_SERVICE_ACCOUNT",
"GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION",
"GOOGLE_TPU_V2_VM_RUNTIME_VERSION",
"GOOGLE_ZONE",
"PATH",
"SA_KEY",
Expand Down
8 changes: 4 additions & 4 deletions .ci/magician/github/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (gh *Client) GetPullRequest(prNumber string) (PullRequest, error) {

var pullRequest PullRequest

_, err := utils.RequestCall(url, "GET", gh.token, &pullRequest, nil)
err := utils.RequestCall(url, "GET", gh.token, &pullRequest, nil)
if err != nil {
return pullRequest, err
}
Expand All @@ -53,7 +53,7 @@ func (gh *Client) GetPullRequestRequestedReviewers(prNumber string) ([]User, err
Users []User `json:"users"`
}

_, err := utils.RequestCall(url, "GET", gh.token, &requestedReviewers, nil)
err := utils.RequestCall(url, "GET", gh.token, &requestedReviewers, nil)
if err != nil {
return nil, err
}
Expand All @@ -68,7 +68,7 @@ func (gh *Client) GetPullRequestPreviousReviewers(prNumber string) ([]User, erro
User User `json:"user"`
}

_, err := utils.RequestCall(url, "GET", gh.token, &reviews, nil)
err := utils.RequestCall(url, "GET", gh.token, &reviews, nil)
if err != nil {
return nil, err
}
Expand All @@ -90,7 +90,7 @@ func (gh *Client) GetTeamMembers(organization, team string) ([]User, error) {
url := fmt.Sprintf("https://api.github.com/orgs/%s/teams/%s/members", organization, team)

var members []User
_, err := utils.RequestCall(url, "GET", gh.token, &members, nil)
err := utils.RequestCall(url, "GET", gh.token, &members, nil)
if err != nil {
return nil, err
}
Expand Down
15 changes: 6 additions & 9 deletions .ci/magician/github/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ var (

// This is for reviewers who are "on vacation": will not receive new review assignments but will still receive re-requests for assigned PRs.
onVacationReviewers = []string{
"hao-nan-li",
"SarahFrench",
"melinath",
"roaks3",
"trodge",
"zli82016",
"shuyama1",
"c2thorn",
}
)

Expand Down Expand Up @@ -107,9 +101,12 @@ func IsTeamReviewer(reviewer string) bool {

func isOrgMember(author, org, githubToken string) bool {
url := fmt.Sprintf("https://api.github.com/orgs/%s/members/%s", org, author)
res, _ := utils.RequestCall(url, "GET", githubToken, nil, nil)
err := utils.RequestCall(url, "GET", githubToken, nil, nil)

return res != 404
if err != nil {
return false
}
return true
}

func GetRandomReviewer() string {
Expand Down
25 changes: 6 additions & 19 deletions .ci/magician/github/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package github
import (
"fmt"
utils "magician/utility"
"net/http"
)

func (gh *Client) PostBuildStatus(prNumber, title, state, targetURL, commitSha string) error {
Expand All @@ -30,7 +29,7 @@ func (gh *Client) PostBuildStatus(prNumber, title, state, targetURL, commitSha s
"target_url": targetURL,
}

_, err := utils.RequestCall(url, "POST", gh.token, nil, postBody)
err := utils.RequestCall(url, "POST", gh.token, nil, postBody)
if err != nil {
return err
}
Expand All @@ -47,15 +46,11 @@ func (gh *Client) PostComment(prNumber, comment string) error {
"body": comment,
}

reqStatusCode, err := utils.RequestCall(url, "POST", gh.token, nil, body)
err := utils.RequestCall(url, "POST", gh.token, nil, body)
if err != nil {
return err
}

if reqStatusCode != http.StatusCreated {
return fmt.Errorf("error posting comment for PR %s", prNumber)
}

fmt.Printf("Successfully posted comment to pull request %s\n", prNumber)

return nil
Expand All @@ -69,15 +64,11 @@ func (gh *Client) RequestPullRequestReviewer(prNumber, assignee string) error {
"team_reviewers": {},
}

reqStatusCode, err := utils.RequestCall(url, "POST", gh.token, nil, body)
err := utils.RequestCall(url, "POST", gh.token, nil, body)
if err != nil {
return err
}

if reqStatusCode != http.StatusCreated {
return fmt.Errorf("error adding reviewer for PR %s", prNumber)
}

fmt.Printf("Successfully added reviewer %s to pull request %s\n", assignee, prNumber)

return nil
Expand All @@ -89,7 +80,7 @@ func (gh *Client) AddLabel(prNumber, label string) error {
body := map[string][]string{
"labels": {label},
}
_, err := utils.RequestCall(url, "POST", gh.token, nil, body)
err := utils.RequestCall(url, "POST", gh.token, nil, body)

if err != nil {
return fmt.Errorf("failed to add %s label: %s", label, err)
Expand All @@ -101,7 +92,7 @@ func (gh *Client) AddLabel(prNumber, label string) error {

func (gh *Client) RemoveLabel(prNumber, label string) error {
url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/issues/%s/labels/%s", prNumber, label)
_, err := utils.RequestCall(url, "DELETE", gh.token, nil, nil)
err := utils.RequestCall(url, "DELETE", gh.token, nil, nil)

if err != nil {
return fmt.Errorf("failed to remove %s label: %s", label, err)
Expand All @@ -112,15 +103,11 @@ func (gh *Client) RemoveLabel(prNumber, label string) error {

func (gh *Client) CreateWorkflowDispatchEvent(workflowFileName string, inputs map[string]any) error {
url := fmt.Sprintf("https://api.github.com/repos/GoogleCloudPlatform/magic-modules/actions/workflows/%s/dispatches", workflowFileName)
resp, err := utils.RequestCall(url, "POST", gh.token, nil, map[string]any{
err := utils.RequestCall(url, "POST", gh.token, nil, map[string]any{
"ref": "main",
"inputs": inputs,
})

if resp != 200 && resp != 204 {
return fmt.Errorf("server returned %d creating workflow dispatch event", resp)
}

if err != nil {
return fmt.Errorf("failed to create workflow dispatch event: %s", err)
}
Expand Down
18 changes: 11 additions & 7 deletions .ci/magician/utility/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
"golang.org/x/exp/slices"
)

func RequestCall(url, method, credentials string, result any, body any) (int, error) {
func RequestCall(url, method, credentials string, result any, body any) error {
client := &http.Client{}
jsonBody, err := json.Marshal(body)
if err != nil {
return 1, fmt.Errorf("error marshaling JSON: %s", err)
return fmt.Errorf("error marshaling JSON: %s", err)
}
req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonBody))
if err != nil {
return 2, fmt.Errorf("error creating request: %s", err)
return fmt.Errorf("error creating request: %s", err)
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", credentials))
req.Header.Set("Content-Type", "application/json")
Expand All @@ -44,13 +44,13 @@ func RequestCall(url, method, credentials string, result any, body any) (int, er

resp, err := client.Do(req)
if err != nil {
return 3, err
return err
}
defer resp.Body.Close()

respBodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return 5, err
return err
}

fmt.Println("response status-code: ", resp.StatusCode)
Expand All @@ -60,11 +60,15 @@ func RequestCall(url, method, credentials string, result any, body any) (int, er
// Decode the response, if needed
if result != nil {
if err = json.Unmarshal(respBodyBytes, &result); err != nil {
return 4, err
return err
}
}

return resp.StatusCode, nil
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("got code %d from server", resp.StatusCode)
}

return nil
}

func Removes(s1 []string, s2 []string) []string {
Expand Down
25 changes: 2 additions & 23 deletions .ci/scripts/go-plus/tgc-tester-integration/test_tgc_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,8 @@ else
echo "Running tests: Go files changed"
fi


TERRAFORM_BINARY=/terraform/$TERRAFORM_VERSION
if test -f "$TERRAFORM_BINARY"; then
echo "terraform binary $TERRAFORM_BINARY exists on container"
echo setting terraform to version $TERRAFORM_VERSION
set x-
mv /terraform/$TERRAFORM_VERSION /bin/terraform
set x+
terraform version
else
echo "terraform binary $TERRAFORM_BINARY does not exist."
echo "exiting ..."
state="failure"
post_body=$( jq -n \
--arg context "${gh_repo}-test-integration-${TERRAFORM_VERSION}" \
--arg target_url "https://console.cloud.google.com/cloud-build/builds;region=global/${build_id};step=${build_step}?project=${project_id}" \
--arg state "$state" \
'{context: $context, target_url: $target_url, state: $state}')
exit 0
fi

post_body=$( jq -n \
--arg context "${gh_repo}-test-integration-${TERRAFORM_VERSION}" \
--arg context "${gh_repo}-test-integration" \
--arg target_url "https://console.cloud.google.com/cloud-build/builds;region=global/${build_id};step=${build_step}?project=${project_id}" \
--arg state "pending" \
'{context: $context, target_url: $target_url, state: $state}')
Expand Down Expand Up @@ -82,7 +61,7 @@ else
fi

post_body=$( jq -n \
--arg context "${gh_repo}-test-integration-${TERRAFORM_VERSION}" \
--arg context "${gh_repo}-test-integration" \
--arg target_url "https://console.cloud.google.com/cloud-build/builds;region=global/${build_id};step=${build_step}?project=${project_id}" \
--arg state "${state}" \
'{context: $context, target_url: $target_url, state: $state}')
Expand Down
Loading

0 comments on commit 6bc0236

Please sign in to comment.