feat(healthcheck): run joj3-check-env
All checks were successful
submodules sync / sync (push) Successful in 51s
build / build (push) Successful in 1m48s
build / trigger-build-image (push) Successful in 8s

This commit is contained in:
张泊明518370910136 2025-01-31 19:23:05 -05:00
parent 797161940f
commit 3d828b6168
GPG Key ID: D47306D7062CDA9D
3 changed files with 11 additions and 27 deletions

View File

@ -6,7 +6,6 @@ import (
"fmt"
"log/slog"
"os"
"strings"
"github.com/joint-online-judge/JOJ3/internal/conf"
"github.com/joint-online-judge/JOJ3/pkg/healthcheck"
@ -60,20 +59,8 @@ func init() {
}
func prepareTeapotCheck() (
confObj *conf.Conf, groups []string, actor, repoName string, err error,
confObj *conf.Conf, groups []string, err error,
) {
actor = os.Getenv("GITHUB_ACTOR")
repository := os.Getenv("GITHUB_REPOSITORY")
if actor == "" ||
repository == "" ||
strings.Count(repository, "/") != 1 ||
confPath == "" {
slog.Error("teapot env not set", "actor", actor, "repository", repository, "confPath", confPath, "env", os.Environ())
err = fmt.Errorf("teapot env not set")
return
}
repoParts := strings.Split(repository, "/")
repoName = repoParts[1]
commitMsg, err := conf.GetCommitMsg()
if err != nil {
slog.Error("get commit msg", "error", err)
@ -108,13 +95,13 @@ func main() {
"meta", metaFile,
)
var err error
confObj, groups, actor, repoName, err := prepareTeapotCheck()
confObj, groups, err := prepareTeapotCheck()
if err != nil {
slog.Error("prepare teapot check", "error", err)
confObj = nil
}
res := healthcheck.All(
confObj, actor, repoName, rootDir, checkFileNameList, checkFileSumList,
confObj, rootDir, checkFileNameList, checkFileSumList,
groups, metaFile, repoSize,
)
jsonRes, err := json.Marshal(res)

View File

@ -13,13 +13,13 @@ type Result struct {
func All(
confObj *conf.Conf,
actor, repoName, rootDir, checkFileNameList, checkFileSumList string,
rootDir, checkFileNameList, checkFileSumList string,
groups, metaFile []string,
repoSize float64,
) (res Result) {
var err error
if confObj != nil {
output, err := TeapotCheck(confObj, actor, repoName, groups)
output, err := TeapotCheck(confObj, groups)
if err != nil {
res.Msg += fmt.Sprintf("### Teapot Check Failed:\n%s\n", output)
res.Failed = true

View File

@ -19,9 +19,8 @@ type CheckResult struct {
TimePeriod int `json:"time_period"`
}
func runTeapot(conf *conf.Conf, actor, repoName string) (checkResults []CheckResult, err error) {
func runTeapot(conf *conf.Conf) (checkResults []CheckResult, err error) {
os.Setenv("LOG_FILE_PATH", conf.Teapot.LogPath)
os.Setenv("_TYPER_STANDARD_TRACEBACK", "1")
var formattedGroups []string
for _, group := range conf.Teapot.Groups {
groupConfig := fmt.Sprintf("%s=%d:%d",
@ -29,9 +28,9 @@ func runTeapot(conf *conf.Conf, actor, repoName string) (checkResults []CheckRes
formattedGroups = append(formattedGroups, groupConfig)
}
args := []string{
"joj3-check", conf.Teapot.EnvFilePath,
actor, conf.Teapot.GradingRepoName, repoName,
conf.Teapot.ScoreboardPath, conf.Name,
"joj3-check-env", conf.Teapot.EnvFilePath,
conf.Teapot.GradingRepoName,
conf.Teapot.ScoreboardPath,
"--group-config", strings.Join(formattedGroups, ","),
}
var stdoutBuf, stderrBuf bytes.Buffer
@ -90,10 +89,8 @@ func generateOutput(
return
}
func TeapotCheck(
conf *conf.Conf, actor, repoName string, groups []string,
) (output string, err error) {
checkResults, err := runTeapot(conf, actor, repoName)
func TeapotCheck(conf *conf.Conf, groups []string) (output string, err error) {
checkResults, err := runTeapot(conf)
if err != nil {
slog.Error("teapot check", "error", err)
return