feat(cmd): load groups from env
All checks were successful
submodules sync / sync (push) Successful in 33s
build / build (push) Successful in 1m5s
build / trigger-build-image (push) Successful in 7s

This commit is contained in:
张泊明518370910136 2025-01-31 21:06:38 -05:00
parent 6ddd403f08
commit e8c6e87b94
GPG Key ID: D47306D7062CDA9D
2 changed files with 12 additions and 14 deletions

12
cmd/joj3/env/env.go vendored
View File

@ -6,6 +6,12 @@ import (
"time"
)
const (
ConfName = "JOJ3_CONF_NAME"
Groups = "JOJ3_GROUPS"
RunID = "JOJ3_RUN_ID"
)
type Attribute struct {
ConfName string
Groups string
@ -42,7 +48,7 @@ func init() {
}
func Set() {
os.Setenv("JOJ3_CONF_NAME", Attr.ConfName)
os.Setenv("JOJ3_GROUPS", Attr.Groups)
os.Setenv("JOJ3_RUN_ID", Attr.RunID)
os.Setenv(ConfName, Attr.ConfName)
os.Setenv(Groups, Attr.Groups)
os.Setenv(RunID, Attr.RunID)
}

View File

@ -6,7 +6,9 @@ import (
"fmt"
"log/slog"
"os"
"strings"
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/internal/conf"
"github.com/joint-online-judge/JOJ3/pkg/healthcheck"
)
@ -61,22 +63,12 @@ func init() {
func prepareTeapotCheck() (
confObj *conf.Conf, groups []string, err error,
) {
commitMsg, err := conf.GetCommitMsg()
if err != nil {
slog.Error("get commit msg", "error", err)
return
}
conventionalCommit, err := conf.ParseConventionalCommit(commitMsg)
if err != nil {
slog.Error("parse commit msg", "error", err)
return
}
confObj, err = conf.ParseConfFile(confPath)
if err != nil {
slog.Error("parse conf", "error", err)
return
}
groups = conf.MatchGroups(confObj, conventionalCommit)
groups = strings.Split(os.Getenv(env.Groups), ",")
return
}