feat: run real teapot commands
All checks were successful
build / build (push) Successful in 1m45s
build / build (pull_request) Successful in 1m57s
build / trigger-build-image (push) Has been skipped
build / trigger-build-image (pull_request) Has been skipped

This commit is contained in:
张泊明518370910136 2024-10-07 01:21:03 -04:00
parent 801f9368d9
commit 99235e7c93
GPG Key ID: D47306D7062CDA9D
2 changed files with 42 additions and 3 deletions

View File

@ -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

View File

@ -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
}