From 238ef11784dc814aeba792bb9af842597b1dcef6 Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Fri, 8 Nov 2024 12:08:24 -0800 Subject: [PATCH 1/2] Add vcr merge for EAP --- .ci/magician/cmd/vcr_merge_eap.go | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .ci/magician/cmd/vcr_merge_eap.go diff --git a/.ci/magician/cmd/vcr_merge_eap.go b/.ci/magician/cmd/vcr_merge_eap.go new file mode 100644 index 000000000000..3a28eeea28b3 --- /dev/null +++ b/.ci/magician/cmd/vcr_merge_eap.go @@ -0,0 +1,66 @@ +package cmd + +import ( + "fmt" + "magician/exec" + "magician/github" + "magician/source" + "os" + + "github.com/spf13/cobra" +) + +var vcrMergeEapCmd = &cobra.Command{ + Use: "vcr-merge-eap", + Short: "Merge VCR cassettes for EAP", + Long: `This command is triggered in .ci/gcb-push-downstream.yml to merge vcr cassettes. + + The command expects the following as arguments: + 1. CL number + + It then performs the following operations: + 1. Run gsutil to list, copy, and remove the vcr cassettes fixtures. + `, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clNumber := args[0] + fmt.Println("CL number:", clNumber) + + githubToken, ok := os.LookupEnv("GITHUB_TOKEN_CLASSIC") + if !ok { + return fmt.Errorf("did not provide GITHUB_TOKEN_CLASSIC environment variable") + } + + baseBranch := os.Getenv("BASE_BRANCH") + if baseBranch == "" { + return fmt.Errorf("environment variable BASE_BRANCH is empty") + } + + rnr, err := exec.NewRunner() + if err != nil { + return fmt.Errorf("error creating Runner: %w", err) + } + + gh := github.NewClient(githubToken) + return execVCRMergeEAP(gh, clNumber, baseBranch, rnr) + }, +} + +func execVCRMergeEAP(gh GithubClient, clNumber, baseBranch string, runner source.Runner) error { + head := "auto-cl-" + clNumber + var branchPath string + if baseBranch != "main" { + branchPath = "/refs/heads/" + baseBranch + } + mergeCassettes( + "gs://ci-vcr-cassettes/private", + branchPath, + fmt.Sprintf("refs/heads/%s", head), + runner, + ) + return nil +} + +func init() { + rootCmd.AddCommand(vcrMergeEapCmd) +} From b03665f3c0d0db31dfa0a388b5ac2700bbcbe37e Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Wed, 4 Dec 2024 21:08:30 +0000 Subject: [PATCH 2/2] Fix merge cassettes parameters --- .ci/magician/cmd/vcr_merge_eap.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.ci/magician/cmd/vcr_merge_eap.go b/.ci/magician/cmd/vcr_merge_eap.go index 3a28eeea28b3..5797f0aaf52d 100644 --- a/.ci/magician/cmd/vcr_merge_eap.go +++ b/.ci/magician/cmd/vcr_merge_eap.go @@ -48,16 +48,7 @@ var vcrMergeEapCmd = &cobra.Command{ func execVCRMergeEAP(gh GithubClient, clNumber, baseBranch string, runner source.Runner) error { head := "auto-cl-" + clNumber - var branchPath string - if baseBranch != "main" { - branchPath = "/refs/heads/" + baseBranch - } - mergeCassettes( - "gs://ci-vcr-cassettes/private", - branchPath, - fmt.Sprintf("refs/heads/%s", head), - runner, - ) + mergeCassettes("gs://ci-vcr-cassettes/private", baseBranch, fmt.Sprintf("refs/heads/%s", head), runner) return nil }