Skip to content

Commit d6d2116

Browse files
authored
Merge branch 'main' into key-revocation-action-field
2 parents 3055ad7 + 91654fd commit d6d2116

File tree

391 files changed

+12855
-1218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

391 files changed

+12855
-1218
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
{{- if or (gt (len .NotRunBetaTests) 0) (gt (len .NotRunGATests) 0) -}}
1+
{{- if or (gt (len .NotRunBetaTests) 0) (gt (len .NotRunGATests) 0)}}
22
#### Non-exercised tests
33

44
{{if gt (len .NotRunBetaTests) 0 -}}
5-
Tests were added that are skipped in VCR:
5+
{{color "red" "Tests were added that are skipped in VCR:"}}
66
{{range .NotRunBetaTests}}{{. | printf "- %s\n"}}{{end}}
77
{{end}}
88

99
{{if gt (len .NotRunGATests) 0 -}}
10-
Tests were added that are GA-only additions and require manual runs:
10+
{{color "red" "Tests were added that are GA-only additions and require manual runs:"}}
1111
{{range .NotRunGATests}}{{. | printf "- %s\n"}}{{end}}
1212
{{end}}
1313
{{end}}

.ci/magician/cmd/templates/vcr/record_replay.tmpl

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
{{- if gt (len .RecordingResult.PassedTests) 0 -}}
22
{{color "green" "Tests passed during RECORDING mode:"}}
3-
{{range .RecordingResult.PassedTests}}`{{.}}`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-{{$.PRNumber}}/artifacts/{{$.BuildID}}/recording/{{.}}.log)]
3+
{{range .RecordingResult.PassedTests -}}
4+
`{{.}}` {{/* remove trailing whitespace */ -}}
5+
[[Debug log](https://storage.cloud.google.com/{{$.LogBucket}}/{{$.Version}}/refs/heads/{{$.Head}}/artifacts/{{$.BuildID}}/recording/{{.}}.log)]
6+
{{/* remove trailing whitespace */ -}}
47
{{end}}
58

6-
{{- if gt (len .ReplayingAfterRecordingResult.FailedTests ) 0 -}}
9+
{{- if gt (len .ReplayingAfterRecordingResult.FailedTests ) 0 }}
10+
711
{{color "red" "Tests failed when rerunning REPLAYING mode:"}}
8-
{{range .ReplayingAfterRecordingResult.FailedTests}}`{{.}}`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-{{$.PRNumber}}/artifacts/{{$.BuildID}}/build-log/replaying_build_after_recording/{{.}}_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-{{$.PRNumber}}/artifacts/{{$.BuildID}}/replaying_after_recording/{{.}}.log)]
12+
{{range .ReplayingAfterRecordingResult.FailedTests -}}
13+
`{{.}}` {{/* remove trailing whitespace */ -}}
14+
[[Error message](https://storage.cloud.google.com/{{$.LogBucket}}/{{$.Version}}/refs/heads/{{$.Head}}/artifacts/{{$.BuildID}}/build-log/replaying_build_after_recording/{{.}}_replaying_test.log)] {{/* remove trailing whitespace */ -}}
15+
[[Debug log](https://storage.cloud.google.com/{{$.LogBucket}}/{{$.Version}}/refs/heads/{{$.Head}}/artifacts/{{$.BuildID}}/replaying_after_recording/{{.}}.log)]
16+
{{/* remove trailing whitespace */ -}}
917
{{end}}
1018

1119
Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.
@@ -20,12 +28,19 @@ Please fix these to complete your PR. If you believe these test failures to be i
2028

2129
{{if gt (len .RecordingResult.FailedTests) 0 -}}
2230
{{color "red" "Tests failed during RECORDING mode:"}}
23-
{{range .RecordingResult.FailedTests}}`{{.}}`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-{{$.PRNumber}}/artifacts/{{$.BuildID}}/build-log/recording_build/{{.}}_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-{{$.PRNumber}}/artifacts/{{$.BuildID}}/recording/{{.}}.log)]
31+
{{range .RecordingResult.FailedTests -}}
32+
`{{.}}` {{/* remove trailing whitespace */ -}}
33+
[[Error message](https://storage.cloud.google.com/{{$.LogBucket}}/{{$.Version}}/refs/heads/{{$.Head}}/artifacts/{{$.BuildID}}/build-log/recording_build/{{.}}_recording_test.log)] {{/* remove trailing whitespace */ -}}
34+
[[Debug log](https://storage.cloud.google.com/{{$.LogBucket}}/{{$.Version}}/refs/heads/{{$.Head}}/artifacts/{{$.BuildID}}/recording/{{.}}.log)]
35+
{{/* remove trailing whitespace */ -}}
2436
{{end}}
2537
{{end}} {{- /* end of if gt (len .RecordingResult.FailedTests) 0 */ -}}
2638

27-
{{if .HasTerminatedTests}}{{color "red" "Several tests got terminated during RECORDING mode."}}{{end}}
39+
{{if .HasTerminatedTests}}{{color "red" "Several tests terminated during RECORDING mode."}}{{end}}
40+
2841
{{if .RecordingErr}}{{color "red" "Errors occurred during RECORDING mode. Please fix them to complete your PR."}}{{end}}
42+
2943
{{if .AllRecordingPassed}}{{color "green" "All tests passed!"}}{{end}}
3044

31-
View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-{{.PRNumber}}/artifacts/{{.BuildID}}/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-{{.PRNumber}}/artifacts/{{.BuildID}}/recording) for each test
45+
View the [build log](https://storage.cloud.google.com/{{.LogBucket}}/{{.Version}}/refs/heads/{{.Head}}/artifacts/{{.BuildID}}/build-log/recording_test.log) {{/* remove trailing whitespace */ -}}
46+
or the [debug log](https://console.cloud.google.com/storage/browser/{{.LogBucket}}/{{.Version}}/refs/heads/{{.Head}}/artifacts/{{.BuildID}}/recording) for each test

.ci/magician/cmd/templates/vcr/without_replay_failed_tests.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
{{color "green" "All tests passed!"}}
55
{{- end}}
66

7-
View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-{{.PRNumber}}/artifacts/{{.BuildID}}/build-log/replaying_test.log)
7+
View the [build log](https://storage.cloud.google.com/{{.LogBucket}}/{{.Version}}/refs/heads/{{.Head}}/artifacts/{{.BuildID}}/build-log/replaying_test.log)

.ci/magician/cmd/test_terraform_vcr.go

+41-16
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ type withReplayFailedTests struct {
7272

7373
type withoutReplayFailedTests struct {
7474
ReplayingErr error
75-
PRNumber string
75+
LogBucket string
76+
Version string
77+
Head string
7678
BuildID string
7779
}
7880

@@ -82,14 +84,26 @@ type recordReplay struct {
8284
HasTerminatedTests bool
8385
RecordingErr error
8486
AllRecordingPassed bool
85-
PRNumber string
87+
LogBucket string
88+
Version string
89+
Head string
8690
BuildID string
8791
}
8892

8993
var testTerraformVCRCmd = &cobra.Command{
9094
Use: "test-terraform-vcr",
9195
Short: "Run vcr tests for affected packages",
92-
Long: `This command runs on new pull requests to replay VCR cassettes and re-record failing cassettes.`,
96+
Long: `This command runs on new pull requests to replay VCR cassettes and re-record failing cassettes.
97+
98+
It expects the following arguments:
99+
1. PR number
100+
2. SHA of the latest magic-modules commit
101+
3. Build ID
102+
4. Project ID where Cloud Builds are located
103+
5. Build step number
104+
105+
The following environment variables are required:
106+
` + listTTVEnvironmentVariables(),
93107
RunE: func(cmd *cobra.Command, args []string) error {
94108
env := make(map[string]string, len(ttvEnvironmentVariables))
95109
for _, ev := range ttvEnvironmentVariables {
@@ -133,6 +147,14 @@ var testTerraformVCRCmd = &cobra.Command{
133147
},
134148
}
135149

150+
func listTTVEnvironmentVariables() string {
151+
var result string
152+
for i, ev := range ttvEnvironmentVariables {
153+
result += fmt.Sprintf("\t%2d. %s\n", i+1, ev)
154+
}
155+
return result
156+
}
157+
136158
func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep, baseBranch string, gh GithubClient, rnr ExecRunner, ctlr *source.Controller, vt *vcr.Tester) error {
137159
newBranch := "auto-pr-" + prNumber
138160
oldBranch := newBranch + "-old"
@@ -173,7 +195,7 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
173195
return fmt.Errorf("error changing to tpgbRepo dir: %w", err)
174196
}
175197

176-
services, runFullVCR := modifiedPackages(tpgbRepo.ChangedFiles)
198+
services, runFullVCR := modifiedPackages(tpgbRepo.ChangedFiles, provider.Beta)
177199
if len(services) == 0 && !runFullVCR {
178200
fmt.Println("Skipping tests: No go files or test fixtures changed")
179201
return nil
@@ -189,7 +211,7 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
189211
return fmt.Errorf("error posting pending status: %w", err)
190212
}
191213

192-
replayingResult, testDirs, replayingErr := runReplaying(runFullVCR, services, vt)
214+
replayingResult, testDirs, replayingErr := runReplaying(runFullVCR, provider.Beta, services, vt)
193215
testState := "success"
194216
if replayingErr != nil {
195217
testState = "failure"
@@ -316,7 +338,9 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
316338
RecordingErr: recordingErr,
317339
HasTerminatedTests: hasTerminatedTests,
318340
AllRecordingPassed: allRecordingPassed,
319-
PRNumber: prNumber,
341+
LogBucket: "ci-vcr-logs",
342+
Version: provider.Beta.String(),
343+
Head: newBranch,
320344
BuildID: buildID,
321345
}
322346
recordReplayComment, err := formatRecordReplay(recordReplayData)
@@ -330,7 +354,8 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
330354
} else { // len(replayingResult.FailedTests) == 0
331355
withoutReplayFailedTestsData := withoutReplayFailedTests{
332356
ReplayingErr: replayingErr,
333-
PRNumber: prNumber,
357+
Head: newBranch,
358+
LogBucket: "ci-vcr-logs",
334359
BuildID: buildID,
335360
}
336361
withoutReplayFailedTestsComment, err := formatWithoutReplayFailedTests(withoutReplayFailedTestsData)
@@ -393,7 +418,7 @@ func notRunTests(gaDiff, betaDiff string, result vcr.Result) ([]string, []string
393418
return notRunBeta, notRunGa
394419
}
395420

396-
func modifiedPackages(changedFiles []string) (map[string]struct{}, bool) {
421+
func modifiedPackages(changedFiles []string, version provider.Version) (map[string]struct{}, bool) {
397422
var goFiles []string
398423
for _, line := range changedFiles {
399424
if strings.HasSuffix(line, ".go") || strings.Contains(line, "test-fixtures") || strings.HasSuffix(line, "go.mod") || strings.HasSuffix(line, "go.sum") {
@@ -403,10 +428,10 @@ func modifiedPackages(changedFiles []string) (map[string]struct{}, bool) {
403428
services := make(map[string]struct{})
404429
runFullVCR := false
405430
for _, file := range goFiles {
406-
if strings.HasPrefix(file, "google-beta/services/") {
431+
if strings.HasPrefix(file, version.ProviderName()+"/services/") {
407432
fileParts := strings.Split(file, "/")
408433
services[fileParts[2]] = struct{}{}
409-
} else if file == "google-beta/provider/provider_mmv1_resources.go" || file == "google-beta/provider/provider_dcl_resources.go" {
434+
} else if file == version.ProviderName()+"/provider/provider_mmv1_resources.go" || file == version.ProviderName()+"/provider/provider_dcl_resources.go" {
410435
fmt.Println("ignore changes in ", file)
411436
} else {
412437
fmt.Println("run full tests ", file)
@@ -417,25 +442,25 @@ func modifiedPackages(changedFiles []string) (map[string]struct{}, bool) {
417442
return services, runFullVCR
418443
}
419444

420-
func runReplaying(runFullVCR bool, services map[string]struct{}, vt *vcr.Tester) (vcr.Result, []string, error) {
445+
func runReplaying(runFullVCR bool, version provider.Version, services map[string]struct{}, vt *vcr.Tester) (vcr.Result, []string, error) {
421446
result := vcr.Result{}
422447
var testDirs []string
423448
var replayingErr error
424449
if runFullVCR {
425450
fmt.Println("runReplaying: full VCR tests")
426451
result, replayingErr = vt.Run(vcr.RunOptions{
427452
Mode: vcr.Replaying,
428-
Version: provider.Beta,
453+
Version: version,
429454
})
430455
} else if len(services) > 0 {
431456
fmt.Printf("runReplaying: %d specific services: %v\n", len(services), services)
432457
for service := range services {
433-
servicePath := "./" + filepath.Join("google-beta", "services", service)
458+
servicePath := "./" + filepath.Join(version.ProviderName(), "services", service)
434459
testDirs = append(testDirs, servicePath)
435460
fmt.Println("run VCR tests in ", service)
436461
serviceResult, serviceReplayingErr := vt.Run(vcr.RunOptions{
437462
Mode: vcr.Replaying,
438-
Version: provider.Beta,
463+
Version: version,
439464
TestDirs: []string{servicePath},
440465
})
441466
if serviceReplayingErr != nil {
@@ -475,8 +500,8 @@ func init() {
475500

476501
func formatComment(fileName string, tmplText string, data any) (string, error) {
477502
funcs := template.FuncMap{
478-
"join": strings.Join,
479-
"add": func(i, j int) int { return i + j },
503+
"join": strings.Join,
504+
"add": func(i, j int) int { return i + j },
480505
"color": color,
481506
}
482507
tmpl, err := template.New(fileName).Funcs(funcs).Parse(tmplText)

0 commit comments

Comments
 (0)