Compare commits
	
		
			3 Commits
		
	
	
		
			d56e3e5ebc
			...
			3780ae004b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3780ae004b | |||
| 132a50833b | |||
| cda3faeb9a | 
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package stage
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log/slog"
 | 
			
		||||
 | 
			
		||||
	"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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Run(conf *conf.Conf, group string) (
 | 
			
		||||
	stageResults []stage.StageResult, forceQuit bool, err error,
 | 
			
		||||
) {
 | 
			
		||||
	stageResultsOnError := []stage.StageResult{
 | 
			
		||||
func newErrorStageResults(err error) []stage.StageResult {
 | 
			
		||||
	return []stage.StageResult{
 | 
			
		||||
		{
 | 
			
		||||
			Name: "Internal Error",
 | 
			
		||||
			Results: []stage.ParserResult{{
 | 
			
		||||
				Score:   0,
 | 
			
		||||
				Comment: "JOJ3 internal error, check the log in Gitea Actions.",
 | 
			
		||||
				Score: 0,
 | 
			
		||||
				Comment: "JOJ3 internal error, " +
 | 
			
		||||
					"check the log in Gitea Actions.\n" +
 | 
			
		||||
					fmt.Sprintf("Error: `%s`", err),
 | 
			
		||||
			}},
 | 
			
		||||
			ForceQuit: true,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Run(conf *conf.Conf, group string) (
 | 
			
		||||
	stageResults []stage.StageResult, forceQuit bool, err error,
 | 
			
		||||
) {
 | 
			
		||||
	executors.InitWithConf(
 | 
			
		||||
		conf.Stage.SandboxExecServer,
 | 
			
		||||
		conf.Stage.SandboxToken,
 | 
			
		||||
| 
						 | 
				
			
			@ -88,7 +94,7 @@ func Run(conf *conf.Conf, group string) (
 | 
			
		|||
	stages, err := generateStages(conf, group)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		slog.Error("generate stages", "error", err)
 | 
			
		||||
		stageResults = stageResultsOnError
 | 
			
		||||
		stageResults = newErrorStageResults(err)
 | 
			
		||||
		forceQuit = true
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +102,7 @@ func Run(conf *conf.Conf, group string) (
 | 
			
		|||
	stageResults, forceQuit, err = stage.Run(stages)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		slog.Error("run stages", "error", err)
 | 
			
		||||
		stageResults = stageResultsOnError
 | 
			
		||||
		stageResults = newErrorStageResults(err)
 | 
			
		||||
		forceQuit = true
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,13 +17,15 @@ type Conf struct {
 | 
			
		|||
	Score   int    `default:"100"`
 | 
			
		||||
	RootDir string `default:"/w"`
 | 
			
		||||
	Matches []Match
 | 
			
		||||
	Stdout  string `default:"stdout"`
 | 
			
		||||
	Stderr  string `default:"stderr"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ClangTidy struct{}
 | 
			
		||||
 | 
			
		||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
 | 
			
		||||
	stdout := executorResult.Files["stdout"]
 | 
			
		||||
	stderr := executorResult.Files["stderr"]
 | 
			
		||||
	stdout := executorResult.Files[conf.Stdout]
 | 
			
		||||
	stderr := executorResult.Files[conf.Stderr]
 | 
			
		||||
	if executorResult.Status != stage.Status(envexec.StatusAccepted) {
 | 
			
		||||
		if !((executorResult.Status == stage.Status(envexec.StatusNonzeroExitStatus)) &&
 | 
			
		||||
			(executorResult.ExitStatus == 1)) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,6 +19,8 @@ type Match struct {
 | 
			
		|||
type Conf struct {
 | 
			
		||||
	Score   int `default:"100"`
 | 
			
		||||
	Matches []Match
 | 
			
		||||
	Stdout  string `default:"stdout"`
 | 
			
		||||
	Stderr  string `default:"stderr"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Record struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -31,8 +33,8 @@ type Record struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
 | 
			
		||||
	// stdout := executorResult.Files["stdout"]
 | 
			
		||||
	stderr := executorResult.Files["stderr"]
 | 
			
		||||
	// stdout := executorResult.Files[conf.Stdout]
 | 
			
		||||
	stderr := executorResult.Files[conf.Stderr]
 | 
			
		||||
 | 
			
		||||
	if executorResult.Status != stage.Status(envexec.StatusAccepted) {
 | 
			
		||||
		return stage.ParserResult{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,14 +9,19 @@ import (
 | 
			
		|||
 | 
			
		||||
type Healthcheck struct{}
 | 
			
		||||
 | 
			
		||||
func Parse(executorResult stage.ExecutorResult) (stage.ParserResult, bool) {
 | 
			
		||||
	stdout := executorResult.Files["stdout"]
 | 
			
		||||
	stderr := executorResult.Files["stderr"]
 | 
			
		||||
type Conf struct {
 | 
			
		||||
	Stdout string `default:"stdout"`
 | 
			
		||||
	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) {
 | 
			
		||||
		return stage.ParserResult{
 | 
			
		||||
			Score: 0,
 | 
			
		||||
			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,
 | 
			
		||||
			),
 | 
			
		||||
		}, true
 | 
			
		||||
| 
						 | 
				
			
			@ -30,10 +35,14 @@ func Parse(executorResult stage.ExecutorResult) (stage.ParserResult, bool) {
 | 
			
		|||
func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
 | 
			
		||||
	[]stage.ParserResult, bool, error,
 | 
			
		||||
) {
 | 
			
		||||
	conf, err := stage.DecodeConf[Conf](confAny)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, true, err
 | 
			
		||||
	}
 | 
			
		||||
	var res []stage.ParserResult
 | 
			
		||||
	forceQuit := false
 | 
			
		||||
	for _, result := range results {
 | 
			
		||||
		parserResult, forceQuitResult := Parse(result)
 | 
			
		||||
		parserResult, forceQuitResult := Parse(result, *conf)
 | 
			
		||||
		res = append(res, parserResult)
 | 
			
		||||
		forceQuit = forceQuit || forceQuitResult
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,13 +12,15 @@ import (
 | 
			
		|||
type Conf struct {
 | 
			
		||||
	Score   int
 | 
			
		||||
	Comment string
 | 
			
		||||
	Stdout  string `default:"stdout"`
 | 
			
		||||
	Stderr  string `default:"stderr"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Sample struct{}
 | 
			
		||||
 | 
			
		||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
 | 
			
		||||
	stdout := executorResult.Files["stdout"]
 | 
			
		||||
	stderr := executorResult.Files["stderr"]
 | 
			
		||||
	stdout := executorResult.Files[conf.Stdout]
 | 
			
		||||
	stderr := executorResult.Files[conf.Stderr]
 | 
			
		||||
	if executorResult.Status != stage.Status(envexec.StatusAccepted) {
 | 
			
		||||
		return stage.ParserResult{
 | 
			
		||||
			Score: 0,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user