Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
spapi17 committed Dec 13, 2023
2 parents 886ac1c + de7d39b commit 5bbc7ca
Show file tree
Hide file tree
Showing 499 changed files with 11,394 additions and 4,831 deletions.
4 changes: 2 additions & 2 deletions .ci/containers/build-environment/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Building Go dependencies
FROM golang:1.19-bullseye AS builder
FROM golang:1.20-bullseye AS builder

# Set working directory
WORKDIR /app
Expand All @@ -15,7 +15,7 @@ RUN go mod download
FROM ruby:3.1-bullseye

# golang
COPY --from=golang:1.19-bullseye /usr/local/go /usr/local/go
COPY --from=golang:1.20-bullseye /usr/local/go /usr/local/go
ENV GOPATH /go
ENV PATH /usr/local/go/bin:$PATH
ENV PATH $GOPATH/bin:$PATH
Expand Down
4 changes: 2 additions & 2 deletions .ci/containers/go-plus/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Download go module cache for builds
FROM golang:1.19-bullseye AS builder
FROM golang:1.20-bullseye AS builder
ENV GOCACHE=/go/cache

RUN apt-get update && apt-get install -y unzip
Expand All @@ -12,7 +12,7 @@ WORKDIR /app1/magic-modules-main/.ci/magician
RUN go build -o /dev/null .

# Stage 2: Creating the final image
FROM golang:1.19-bullseye
FROM golang:1.20-bullseye
SHELL ["/bin/bash", "-c"]
ENV GOCACHE=/go/cache

Expand Down
2 changes: 2 additions & 0 deletions .ci/infra/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ After applying this configuration:
- Add a new test user in the Google Workspace Admin Console: https://admin.google.com/ac/users
- Create a `support@` group in the Google Workspace Admin Console, add new service account as a member, and make it an owner
- Enroll in Cloud Armor Managed Protection Plus tier
- Add Cloud Identity Premium Plan to the Google Workspace domain
Quotas that will need to be adjusted to support all tests:
- Project quota for the new service account
Expand All @@ -67,3 +68,4 @@ Quotas that will need to be adjusted to support all tests:
- compute.googleapis.com/regional_static_addresses (us-central1)
- compute.googleapis.com/routers
- compute.googleapis.com/c2_cpus (us-central1)
- compute.googleapis.com/n2_cpus (us-central1) to 36+
3 changes: 3 additions & 0 deletions .ci/infra/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ module "project-services" {
"managedidentities.googleapis.com",
"memcache.googleapis.com",
"metastore.googleapis.com",
"migrationcenter.googleapis.com",
"ml.googleapis.com",
"mobilecrashreporting.googleapis.com",
"monitoring.googleapis.com",
"multiclustermetering.googleapis.com",
"netapp.googleapis.com",
"networkconnectivity.googleapis.com",
"networkmanagement.googleapis.com",
"networksecurity.googleapis.com",
Expand All @@ -286,6 +288,7 @@ module "project-services" {
"run.googleapis.com",
"runtimeconfig.googleapis.com",
"secretmanager.googleapis.com",
"securesourcemanager.googleapis.com",
"securetoken.googleapis.com",
"securitycenter.googleapis.com",
"serviceconsumermanagement.googleapis.com",
Expand Down
8 changes: 4 additions & 4 deletions .ci/magician/cloudbuild/build_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"os"

"google.golang.org/api/cloudbuild/v1"
cloudbuildv1 "google.golang.org/api/cloudbuild/v1"
)

func (cb cloudBuild) TriggerMMPresubmitRuns(commitSha string, substitutions map[string]string) error {
func (cb *Client) TriggerMMPresubmitRuns(commitSha string, substitutions map[string]string) error {
presubmitTriggerId, ok := os.LookupEnv("GENERATE_DIFFS_TRIGGER")
if !ok {
return fmt.Errorf("did not provide GENERATE_DIFFS_TRIGGER environment variable")
Expand All @@ -24,12 +24,12 @@ func (cb cloudBuild) TriggerMMPresubmitRuns(commitSha string, substitutions map[

func triggerCloudBuildRun(projectId, triggerId, repoName, commitSha string, substitutions map[string]string) error {
ctx := context.Background()
c, err := cloudbuild.NewService(ctx)
c, err := cloudbuildv1.NewService(ctx)
if err != nil {
return fmt.Errorf("failed to create Cloud Build service client: %s", err)
}

repoSource := &cloudbuild.RepoSource{
repoSource := &cloudbuildv1.RepoSource{
ProjectId: projectId,
RepoName: repoName,
CommitSha: commitSha,
Expand Down
14 changes: 7 additions & 7 deletions .ci/magician/cloudbuild/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"os"

"google.golang.org/api/cloudbuild/v1"
cloudbuildv1 "google.golang.org/api/cloudbuild/v1"
)

func (cb cloudBuild) ApproveCommunityChecker(prNumber, commitSha string) error {
func (cb *Client) ApproveCommunityChecker(prNumber, commitSha string) error {
buildId, err := getPendingBuildId(PROJECT_ID, commitSha)
if err != nil {
return err
Expand All @@ -26,7 +26,7 @@ func (cb cloudBuild) ApproveCommunityChecker(prNumber, commitSha string) error {
return nil
}

func (cb cloudBuild) GetAwaitingApprovalBuildLink(prNumber, commitSha string) (string, error) {
func (cb *Client) GetAwaitingApprovalBuildLink(prNumber, commitSha string) (string, error) {
buildId, err := getPendingBuildId(PROJECT_ID, commitSha)
if err != nil {
return "", err
Expand All @@ -49,7 +49,7 @@ func getPendingBuildId(projectId, commitSha string) (string, error) {

ctx := context.Background()

c, err := cloudbuild.NewService(ctx)
c, err := cloudbuildv1.NewService(ctx)
if err != nil {
return "", err
}
Expand All @@ -76,15 +76,15 @@ func getPendingBuildId(projectId, commitSha string) (string, error) {
func approveBuild(projectId, buildId string) error {
ctx := context.Background()

c, err := cloudbuild.NewService(ctx)
c, err := cloudbuildv1.NewService(ctx)
if err != nil {
return err
}

name := fmt.Sprintf("projects/%s/builds/%s", projectId, buildId)

approveBuildRequest := &cloudbuild.ApproveBuildRequest{
ApprovalResult: &cloudbuild.ApprovalResult{
approveBuildRequest := &cloudbuildv1.ApproveBuildRequest{
ApprovalResult: &cloudbuildv1.ApprovalResult{
Decision: "APPROVED",
},
}
Expand Down
12 changes: 3 additions & 9 deletions .ci/magician/cloudbuild/init.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package cloudbuild

type cloudBuild bool

type CloudBuild interface {
ApproveCommunityChecker(prNumber, commitSha string) error
GetAwaitingApprovalBuildLink(prNumber, commitSha string) (string, error)
TriggerMMPresubmitRuns(commitSha string, substitutions map[string]string) error
type Client struct {
}

func NewCloudBuildService() CloudBuild {
var x cloudBuild = true
return x
func NewClient() *Client {
return &Client{}
}
20 changes: 5 additions & 15 deletions .ci/magician/cmd/community_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ import (
"github.com/spf13/cobra"
)

type ccGithub interface {
GetPullRequestAuthor(prNumber string) (string, error)
GetUserType(user string) github.UserType
RemoveLabel(prNumber string, label string) error
PostBuildStatus(prNumber string, title string, state string, targetUrl string, commitSha string) error
}

type ccCloudbuild interface {
TriggerMMPresubmitRuns(commitSha string, substitutions map[string]string) error
}

// communityApprovalCmd represents the communityApproval command
var communityApprovalCmd = &cobra.Command{
Use: "community-checker",
Expand Down Expand Up @@ -63,13 +52,13 @@ var communityApprovalCmd = &cobra.Command{
baseBranch := args[5]
fmt.Println("Base Branch: ", baseBranch)

gh := github.NewGithubService()
cb := cloudbuild.NewCloudBuildService()
gh := github.NewClient()
cb := cloudbuild.NewClient()
execCommunityChecker(prNumber, commitSha, branchName, headRepoUrl, headBranch, baseBranch, gh, cb)
},
}

func execCommunityChecker(prNumber, commitSha, branchName, headRepoUrl, headBranch, baseBranch string, gh ccGithub, cb ccCloudbuild) {
func execCommunityChecker(prNumber, commitSha, branchName, headRepoUrl, headBranch, baseBranch string, gh GithubClient, cb CloudbuildClient) {
substitutions := map[string]string{
"BRANCH_NAME": branchName,
"_PR_NUMBER": prNumber,
Expand All @@ -78,12 +67,13 @@ func execCommunityChecker(prNumber, commitSha, branchName, headRepoUrl, headBran
"_BASE_BRANCH": baseBranch,
}

author, err := gh.GetPullRequestAuthor(prNumber)
pullRequest, err := gh.GetPullRequest(prNumber)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

author := pullRequest.User.Login
authorUserType := gh.GetUserType(author)
trusted := authorUserType == github.CoreContributorUserType || authorUserType == github.GooglerUserType

Expand Down
18 changes: 15 additions & 3 deletions .ci/magician/cmd/community_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (

func TestExecCommunityChecker_CoreContributorFlow(t *testing.T) {
gh := &mockGithub{
author: "core_author",
pullRequest: github.PullRequest{
User: github.User{
Login: "core_author",
},
},
userType: github.CoreContributorUserType,
calledMethods: make(map[string][][]any),
}
Expand All @@ -34,7 +38,11 @@ func TestExecCommunityChecker_CoreContributorFlow(t *testing.T) {

func TestExecCommunityChecker_GooglerFlow(t *testing.T) {
gh := &mockGithub{
author: "googler_author",
pullRequest: github.PullRequest{
User: github.User{
Login: "googler_author",
},
},
userType: github.GooglerUserType,
calledMethods: make(map[string][][]any),
firstReviewer: "reviewer1",
Expand All @@ -61,7 +69,11 @@ func TestExecCommunityChecker_GooglerFlow(t *testing.T) {

func TestExecCommunityChecker_AmbiguousUserFlow(t *testing.T) {
gh := &mockGithub{
author: "ambiguous_author",
pullRequest: github.PullRequest{
User: github.User{
Login: "ambiguous_author",
},
},
userType: github.CommunityUserType,
calledMethods: make(map[string][][]any),
firstReviewer: github.GetRandomReviewer(),
Expand Down
Loading

0 comments on commit 5bbc7ca

Please sign in to comment.