Compare commits
No commits in common. "e785ce2860e5259b16000540a477276ec2813d23" and "e9c3172e9afd6f8e793fb678d64e87db81f52cf8" have entirely different histories.
e785ce2860
...
e9c3172e9a
|
@ -11,7 +11,8 @@ import (
|
|||
|
||||
joj3Conf "github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
|
||||
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
|
||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
"github.com/joint-online-judge/JOJ3/cmd/joj3/stage"
|
||||
internalStage "github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -91,11 +92,11 @@ func mainImpl() (err error) {
|
|||
groups := joj3Conf.MatchGroups(conf, conventionalCommit)
|
||||
env.Attr.Groups = strings.Join(groups, ",")
|
||||
env.Set()
|
||||
_, forceQuitStageName, err := runStages(
|
||||
_, forceQuitStageName, err := stage.Run(
|
||||
conf,
|
||||
groups,
|
||||
func(
|
||||
stageResults []stage.StageResult,
|
||||
stageResults []internalStage.StageResult,
|
||||
forceQuitStageName string,
|
||||
) {
|
||||
env.Attr.ForceQuitStageName = forceQuitStageName
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package main
|
||||
package stage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
|
||||
"github.com/joint-online-judge/JOJ3/internal/executor"
|
||||
executors "github.com/joint-online-judge/JOJ3/internal/executor"
|
||||
_ "github.com/joint-online-judge/JOJ3/internal/parser"
|
||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
|
||||
|
@ -134,14 +132,14 @@ func newErrorStageResults(err error) ([]stage.StageResult, string) {
|
|||
}, "Internal Error"
|
||||
}
|
||||
|
||||
func runStages(
|
||||
func Run(
|
||||
conf *conf.Conf,
|
||||
groups []string,
|
||||
onStagesComplete func([]stage.StageResult, string),
|
||||
) (
|
||||
stageResults []stage.StageResult, forceQuitStageName string, err error,
|
||||
) {
|
||||
executor.InitWithConf(
|
||||
executors.InitWithConf(
|
||||
conf.Stage.SandboxExecServer,
|
||||
conf.Stage.SandboxToken,
|
||||
)
|
||||
|
@ -177,16 +175,8 @@ func runStages(
|
|||
stageResults, forceQuitStageName = newErrorStageResults(err)
|
||||
}
|
||||
onStagesComplete(stageResults, forceQuitStageName)
|
||||
slog.Info("output result start", "path", conf.Stage.OutputPath)
|
||||
slog.Debug("output result start",
|
||||
"path", conf.Stage.OutputPath, "results", stageResults)
|
||||
content, err := json.Marshal(stageResults)
|
||||
if err != nil {
|
||||
slog.Error("marshal stageResults", "error", err)
|
||||
}
|
||||
err = os.WriteFile(conf.Stage.OutputPath,
|
||||
append(content, []byte("\n")...), 0o600)
|
||||
if err != nil {
|
||||
slog.Info("write stageResults")
|
||||
if err = Write(conf.Stage.OutputPath, stageResults); err != nil {
|
||||
slog.Error("write stageResults", "error", err)
|
||||
}
|
||||
slog.Info("run postStages")
|
20
cmd/joj3/stage/write.go
Normal file
20
cmd/joj3/stage/write.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package stage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
func Write(outputPath string, results []stage.StageResult) error {
|
||||
slog.Info("output result start", "path", outputPath)
|
||||
slog.Debug("output result start", "path", outputPath, "results", results)
|
||||
content, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(outputPath,
|
||||
append(content, []byte("\n")...), 0o600)
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
// Package executor contains all the executors.
|
||||
package executor
|
||||
package executors
|
||||
|
||||
import (
|
||||
_ "github.com/joint-online-judge/JOJ3/internal/executor/dummy"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// Package parser contains all the parsers.
|
||||
package parser
|
||||
package parsers
|
||||
|
||||
import (
|
||||
_ "github.com/joint-online-judge/JOJ3/internal/parser/clangtidy"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Referenced from https://github.com/yuriisk/clang-tidy-converter/blob/master/clang_tidy_converter/parser/clang_tidy_parser.py
|
||||
package clangtidy
|
||||
|
||||
import (
|
||||
|
@ -8,7 +9,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// Referenced from https://github.com/yuriisk/clang-tidy-converter/blob/master/clang_tidy_converter/parser/clang_tidy_parser.py
|
||||
type Level int
|
||||
|
||||
const (
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// dynamically. It is used for custom parsers.
|
||||
// The plugin needs to be located at `ModPath` and export a symbol with name
|
||||
// `SymName` that implements the stage.Parser interface.
|
||||
|
||||
package plugin
|
||||
|
||||
import "github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Package tierscore provides a parser for tiered scoring based on
|
||||
// time and memory constraints. Leave the field empty or 0 to disable.
|
||||
|
||||
package tierscore
|
||||
|
||||
import "github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// Package stage provides functionality to run stages. Each stage contains an
|
||||
// executor and multiple parsers. The executor executes the command and parsers
|
||||
// parse the output generated by the executor.
|
||||
package stage
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// Package healthcheck provides a set of health checks for a repository.
|
||||
package healthcheck
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// Package sample provides a sample function that returns a Result.
|
||||
package sample
|
||||
|
||||
import (
|
||||
|
|
Loading…
Reference in New Issue
Block a user