From 51c84828f6e00f3603264344619524220130ab98 Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Mon, 16 Sep 2024 11:55:29 -0700 Subject: [PATCH] Trivial magician changes (#11712) --- .ci/magician/cmd/generate_comment.go | 2 +- .ci/magician/cmd/interfaces.go | 1 + .ci/magician/cmd/mock_runner_test.go | 4 +++ .ci/magician/cmd/scheduled_pr_reminders.go | 6 ++-- .../DIFF_COMMENT.md.tmpl} | 0 ...HEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl | 0 .../SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl | 0 .../SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl | 0 .../vcr/non_exercised_tests.tmpl} | 0 .../vcr/record_replay.tmpl} | 0 .../vcr/test_analytics.tmpl} | 0 .../vcr}/vcr_cassettes_update_recording.tmpl | 0 .../vcr}/vcr_cassettes_update_replaying.tmpl | 0 .../vcr/with_replay_failed_tests.tmpl} | 0 .../vcr/without_replay_failed_tests.tmpl} | 0 .ci/magician/cmd/test_terraform_vcr.go | 10 +++--- .ci/magician/cmd/test_terraform_vcr_test.go | 36 +++++++++---------- .ci/magician/cmd/vcr_cassette_update.go | 4 +-- .ci/magician/exec/runner.go | 13 +++++++ 19 files changed, 47 insertions(+), 29 deletions(-) rename .ci/magician/cmd/{DIFF_COMMENT.md => templates/DIFF_COMMENT.md.tmpl} (100%) rename .ci/magician/cmd/{ => templates}/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl (100%) rename .ci/magician/cmd/{ => templates}/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl (100%) rename .ci/magician/cmd/{ => templates}/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl (100%) rename .ci/magician/cmd/{test_terraform_vcr_non_exercised_tests.tmpl => templates/vcr/non_exercised_tests.tmpl} (100%) rename .ci/magician/cmd/{test_terraform_vcr_record_replay.tmpl => templates/vcr/record_replay.tmpl} (100%) rename .ci/magician/cmd/{test_terraform_vcr_test_analytics.tmpl => templates/vcr/test_analytics.tmpl} (100%) rename .ci/magician/cmd/{ => templates/vcr}/vcr_cassettes_update_recording.tmpl (100%) rename .ci/magician/cmd/{ => templates/vcr}/vcr_cassettes_update_replaying.tmpl (100%) rename .ci/magician/cmd/{test_terraform_vcr_with_replay_failed_tests.tmpl => templates/vcr/with_replay_failed_tests.tmpl} (100%) rename .ci/magician/cmd/{test_terraform_vcr_without_replay_failed_tests.tmpl => templates/vcr/without_replay_failed_tests.tmpl} (100%) diff --git a/.ci/magician/cmd/generate_comment.go b/.ci/magician/cmd/generate_comment.go index f1a963d8f3f9..0962a0f71e19 100644 --- a/.ci/magician/cmd/generate_comment.go +++ b/.ci/magician/cmd/generate_comment.go @@ -40,7 +40,7 @@ import ( ) var ( - //go:embed DIFF_COMMENT.md + //go:embed templates/DIFF_COMMENT.md.tmpl diffComment string ) diff --git a/.ci/magician/cmd/interfaces.go b/.ci/magician/cmd/interfaces.go index b7007b89e934..ff4b1a2db97c 100644 --- a/.ci/magician/cmd/interfaces.go +++ b/.ci/magician/cmd/interfaces.go @@ -47,6 +47,7 @@ type ExecRunner interface { PushDir(path string) error PopDir() error WriteFile(name, data string) error + AppendFile(name, data string) error // Not used (yet). Run(name string, args []string, env map[string]string) (string, error) MustRun(name string, args []string, env map[string]string) string } diff --git a/.ci/magician/cmd/mock_runner_test.go b/.ci/magician/cmd/mock_runner_test.go index c3a1abccbde3..166a97412d8f 100644 --- a/.ci/magician/cmd/mock_runner_test.go +++ b/.ci/magician/cmd/mock_runner_test.go @@ -113,6 +113,10 @@ func (mr *mockRunner) WriteFile(name, data string) error { return nil } +func (mr *mockRunner) AppendFile(name, data string) error { + return nil +} + func (mr *mockRunner) Copy(src, dest string) error { mr.calledMethods["Copy"] = append(mr.calledMethods["Copy"], ParameterList{src, dest}) return nil diff --git a/.ci/magician/cmd/scheduled_pr_reminders.go b/.ci/magician/cmd/scheduled_pr_reminders.go index 6cfac38f013c..d0ae3c33041a 100644 --- a/.ci/magician/cmd/scheduled_pr_reminders.go +++ b/.ci/magician/cmd/scheduled_pr_reminders.go @@ -38,13 +38,13 @@ var ( // used for flags dryRun bool - //go:embed SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl + //go:embed templates/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl waitingForContributorTemplate string - //go:embed SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl + //go:embed templates/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl waitingForMergeTemplate string - //go:embed SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl + //go:embed templates/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl waitingForReviewTemplate string ) diff --git a/.ci/magician/cmd/DIFF_COMMENT.md b/.ci/magician/cmd/templates/DIFF_COMMENT.md.tmpl similarity index 100% rename from .ci/magician/cmd/DIFF_COMMENT.md rename to .ci/magician/cmd/templates/DIFF_COMMENT.md.tmpl diff --git a/.ci/magician/cmd/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl b/.ci/magician/cmd/templates/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl similarity index 100% rename from .ci/magician/cmd/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl rename to .ci/magician/cmd/templates/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl diff --git a/.ci/magician/cmd/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl b/.ci/magician/cmd/templates/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl similarity index 100% rename from .ci/magician/cmd/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl rename to .ci/magician/cmd/templates/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl diff --git a/.ci/magician/cmd/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl b/.ci/magician/cmd/templates/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl similarity index 100% rename from .ci/magician/cmd/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl rename to .ci/magician/cmd/templates/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl diff --git a/.ci/magician/cmd/test_terraform_vcr_non_exercised_tests.tmpl b/.ci/magician/cmd/templates/vcr/non_exercised_tests.tmpl similarity index 100% rename from .ci/magician/cmd/test_terraform_vcr_non_exercised_tests.tmpl rename to .ci/magician/cmd/templates/vcr/non_exercised_tests.tmpl diff --git a/.ci/magician/cmd/test_terraform_vcr_record_replay.tmpl b/.ci/magician/cmd/templates/vcr/record_replay.tmpl similarity index 100% rename from .ci/magician/cmd/test_terraform_vcr_record_replay.tmpl rename to .ci/magician/cmd/templates/vcr/record_replay.tmpl diff --git a/.ci/magician/cmd/test_terraform_vcr_test_analytics.tmpl b/.ci/magician/cmd/templates/vcr/test_analytics.tmpl similarity index 100% rename from .ci/magician/cmd/test_terraform_vcr_test_analytics.tmpl rename to .ci/magician/cmd/templates/vcr/test_analytics.tmpl diff --git a/.ci/magician/cmd/vcr_cassettes_update_recording.tmpl b/.ci/magician/cmd/templates/vcr/vcr_cassettes_update_recording.tmpl similarity index 100% rename from .ci/magician/cmd/vcr_cassettes_update_recording.tmpl rename to .ci/magician/cmd/templates/vcr/vcr_cassettes_update_recording.tmpl diff --git a/.ci/magician/cmd/vcr_cassettes_update_replaying.tmpl b/.ci/magician/cmd/templates/vcr/vcr_cassettes_update_replaying.tmpl similarity index 100% rename from .ci/magician/cmd/vcr_cassettes_update_replaying.tmpl rename to .ci/magician/cmd/templates/vcr/vcr_cassettes_update_replaying.tmpl diff --git a/.ci/magician/cmd/test_terraform_vcr_with_replay_failed_tests.tmpl b/.ci/magician/cmd/templates/vcr/with_replay_failed_tests.tmpl similarity index 100% rename from .ci/magician/cmd/test_terraform_vcr_with_replay_failed_tests.tmpl rename to .ci/magician/cmd/templates/vcr/with_replay_failed_tests.tmpl diff --git a/.ci/magician/cmd/test_terraform_vcr_without_replay_failed_tests.tmpl b/.ci/magician/cmd/templates/vcr/without_replay_failed_tests.tmpl similarity index 100% rename from .ci/magician/cmd/test_terraform_vcr_without_replay_failed_tests.tmpl rename to .ci/magician/cmd/templates/vcr/without_replay_failed_tests.tmpl diff --git a/.ci/magician/cmd/test_terraform_vcr.go b/.ci/magician/cmd/test_terraform_vcr.go index 042be4732129..8415339c3340 100644 --- a/.ci/magician/cmd/test_terraform_vcr.go +++ b/.ci/magician/cmd/test_terraform_vcr.go @@ -21,15 +21,15 @@ import ( ) var ( - //go:embed test_terraform_vcr_test_analytics.tmpl + //go:embed templates/vcr/test_analytics.tmpl testsAnalyticsTmplText string - //go:embed test_terraform_vcr_non_exercised_tests.tmpl + //go:embed templates/vcr/non_exercised_tests.tmpl nonExercisedTestsTmplText string - //go:embed test_terraform_vcr_with_replay_failed_tests.tmpl + //go:embed templates/vcr/with_replay_failed_tests.tmpl withReplayFailedTestsTmplText string - //go:embed test_terraform_vcr_without_replay_failed_tests.tmpl + //go:embed templates/vcr/without_replay_failed_tests.tmpl withoutReplayFailedTestsTmplText string - //go:embed test_terraform_vcr_record_replay.tmpl + //go:embed templates/vcr/record_replay.tmpl recordReplayTmplText string ) diff --git a/.ci/magician/cmd/test_terraform_vcr_test.go b/.ci/magician/cmd/test_terraform_vcr_test.go index 393dd5057bb7..251ee2c74263 100644 --- a/.ci/magician/cmd/test_terraform_vcr_test.go +++ b/.ci/magician/cmd/test_terraform_vcr_test.go @@ -476,13 +476,13 @@ func TestWithoutReplayFailedTests(t *testing.T) { data: withoutReplayFailedTests{ ReplayingErr: fmt.Errorf("some error"), BuildID: "build-123", - PRNumber: "pr-123", + PRNumber: "123", }, want: strings.Join( []string{ "$\\textcolor{red}{\\textsf{Errors occurred during REPLAYING mode. Please fix them to complete your PR.}}$", "", - "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/replaying_test.log)", + "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_test.log)", }, "\n", ), @@ -491,13 +491,13 @@ func TestWithoutReplayFailedTests(t *testing.T) { name: "without replay error", data: withoutReplayFailedTests{ BuildID: "build-123", - PRNumber: "pr-123", + PRNumber: "123", }, want: strings.Join( []string{ "$\\textcolor{green}{\\textsf{All tests passed!}}$", "", - "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/replaying_test.log)", + "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_test.log)", }, "\n", ), @@ -536,16 +536,16 @@ func TestRecordReplay(t *testing.T) { HasTerminatedTests: true, RecordingErr: fmt.Errorf("some error"), BuildID: "build-123", - PRNumber: "pr-123", + PRNumber: "123", }, want: strings.Join( []string{ - "$\\textcolor{green}{\\textsf{Tests passed during RECORDING mode:}}$", "`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/a.log)]", - "`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/b.log)]", - "`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/c.log)]", + "$\\textcolor{green}{\\textsf{Tests passed during RECORDING mode:}}$", "`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/a.log)]", + "`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]", + "`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]", "$\\textcolor{red}{\\textsf{Tests failed when rerunning REPLAYING mode:}}$", - "`b`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/b_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/replaying_after_recording/b.log)]", - "`c`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/c_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/replaying_after_recording/c.log)]", + "`b`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/b_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/replaying_after_recording/b.log)]", + "`c`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/c_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/replaying_after_recording/c.log)]", "", "", "Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.", @@ -557,14 +557,14 @@ func TestRecordReplay(t *testing.T) { "", "", "$\\textcolor{red}{\\textsf{Tests failed during RECORDING mode:}}$", - "`d`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/recording_build/d_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/d.log)]", - "`e`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/recording_build/e_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/e.log)]", + "`d`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_build/d_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/d.log)]", + "`e`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_build/e_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/e.log)]", "", "$\\textcolor{red}{\\textsf{Several tests got terminated during RECORDING mode.}}$", "$\\textcolor{red}{\\textsf{Errors occurred during RECORDING mode. Please fix them to complete your PR.}}$", "", "", - "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording) for each test", + "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording) for each test", }, "\n", ), @@ -580,13 +580,13 @@ func TestRecordReplay(t *testing.T) { }, AllRecordingPassed: true, BuildID: "build-123", - PRNumber: "pr-123", + PRNumber: "123", }, want: strings.Join( []string{ - "$\\textcolor{green}{\\textsf{Tests passed during RECORDING mode:}}$", "`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/a.log)]", - "`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/b.log)]", - "`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/c.log)]", + "$\\textcolor{green}{\\textsf{Tests passed during RECORDING mode:}}$", "`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/a.log)]", + "`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]", + "`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]", "", "$\\textcolor{green}{\\textsf{No issues found for passed tests after REPLAYING rerun.}}$", "", @@ -597,7 +597,7 @@ func TestRecordReplay(t *testing.T) { "", "$\\textcolor{green}{\\textsf{All tests passed!}}$", "", - "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording) for each test", + "View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording) for each test", }, "\n", ), diff --git a/.ci/magician/cmd/vcr_cassette_update.go b/.ci/magician/cmd/vcr_cassette_update.go index bcf6642e6586..a7cff89e8582 100644 --- a/.ci/magician/cmd/vcr_cassette_update.go +++ b/.ci/magician/cmd/vcr_cassette_update.go @@ -39,9 +39,9 @@ var vcuEnvironmentVariables = [...]string{ } var ( - //go:embed vcr_cassettes_update_replaying.tmpl + //go:embed templates/vcr/vcr_cassettes_update_replaying.tmpl replayingTmplText string - //go:embed vcr_cassettes_update_recording.tmpl + //go:embed templates/vcr/vcr_cassettes_update_recording.tmpl recordingTmplText string ) diff --git a/.ci/magician/exec/runner.go b/.ci/magician/exec/runner.go index 4d85ece99189..c1bdc79525c5 100644 --- a/.ci/magician/exec/runner.go +++ b/.ci/magician/exec/runner.go @@ -100,6 +100,19 @@ func (ar *Runner) ReadFile(name string) (string, error) { return string(data), nil } +// Note: This is not used yet. +func (ar *Runner) AppendFile(name, data string) error { + f, err := os.OpenFile(ar.abs(name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return fmt.Errorf("error opening file %s: %v", name, err) + } + defer f.Close() + if _, err := f.Write([]byte(data)); err != nil { + return fmt.Errorf("error writing to file %s: %v", name, err) + } + return nil +} + // Run the given command with the given args and env, return output and error if any func (ar *Runner) Run(name string, args []string, env map[string]string) (string, error) { cmd := exec.Command(name, args...)