Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vcr merge for EAP #12301

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .ci/magician/cmd/vcr_merge_eap.go
Original file line number Diff line number Diff line change
@@ -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,
roaks3 marked this conversation as resolved.
Show resolved Hide resolved
fmt.Sprintf("refs/heads/%s", head),
runner,
)
return nil
}

func init() {
rootCmd.AddCommand(vcrMergeEapCmd)
}
Loading