feat(cmd/joj3): pass conf.Conf by pointer
All checks were successful
build / build (push) Successful in 1m4s
build / trigger-build-image (push) Successful in 7s

This commit is contained in:
张泊明518370910136 2024-10-12 07:16:13 -04:00
parent 9cd0e44678
commit 4e3d202fa9
GPG Key ID: D47306D7062CDA9D
3 changed files with 7 additions and 6 deletions

View File

@ -144,18 +144,19 @@ func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
return cc, nil return cc, nil
} }
func ParseConfFile(path string) (conf Conf, err error) { func ParseConfFile(path string) (conf *Conf, err error) {
conf = new(Conf)
d := &multiconfig.DefaultLoader{} d := &multiconfig.DefaultLoader{}
d.Loader = multiconfig.MultiLoader( d.Loader = multiconfig.MultiLoader(
&multiconfig.TagLoader{}, &multiconfig.TagLoader{},
&multiconfig.JSONLoader{Path: path}, &multiconfig.JSONLoader{Path: path},
) )
d.Validator = multiconfig.MultiValidator(&multiconfig.RequiredValidator{}) d.Validator = multiconfig.MultiValidator(&multiconfig.RequiredValidator{})
if err = d.Load(&conf); err != nil { if err = d.Load(conf); err != nil {
slog.Error("parse stages conf", "error", err) slog.Error("parse stages conf", "error", err)
return return
} }
if err = d.Validate(&conf); err != nil { if err = d.Validate(conf); err != nil {
slog.Error("validate stages conf", "error", err) slog.Error("validate stages conf", "error", err)
return return
} }

View File

@ -13,7 +13,7 @@ import (
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
) )
func generateStages(conf conf.Conf, group string) ([]stage.Stage, error) { func generateStages(conf *conf.Conf, group string) ([]stage.Stage, error) {
stages := []stage.Stage{} stages := []stage.Stage{}
existNames := map[string]bool{} existNames := map[string]bool{}
for _, s := range conf.Stage.Stages { for _, s := range conf.Stage.Stages {
@ -81,7 +81,7 @@ func outputResult(outputPath string, results []stage.StageResult) error {
append(content, []byte("\n")...), 0o600) append(content, []byte("\n")...), 0o600)
} }
func Run(conf conf.Conf, group string) error { func Run(conf *conf.Conf, group string) error {
executors.InitWithConf( executors.InitWithConf(
conf.Stage.SandboxExecServer, conf.Stage.SandboxExecServer,
conf.Stage.SandboxToken, conf.Stage.SandboxToken,

View File

@ -11,7 +11,7 @@ import (
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf" "github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
) )
func Run(conf conf.Conf) error { func Run(conf *conf.Conf) error {
actions := os.Getenv("GITHUB_ACTIONS") actions := os.Getenv("GITHUB_ACTIONS")
if actions != "true" { if actions != "true" {
slog.Info("teapot exit", "GITHUB_ACTIONS", actions) slog.Info("teapot exit", "GITHUB_ACTIONS", actions)