Compare commits

...

3 Commits

Author SHA1 Message Date
3780ae004b
feat(cmd/joj3): show internal error msg in stage results
All checks were successful
submodules sync / sync (push) Successful in 40s
build / build (push) Successful in 1m34s
build / trigger-build-image (push) Successful in 7s
2024-10-29 17:29:35 -04:00
132a50833b
chore(parser/healthcheck): output in code format on error 2024-10-29 17:04:27 -04:00
cda3faeb9a
feat(parser): make stdout & stderr file in conf 2024-10-29 17:02:35 -04:00
5 changed files with 40 additions and 19 deletions

View File

@ -1,6 +1,7 @@
package stage package stage
import ( import (
"fmt"
"log/slog" "log/slog"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf" "github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
@ -68,19 +69,24 @@ func generateStages(conf *conf.Conf, group string) ([]stage.Stage, error) {
return stages, nil return stages, nil
} }
func Run(conf *conf.Conf, group string) ( func newErrorStageResults(err error) []stage.StageResult {
stageResults []stage.StageResult, forceQuit bool, err error, return []stage.StageResult{
) {
stageResultsOnError := []stage.StageResult{
{ {
Name: "Internal Error", Name: "Internal Error",
Results: []stage.ParserResult{{ Results: []stage.ParserResult{{
Score: 0, Score: 0,
Comment: "JOJ3 internal error, check the log in Gitea Actions.", Comment: "JOJ3 internal error, " +
"check the log in Gitea Actions.\n" +
fmt.Sprintf("Error: `%s`", err),
}}, }},
ForceQuit: true, ForceQuit: true,
}, },
} }
}
func Run(conf *conf.Conf, group string) (
stageResults []stage.StageResult, forceQuit bool, err error,
) {
executors.InitWithConf( executors.InitWithConf(
conf.Stage.SandboxExecServer, conf.Stage.SandboxExecServer,
conf.Stage.SandboxToken, conf.Stage.SandboxToken,
@ -88,7 +94,7 @@ func Run(conf *conf.Conf, group string) (
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)
stageResults = stageResultsOnError stageResults = newErrorStageResults(err)
forceQuit = true forceQuit = true
return return
} }
@ -96,7 +102,7 @@ func Run(conf *conf.Conf, group string) (
stageResults, forceQuit, err = stage.Run(stages) stageResults, forceQuit, err = stage.Run(stages)
if err != nil { if err != nil {
slog.Error("run stages", "error", err) slog.Error("run stages", "error", err)
stageResults = stageResultsOnError stageResults = newErrorStageResults(err)
forceQuit = true forceQuit = true
return return
} }

View File

@ -17,13 +17,15 @@ type Conf struct {
Score int `default:"100"` Score int `default:"100"`
RootDir string `default:"/w"` RootDir string `default:"/w"`
Matches []Match Matches []Match
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
} }
type ClangTidy struct{} type ClangTidy struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"] stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files["stderr"] stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) { if executorResult.Status != stage.Status(envexec.StatusAccepted) {
if !((executorResult.Status == stage.Status(envexec.StatusNonzeroExitStatus)) && if !((executorResult.Status == stage.Status(envexec.StatusNonzeroExitStatus)) &&
(executorResult.ExitStatus == 1)) { (executorResult.ExitStatus == 1)) {

View File

@ -19,6 +19,8 @@ type Match struct {
type Conf struct { type Conf struct {
Score int `default:"100"` Score int `default:"100"`
Matches []Match Matches []Match
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
} }
type Record struct { type Record struct {
@ -31,8 +33,8 @@ type Record struct {
} }
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
// stdout := executorResult.Files["stdout"] // stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files["stderr"] stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) { if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{ return stage.ParserResult{

View File

@ -9,14 +9,19 @@ import (
type Healthcheck struct{} type Healthcheck struct{}
func Parse(executorResult stage.ExecutorResult) (stage.ParserResult, bool) { type Conf struct {
stdout := executorResult.Files["stdout"] Stdout string `default:"stdout"`
stderr := executorResult.Files["stderr"] Stderr string `default:"stderr"`
}
func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult, bool) {
stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) { if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{ return stage.ParserResult{
Score: 0, Score: 0,
Comment: fmt.Sprintf( Comment: fmt.Sprintf(
"Unexpected executor status: %s.\nStdout: %s\nStderr: %s", "Unexpected executor status: %s.\n`stdout`: ```%s\n```\n`stderr`: ```%s\n```",
executorResult.Status, stdout, stderr, executorResult.Status, stdout, stderr,
), ),
}, true }, true
@ -30,10 +35,14 @@ func Parse(executorResult stage.ExecutorResult) (stage.ParserResult, bool) {
func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) ( func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
var res []stage.ParserResult var res []stage.ParserResult
forceQuit := false forceQuit := false
for _, result := range results { for _, result := range results {
parserResult, forceQuitResult := Parse(result) parserResult, forceQuitResult := Parse(result, *conf)
res = append(res, parserResult) res = append(res, parserResult)
forceQuit = forceQuit || forceQuitResult forceQuit = forceQuit || forceQuitResult
} }

View File

@ -12,13 +12,15 @@ import (
type Conf struct { type Conf struct {
Score int Score int
Comment string Comment string
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
} }
type Sample struct{} type Sample struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"] stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files["stderr"] stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) { if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{ return stage.ParserResult{
Score: 0, Score: 0,