Compare commits

...

2 Commits

Author SHA1 Message Date
e785ce2860
refactor(cmd/joj3): move stage to main package
All checks were successful
submodules sync / sync (push) Successful in 48s
build / build (push) Successful in 1m53s
build / trigger-build-image (push) Successful in 9s
2025-02-18 06:32:47 -05:00
1150cc4697
docs: better packages docs 2025-02-18 06:21:17 -05:00
11 changed files with 29 additions and 35 deletions

View File

@ -11,8 +11,7 @@ import (
joj3Conf "github.com/joint-online-judge/JOJ3/cmd/joj3/conf" 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/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/cmd/joj3/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
internalStage "github.com/joint-online-judge/JOJ3/internal/stage"
) )
var ( var (
@ -92,11 +91,11 @@ func mainImpl() (err error) {
groups := joj3Conf.MatchGroups(conf, conventionalCommit) groups := joj3Conf.MatchGroups(conf, conventionalCommit)
env.Attr.Groups = strings.Join(groups, ",") env.Attr.Groups = strings.Join(groups, ",")
env.Set() env.Set()
_, forceQuitStageName, err := stage.Run( _, forceQuitStageName, err := runStages(
conf, conf,
groups, groups,
func( func(
stageResults []internalStage.StageResult, stageResults []stage.StageResult,
forceQuitStageName string, forceQuitStageName string,
) { ) {
env.Attr.ForceQuitStageName = forceQuitStageName env.Attr.ForceQuitStageName = forceQuitStageName

View File

@ -1,12 +1,14 @@
package stage package main
import ( import (
"encoding/json"
"fmt" "fmt"
"log/slog" "log/slog"
"os"
"strings" "strings"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf" "github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
executors "github.com/joint-online-judge/JOJ3/internal/executor" "github.com/joint-online-judge/JOJ3/internal/executor"
_ "github.com/joint-online-judge/JOJ3/internal/parser" _ "github.com/joint-online-judge/JOJ3/internal/parser"
"github.com/joint-online-judge/JOJ3/internal/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
@ -132,14 +134,14 @@ func newErrorStageResults(err error) ([]stage.StageResult, string) {
}, "Internal Error" }, "Internal Error"
} }
func Run( func runStages(
conf *conf.Conf, conf *conf.Conf,
groups []string, groups []string,
onStagesComplete func([]stage.StageResult, string), onStagesComplete func([]stage.StageResult, string),
) ( ) (
stageResults []stage.StageResult, forceQuitStageName string, err error, stageResults []stage.StageResult, forceQuitStageName string, err error,
) { ) {
executors.InitWithConf( executor.InitWithConf(
conf.Stage.SandboxExecServer, conf.Stage.SandboxExecServer,
conf.Stage.SandboxToken, conf.Stage.SandboxToken,
) )
@ -175,8 +177,16 @@ func Run(
stageResults, forceQuitStageName = newErrorStageResults(err) stageResults, forceQuitStageName = newErrorStageResults(err)
} }
onStagesComplete(stageResults, forceQuitStageName) onStagesComplete(stageResults, forceQuitStageName)
slog.Info("write stageResults") slog.Info("output result start", "path", conf.Stage.OutputPath)
if err = Write(conf.Stage.OutputPath, stageResults); err != nil { 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.Error("write stageResults", "error", err) slog.Error("write stageResults", "error", err)
} }
slog.Info("run postStages") slog.Info("run postStages")

View File

@ -1,20 +0,0 @@
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)
}

View File

@ -1,4 +1,5 @@
package executors // Package executor contains all the executors.
package executor
import ( import (
_ "github.com/joint-online-judge/JOJ3/internal/executor/dummy" _ "github.com/joint-online-judge/JOJ3/internal/executor/dummy"

View File

@ -1,4 +1,5 @@
package parsers // Package parser contains all the parsers.
package parser
import ( import (
_ "github.com/joint-online-judge/JOJ3/internal/parser/clangtidy" _ "github.com/joint-online-judge/JOJ3/internal/parser/clangtidy"

View File

@ -1,4 +1,3 @@
// Referenced from https://github.com/yuriisk/clang-tidy-converter/blob/master/clang_tidy_converter/parser/clang_tidy_parser.py
package clangtidy package clangtidy
import ( import (
@ -9,6 +8,7 @@ import (
"strings" "strings"
) )
// Referenced from https://github.com/yuriisk/clang-tidy-converter/blob/master/clang_tidy_converter/parser/clang_tidy_parser.py
type Level int type Level int
const ( const (

View File

@ -2,7 +2,6 @@
// dynamically. It is used for custom parsers. // dynamically. It is used for custom parsers.
// The plugin needs to be located at `ModPath` and export a symbol with name // The plugin needs to be located at `ModPath` and export a symbol with name
// `SymName` that implements the stage.Parser interface. // `SymName` that implements the stage.Parser interface.
package plugin package plugin
import "github.com/joint-online-judge/JOJ3/internal/stage" import "github.com/joint-online-judge/JOJ3/internal/stage"

View File

@ -1,6 +1,5 @@
// Package tierscore provides a parser for tiered scoring based on // Package tierscore provides a parser for tiered scoring based on
// time and memory constraints. Leave the field empty or 0 to disable. // time and memory constraints. Leave the field empty or 0 to disable.
package tierscore package tierscore
import "github.com/joint-online-judge/JOJ3/internal/stage" import "github.com/joint-online-judge/JOJ3/internal/stage"

View File

@ -1,3 +1,6 @@
// 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 package stage
import ( import (

View File

@ -1,3 +1,4 @@
// Package healthcheck provides a set of health checks for a repository.
package healthcheck package healthcheck
import ( import (

View File

@ -1,3 +1,4 @@
// Package sample provides a sample function that returns a Result.
package sample package sample
import ( import (