refactor(cmd/joj3)!: conf #51
| 
						 | 
					@ -36,13 +36,14 @@ type Conf struct {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// TODO: allow skip scoreboard/failed table/issue
 | 
					 | 
				
			||||||
	Teapot struct {
 | 
						Teapot struct {
 | 
				
			||||||
		Skip            bool   `default:"true"`
 | 
					 | 
				
			||||||
		LogPath         string `default:"/home/tt/.cache/joint-teapot-debug.log"`
 | 
							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"`
 | 
				
			||||||
		GradingRepoName string `default:""`
 | 
							GradingRepoName string `default:""`
 | 
				
			||||||
 | 
							SkipIssue       bool   `default:"false"`
 | 
				
			||||||
 | 
							SkipScoreboard  bool   `default:"false"`
 | 
				
			||||||
 | 
							SkipFailedTable bool   `default:"false"`
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,12 +12,16 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Run(conf conf.Conf) error {
 | 
					func Run(conf conf.Conf) error {
 | 
				
			||||||
	if conf.Teapot.Skip {
 | 
						actions := os.Getenv("GITHUB_ACTIONS")
 | 
				
			||||||
 | 
						if actions != "true" {
 | 
				
			||||||
 | 
							slog.Info("teapot exit", "GITHUB_ACTIONS", actions)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	os.Setenv("LOG_FILE_PATH", conf.Teapot.LogPath)
 | 
						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"
 | 
				
			||||||
 | 
						// TODO: pass sha to joint-teapot
 | 
				
			||||||
 | 
						// sha := os.Getenv("GITHUB_SHA")
 | 
				
			||||||
	actor := os.Getenv("GITHUB_ACTOR")
 | 
						actor := os.Getenv("GITHUB_ACTOR")
 | 
				
			||||||
	repository := os.Getenv("GITHUB_REPOSITORY")
 | 
						repository := os.Getenv("GITHUB_REPOSITORY")
 | 
				
			||||||
	runNumber := os.Getenv("GITHUB_RUN_NUMBER")
 | 
						runNumber := os.Getenv("GITHUB_RUN_NUMBER")
 | 
				
			||||||
| 
						 | 
					@ -29,49 +33,55 @@ func Run(conf conf.Conf) error {
 | 
				
			||||||
	repoParts := strings.Split(repository, "/")
 | 
						repoParts := strings.Split(repository, "/")
 | 
				
			||||||
	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",
 | 
						if !conf.Teapot.SkipScoreboard {
 | 
				
			||||||
		envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
 | 
							cmd := exec.Command("joint-teapot", "joj3-scoreboard",
 | 
				
			||||||
		repoName, runNumber, conf.Teapot.ScoreboardPath, conf.Name) // #nosec G204
 | 
								envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
 | 
				
			||||||
	outputBytes, err := cmd.CombinedOutput()
 | 
								repoName, runNumber, conf.Teapot.ScoreboardPath, conf.Name) // #nosec G204
 | 
				
			||||||
	output := re.ReplaceAllString(string(outputBytes), "")
 | 
							outputBytes, err := cmd.CombinedOutput()
 | 
				
			||||||
	for _, line := range strings.Split(output, "\n") {
 | 
							output := re.ReplaceAllString(string(outputBytes), "")
 | 
				
			||||||
		if line == "" {
 | 
							for _, line := range strings.Split(output, "\n") {
 | 
				
			||||||
			continue
 | 
								if line == "" {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								slog.Info("joint-teapot joj3-scoreboard", "output", line)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		slog.Info("joint-teapot joj3-scoreboard", "output", line)
 | 
							if err != nil {
 | 
				
			||||||
	}
 | 
								slog.Error("joint-teapot joj3-scoreboard", "err", err)
 | 
				
			||||||
	if err != nil {
 | 
								return err
 | 
				
			||||||
		slog.Error("joint-teapot joj3-scoreboard", "err", err)
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	cmd = exec.Command("joint-teapot", "joj3-failed-table",
 | 
					 | 
				
			||||||
		envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
 | 
					 | 
				
			||||||
		repoName, runNumber, conf.Teapot.FailedTablePath, conf.Name) // #nosec G204
 | 
					 | 
				
			||||||
	outputBytes, err = cmd.CombinedOutput()
 | 
					 | 
				
			||||||
	output = re.ReplaceAllString(string(outputBytes), "")
 | 
					 | 
				
			||||||
	for _, line := range strings.Split(output, "\n") {
 | 
					 | 
				
			||||||
		if line == "" {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		slog.Info("joint-teapot joj3-failed-table", "output", line)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err != nil {
 | 
						if !conf.Teapot.SkipFailedTable {
 | 
				
			||||||
		slog.Error("joint-teapot joj3-failed-table", "err", err)
 | 
							cmd := exec.Command("joint-teapot", "joj3-failed-table",
 | 
				
			||||||
		return err
 | 
								envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
 | 
				
			||||||
	}
 | 
								repoName, runNumber, conf.Teapot.FailedTablePath, conf.Name) // #nosec G204
 | 
				
			||||||
	cmd = exec.Command("joint-teapot", "joj3-create-result-issue",
 | 
							outputBytes, err := cmd.CombinedOutput()
 | 
				
			||||||
		envFilePath, conf.Stage.OutputPath, repoName, runNumber, conf.Name) // #nosec G204
 | 
							output := re.ReplaceAllString(string(outputBytes), "")
 | 
				
			||||||
	outputBytes, err = cmd.CombinedOutput()
 | 
							for _, line := range strings.Split(output, "\n") {
 | 
				
			||||||
	output = re.ReplaceAllString(string(outputBytes), "")
 | 
								if line == "" {
 | 
				
			||||||
	for _, line := range strings.Split(output, "\n") {
 | 
									continue
 | 
				
			||||||
		if line == "" {
 | 
								}
 | 
				
			||||||
			continue
 | 
								slog.Info("joint-teapot joj3-failed-table", "output", line)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								slog.Error("joint-teapot joj3-failed-table", "err", err)
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		slog.Info("joint-teapot joj3-create-result-issue", "output", line)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err != nil {
 | 
						if !conf.Teapot.SkipIssue {
 | 
				
			||||||
		slog.Error("joint-teapot joj3-create-result-issue", "err", err)
 | 
							cmd := exec.Command("joint-teapot", "joj3-create-result-issue",
 | 
				
			||||||
		return err
 | 
								envFilePath, conf.Stage.OutputPath, repoName, runNumber, conf.Name) // #nosec G204
 | 
				
			||||||
 | 
							outputBytes, err := cmd.CombinedOutput()
 | 
				
			||||||
 | 
							output := re.ReplaceAllString(string(outputBytes), "")
 | 
				
			||||||
 | 
							for _, line := range strings.Split(output, "\n") {
 | 
				
			||||||
 | 
								if line == "" {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								slog.Info("joint-teapot joj3-create-result-issue", "output", line)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								slog.Error("joint-teapot joj3-create-result-issue", "err", err)
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user