40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package healthcheck
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
// For ExitCode, see https://focs.ji.sjtu.edu.cn/git/TAs/resources/src/branch/drone/dronelib.checks
|
|
// 1 for unrecoverable error and 0 for succeses
|
|
type CheckStage struct {
|
|
Name string `json:"name of check"`
|
|
StdOut string `json:"stdout"`
|
|
ExitCode int `json:"exit code"`
|
|
StdErr string `json:"stderr"`
|
|
ErrorLog error `json:"errorLog"`
|
|
}
|
|
|
|
// addExt appends the specified extension to each file name in the given fileList.
|
|
// It modifies the original fileList in place.
|
|
func addExt(fileList []string, ext string) {
|
|
for i, file := range fileList {
|
|
fileList[i] = file + ext
|
|
}
|
|
}
|
|
|
|
// getRegex compiles each regex pattern in the fileList into a []*regexp.Regexp slice.
|
|
// It returns a slice containing compiled regular expressions.
|
|
func getRegex(fileList []string) ([]*regexp.Regexp, error) {
|
|
var regexList []*regexp.Regexp
|
|
for _, pattern := range fileList {
|
|
regex, err := regexp.Compile("(?i)" + pattern)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error compiling regex:%w", err)
|
|
}
|
|
regexList = append(regexList, regex)
|
|
}
|
|
|
|
return regexList, nil
|
|
}
|