diff --git a/cmd/joj3/conf/conf.go b/cmd/joj3/conf/conf.go index 02431cb..c385e4e 100644 --- a/cmd/joj3/conf/conf.go +++ b/cmd/joj3/conf/conf.go @@ -18,6 +18,8 @@ type Conf struct { SandboxToken string `default:""` LogPath string `default:""` OutputPath string `default:"joj3_result.json"` + GradingRepoName string `default:""` + SkipTeapot bool `default:"true"` Stages []struct { Name string Group string diff --git a/cmd/joj3/teapot/main.go b/cmd/joj3/teapot/main.go index f001c7b..8cbe38f 100644 --- a/cmd/joj3/teapot/main.go +++ b/cmd/joj3/teapot/main.go @@ -1,20 +1,57 @@ package teapot import ( + "fmt" "log/slog" + "os" "os/exec" + "strings" "github.com/joint-online-judge/JOJ3/cmd/joj3/conf" ) func Run(conf conf.Conf) error { - // TODO: call teapot - cmd := exec.Command("joint-teapot", "--help") + if conf.SkipTeapot { + return nil + } + os.Setenv("LOG_FILE_PATH", "/home/tt/.cache/joint-teapot-debug.log") + os.Setenv("_TYPER_STANDARD_TRACEBACK", "1") + envFilePath := "/home/tt/.config/teapot/teapot.env" + actor := os.Getenv("GITHUB_ACTOR") + repository := os.Getenv("GITHUB_REPOSITORY") + runNumber := os.Getenv("GITHUB_RUN_NUMBER") + if actor == "" || repository == "" || strings.Count(repository, "/") != 1 || + runNumber == "" { + slog.Error("teapot env not set") + return fmt.Errorf("teapot env not set") + } + repoParts := strings.Split(repository, "/") + repoName := repoParts[1] + cmd := exec.Command("joint-teapot", "joj3-scoreboard", + envFilePath, conf.OutputPath, actor, conf.GradingRepoName, repoName, + runNumber) // #nosec G204 output, err := cmd.CombinedOutput() if err != nil { slog.Error("running git command:", "err", err) return err } - slog.Info("joint-teapot run", "output", string(output)) + slog.Info("joint-teapot joj3-scoreboard", "output", string(output)) + cmd = exec.Command("joint-teapot", "joj3-failed-table", + envFilePath, conf.OutputPath, actor, conf.GradingRepoName, repoName, + runNumber) // #nosec G204 + output, err = cmd.CombinedOutput() + if err != nil { + slog.Error("running git command:", "err", err) + return err + } + slog.Info("joint-teapot joj3-failed-table", "output", string(output)) + cmd = exec.Command("joint-teapot", "joj3-create-result-issue", + envFilePath, conf.OutputPath, repoName, runNumber) // #nosec G204 + output, err = cmd.CombinedOutput() + if err != nil { + slog.Error("running git command:", "err", err) + return err + } + slog.Info("joint-teapot joj3-create-result-issue", "output", string(output)) return nil }