Compare commits

..

No commits in common. "3780ae004beb6f179ef42617c2de60a1d248d09d" and "d56e3e5ebc642b67017318a3f2b3f5d05b902bc5" have entirely different histories.

5 changed files with 19 additions and 40 deletions

View File

@ -1,7 +1,6 @@
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"
@ -69,24 +68,19 @@ func generateStages(conf *conf.Conf, group string) ([]stage.Stage, error) {
return stages, nil return stages, nil
} }
func newErrorStageResults(err error) []stage.StageResult { func Run(conf *conf.Conf, group string) (
return []stage.StageResult{ stageResults []stage.StageResult, forceQuit bool, err error,
) {
stageResultsOnError := []stage.StageResult{
{ {
Name: "Internal Error", Name: "Internal Error",
Results: []stage.ParserResult{{ Results: []stage.ParserResult{{
Score: 0, Score: 0,
Comment: "JOJ3 internal error, " + Comment: "JOJ3 internal error, check the log in Gitea Actions.",
"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,
@ -94,7 +88,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 = newErrorStageResults(err) stageResults = stageResultsOnError
forceQuit = true forceQuit = true
return return
} }
@ -102,7 +96,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 = newErrorStageResults(err) stageResults = stageResultsOnError
forceQuit = true forceQuit = true
return return
} }

View File

@ -17,15 +17,13 @@ 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[conf.Stdout] stdout := executorResult.Files["stdout"]
stderr := executorResult.Files[conf.Stderr] stderr := executorResult.Files["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,8 +19,6 @@ 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 {
@ -33,8 +31,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[conf.Stdout] // stdout := executorResult.Files["stdout"]
stderr := executorResult.Files[conf.Stderr] stderr := executorResult.Files["stderr"]
if executorResult.Status != stage.Status(envexec.StatusAccepted) { if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{ return stage.ParserResult{

View File

@ -9,19 +9,14 @@ import (
type Healthcheck struct{} type Healthcheck struct{}
type Conf struct { func Parse(executorResult stage.ExecutorResult) (stage.ParserResult, bool) {
Stdout string `default:"stdout"` stdout := executorResult.Files["stdout"]
Stderr string `default:"stderr"` stderr := executorResult.Files["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.\n`stdout`: ```%s\n```\n`stderr`: ```%s\n```", "Unexpected executor status: %s.\nStdout: %s\nStderr: %s",
executorResult.Status, stdout, stderr, executorResult.Status, stdout, stderr,
), ),
}, true }, true
@ -35,14 +30,10 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult,
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, *conf) parserResult, forceQuitResult := Parse(result)
res = append(res, parserResult) res = append(res, parserResult)
forceQuit = forceQuit || forceQuitResult forceQuit = forceQuit || forceQuitResult
} }

View File

@ -12,15 +12,13 @@ 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[conf.Stdout] stdout := executorResult.Files["stdout"]
stderr := executorResult.Files[conf.Stderr] stderr := executorResult.Files["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,