refactor(cmd/joj): re-group conf
This commit is contained in:
		
							parent
							
								
									b46e22471f
								
							
						
					
					
						commit
						872adf1621
					
				| 
						 | 
					@ -14,15 +14,20 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Conf struct {
 | 
					type Conf struct {
 | 
				
			||||||
 | 
						Name    string `default:"unknown"`
 | 
				
			||||||
 | 
						LogPath string `default:""`
 | 
				
			||||||
 | 
						Stage   struct {
 | 
				
			||||||
		SandboxExecServer string `default:"localhost:5051"`
 | 
							SandboxExecServer string `default:"localhost:5051"`
 | 
				
			||||||
		SandboxToken      string `default:""`
 | 
							SandboxToken      string `default:""`
 | 
				
			||||||
	LogPath           string `default:""`
 | 
							OutputPath        string `default:"stages_result.json"`
 | 
				
			||||||
	OutputPath        string `default:"joj3_result.json"`
 | 
						}
 | 
				
			||||||
	GradingRepoName   string `default:""`
 | 
						Teapot struct {
 | 
				
			||||||
	SkipTeapot        bool   `default:"true"`
 | 
							Skip            bool   `default:"true"`
 | 
				
			||||||
 | 
							LogPath         string `default:"/home/tt/.cache/joint-teapot-debug.log"`
 | 
				
			||||||
		ScoreboardPath  string `default:"scoreboard.csv"`
 | 
							ScoreboardPath  string `default:"scoreboard.csv"`
 | 
				
			||||||
		FailedTablePath string `default:"failed-table.md"`
 | 
							FailedTablePath string `default:"failed-table.md"`
 | 
				
			||||||
	Name              string `default:"unknown"`
 | 
							GradingRepoName string `default:""`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	Stages []struct {
 | 
						Stages []struct {
 | 
				
			||||||
		Name     string
 | 
							Name     string
 | 
				
			||||||
		Group    string
 | 
							Group    string
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,7 +74,10 @@ func outputResult(outputPath string, results []stage.StageResult) error {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Run(conf conf.Conf, group string) error {
 | 
					func Run(conf conf.Conf, group string) error {
 | 
				
			||||||
	executors.InitWithConf(conf.SandboxExecServer, conf.SandboxToken)
 | 
						executors.InitWithConf(
 | 
				
			||||||
 | 
							conf.Stage.SandboxExecServer,
 | 
				
			||||||
 | 
							conf.Stage.SandboxToken,
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
	stages, err := generateStages(conf, group)
 | 
						stages, err := generateStages(conf, group)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		slog.Error("generate stages", "error", err)
 | 
							slog.Error("generate stages", "error", err)
 | 
				
			||||||
| 
						 | 
					@ -86,7 +89,7 @@ func Run(conf conf.Conf, group string) error {
 | 
				
			||||||
		slog.Error("run stages", "error", err)
 | 
							slog.Error("run stages", "error", err)
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := outputResult(conf.OutputPath, results); err != nil {
 | 
						if err := outputResult(conf.Stage.OutputPath, results); err != nil {
 | 
				
			||||||
		slog.Error("output result", "error", err)
 | 
							slog.Error("output result", "error", err)
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,10 +12,10 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Run(conf conf.Conf) error {
 | 
					func Run(conf conf.Conf) error {
 | 
				
			||||||
	if conf.SkipTeapot {
 | 
						if conf.Teapot.Skip {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	os.Setenv("LOG_FILE_PATH", "/home/tt/.cache/joint-teapot-debug.log")
 | 
						os.Setenv("LOG_FILE_PATH", conf.Teapot.LogPath)
 | 
				
			||||||
	os.Setenv("_TYPER_STANDARD_TRACEBACK", "1")
 | 
						os.Setenv("_TYPER_STANDARD_TRACEBACK", "1")
 | 
				
			||||||
	envFilePath := "/home/tt/.config/teapot/teapot.env"
 | 
						envFilePath := "/home/tt/.config/teapot/teapot.env"
 | 
				
			||||||
	actor := os.Getenv("GITHUB_ACTOR")
 | 
						actor := os.Getenv("GITHUB_ACTOR")
 | 
				
			||||||
| 
						 | 
					@ -30,8 +30,8 @@ func Run(conf conf.Conf) error {
 | 
				
			||||||
	repoName := repoParts[1]
 | 
						repoName := repoParts[1]
 | 
				
			||||||
	re := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
 | 
						re := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
 | 
				
			||||||
	cmd := exec.Command("joint-teapot", "joj3-scoreboard",
 | 
						cmd := exec.Command("joint-teapot", "joj3-scoreboard",
 | 
				
			||||||
		envFilePath, conf.OutputPath, actor, conf.GradingRepoName, repoName,
 | 
							envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
 | 
				
			||||||
		runNumber, conf.ScoreboardPath, conf.Name) // #nosec G204
 | 
							repoName, runNumber, conf.Teapot.ScoreboardPath, conf.Name) // #nosec G204
 | 
				
			||||||
	outputBytes, err := cmd.CombinedOutput()
 | 
						outputBytes, err := cmd.CombinedOutput()
 | 
				
			||||||
	output := re.ReplaceAllString(string(outputBytes), "")
 | 
						output := re.ReplaceAllString(string(outputBytes), "")
 | 
				
			||||||
	for _, line := range strings.Split(output, "\n") {
 | 
						for _, line := range strings.Split(output, "\n") {
 | 
				
			||||||
| 
						 | 
					@ -45,8 +45,8 @@ func Run(conf conf.Conf) error {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cmd = exec.Command("joint-teapot", "joj3-failed-table",
 | 
						cmd = exec.Command("joint-teapot", "joj3-failed-table",
 | 
				
			||||||
		envFilePath, conf.OutputPath, actor, conf.GradingRepoName, repoName,
 | 
							envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
 | 
				
			||||||
		runNumber, conf.FailedTablePath, conf.Name) // #nosec G204
 | 
							repoName, runNumber, conf.Teapot.FailedTablePath, conf.Name) // #nosec G204
 | 
				
			||||||
	outputBytes, err = cmd.CombinedOutput()
 | 
						outputBytes, err = cmd.CombinedOutput()
 | 
				
			||||||
	output = re.ReplaceAllString(string(outputBytes), "")
 | 
						output = re.ReplaceAllString(string(outputBytes), "")
 | 
				
			||||||
	for _, line := range strings.Split(output, "\n") {
 | 
						for _, line := range strings.Split(output, "\n") {
 | 
				
			||||||
| 
						 | 
					@ -60,7 +60,7 @@ func Run(conf conf.Conf) error {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cmd = exec.Command("joint-teapot", "joj3-create-result-issue",
 | 
						cmd = exec.Command("joint-teapot", "joj3-create-result-issue",
 | 
				
			||||||
		envFilePath, conf.OutputPath, repoName, runNumber, conf.Name) // #nosec G204
 | 
							envFilePath, conf.Stage.OutputPath, repoName, runNumber, conf.Name) // #nosec G204
 | 
				
			||||||
	outputBytes, err = cmd.CombinedOutput()
 | 
						outputBytes, err = cmd.CombinedOutput()
 | 
				
			||||||
	output = re.ReplaceAllString(string(outputBytes), "")
 | 
						output = re.ReplaceAllString(string(outputBytes), "")
 | 
				
			||||||
	for _, line := range strings.Split(output, "\n") {
 | 
						for _, line := range strings.Split(output, "\n") {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user