feat(healthcheck): run joj3-check-env
This commit is contained in:
		
							parent
							
								
									797161940f
								
							
						
					
					
						commit
						3d828b6168
					
				|  | @ -6,7 +6,6 @@ import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"log/slog" | 	"log/slog" | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/joint-online-judge/JOJ3/internal/conf" | 	"github.com/joint-online-judge/JOJ3/internal/conf" | ||||||
| 	"github.com/joint-online-judge/JOJ3/pkg/healthcheck" | 	"github.com/joint-online-judge/JOJ3/pkg/healthcheck" | ||||||
|  | @ -60,20 +59,8 @@ func init() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func prepareTeapotCheck() ( | func prepareTeapotCheck() ( | ||||||
| 	confObj *conf.Conf, groups []string, actor, repoName string, err error, | 	confObj *conf.Conf, groups []string, err error, | ||||||
| ) { | ) { | ||||||
| 	actor = os.Getenv("GITHUB_ACTOR") |  | ||||||
| 	repository := os.Getenv("GITHUB_REPOSITORY") |  | ||||||
| 	if actor == "" || |  | ||||||
| 		repository == "" || |  | ||||||
| 		strings.Count(repository, "/") != 1 || |  | ||||||
| 		confPath == "" { |  | ||||||
| 		slog.Error("teapot env not set", "actor", actor, "repository", repository, "confPath", confPath, "env", os.Environ()) |  | ||||||
| 		err = fmt.Errorf("teapot env not set") |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	repoParts := strings.Split(repository, "/") |  | ||||||
| 	repoName = repoParts[1] |  | ||||||
| 	commitMsg, err := conf.GetCommitMsg() | 	commitMsg, err := conf.GetCommitMsg() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("get commit msg", "error", err) | 		slog.Error("get commit msg", "error", err) | ||||||
|  | @ -108,13 +95,13 @@ func main() { | ||||||
| 		"meta", metaFile, | 		"meta", metaFile, | ||||||
| 	) | 	) | ||||||
| 	var err error | 	var err error | ||||||
| 	confObj, groups, actor, repoName, err := prepareTeapotCheck() | 	confObj, groups, err := prepareTeapotCheck() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("prepare teapot check", "error", err) | 		slog.Error("prepare teapot check", "error", err) | ||||||
| 		confObj = nil | 		confObj = nil | ||||||
| 	} | 	} | ||||||
| 	res := healthcheck.All( | 	res := healthcheck.All( | ||||||
| 		confObj, actor, repoName, rootDir, checkFileNameList, checkFileSumList, | 		confObj, rootDir, checkFileNameList, checkFileSumList, | ||||||
| 		groups, metaFile, repoSize, | 		groups, metaFile, repoSize, | ||||||
| 	) | 	) | ||||||
| 	jsonRes, err := json.Marshal(res) | 	jsonRes, err := json.Marshal(res) | ||||||
|  |  | ||||||
|  | @ -13,13 +13,13 @@ type Result struct { | ||||||
| 
 | 
 | ||||||
| func All( | func All( | ||||||
| 	confObj *conf.Conf, | 	confObj *conf.Conf, | ||||||
| 	actor, repoName, rootDir, checkFileNameList, checkFileSumList string, | 	rootDir, checkFileNameList, checkFileSumList string, | ||||||
| 	groups, metaFile []string, | 	groups, metaFile []string, | ||||||
| 	repoSize float64, | 	repoSize float64, | ||||||
| ) (res Result) { | ) (res Result) { | ||||||
| 	var err error | 	var err error | ||||||
| 	if confObj != nil { | 	if confObj != nil { | ||||||
| 		output, err := TeapotCheck(confObj, actor, repoName, groups) | 		output, err := TeapotCheck(confObj, groups) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			res.Msg += fmt.Sprintf("### Teapot Check Failed:\n%s\n", output) | 			res.Msg += fmt.Sprintf("### Teapot Check Failed:\n%s\n", output) | ||||||
| 			res.Failed = true | 			res.Failed = true | ||||||
|  |  | ||||||
|  | @ -19,9 +19,8 @@ type CheckResult struct { | ||||||
| 	TimePeriod  int    `json:"time_period"` | 	TimePeriod  int    `json:"time_period"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func runTeapot(conf *conf.Conf, actor, repoName string) (checkResults []CheckResult, err error) { | func runTeapot(conf *conf.Conf) (checkResults []CheckResult, err error) { | ||||||
| 	os.Setenv("LOG_FILE_PATH", conf.Teapot.LogPath) | 	os.Setenv("LOG_FILE_PATH", conf.Teapot.LogPath) | ||||||
| 	os.Setenv("_TYPER_STANDARD_TRACEBACK", "1") |  | ||||||
| 	var formattedGroups []string | 	var formattedGroups []string | ||||||
| 	for _, group := range conf.Teapot.Groups { | 	for _, group := range conf.Teapot.Groups { | ||||||
| 		groupConfig := fmt.Sprintf("%s=%d:%d", | 		groupConfig := fmt.Sprintf("%s=%d:%d", | ||||||
|  | @ -29,9 +28,9 @@ func runTeapot(conf *conf.Conf, actor, repoName string) (checkResults []CheckRes | ||||||
| 		formattedGroups = append(formattedGroups, groupConfig) | 		formattedGroups = append(formattedGroups, groupConfig) | ||||||
| 	} | 	} | ||||||
| 	args := []string{ | 	args := []string{ | ||||||
| 		"joj3-check", conf.Teapot.EnvFilePath, | 		"joj3-check-env", conf.Teapot.EnvFilePath, | ||||||
| 		actor, conf.Teapot.GradingRepoName, repoName, | 		conf.Teapot.GradingRepoName, | ||||||
| 		conf.Teapot.ScoreboardPath, conf.Name, | 		conf.Teapot.ScoreboardPath, | ||||||
| 		"--group-config", strings.Join(formattedGroups, ","), | 		"--group-config", strings.Join(formattedGroups, ","), | ||||||
| 	} | 	} | ||||||
| 	var stdoutBuf, stderrBuf bytes.Buffer | 	var stdoutBuf, stderrBuf bytes.Buffer | ||||||
|  | @ -90,10 +89,8 @@ func generateOutput( | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TeapotCheck( | func TeapotCheck(conf *conf.Conf, groups []string) (output string, err error) { | ||||||
| 	conf *conf.Conf, actor, repoName string, groups []string, | 	checkResults, err := runTeapot(conf) | ||||||
| ) (output string, err error) { |  | ||||||
| 	checkResults, err := runTeapot(conf, actor, repoName) |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("teapot check", "error", err) | 		slog.Error("teapot check", "error", err) | ||||||
| 		return | 		return | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user