feat(healthcheck): git lfs fsck --pointers
Some checks failed
build / trigger-build-image (push) Blocked by required conditions
build / build (push) Has been cancelled
submodules sync / sync (push) Has been cancelled

This commit is contained in:
张泊明518370910136 2025-06-28 08:27:45 -04:00
parent 38d00246cf
commit 6643644865
GPG Key ID: D47306D7062CDA9D
3 changed files with 30 additions and 2 deletions

View File

@ -16,13 +16,20 @@ func All(
metaFile []string, repoSize float64,
) (res Result) {
var err error
err = RepoSize(repoSize)
err = RepoSize(rootDir, repoSize)
if err != nil {
res.Msg += fmt.Sprintf("### Repo Size Check Failed:\n%s\n", err.Error())
res.Failed = true
} else {
res.Msg += "### Repo Size Check Passed\n"
}
err = RepoLFS(rootDir)
if err != nil {
res.Msg += fmt.Sprintf("### Repo LFS Check Failed:\n%s\n", err.Error())
res.Failed = true
} else {
res.Msg += "### Repo LFS Check Passed\n"
}
err = ForbiddenCheck(rootDir)
if err != nil {
res.Msg += fmt.Sprintf("### Forbidden File Check Failed:\n%s\n", err.Error())

View File

@ -0,0 +1,20 @@
package healthcheck
import (
"fmt"
"os/exec"
)
func RepoLFS(workDir string) error {
cmd := exec.Command("git", "lfs", "fsck", "--pointers")
cmd.Dir = workDir
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf(
"error running `git lfs fsck --pointers`: %w, output: %s",
err,
output,
)
}
return nil
}

View File

@ -10,7 +10,7 @@ import (
// RepoSize checks the size of the repository to determine if it is oversized.
// It executes the 'git count-objects -v' command to obtain the size information,
func RepoSize(confSize float64) error {
func RepoSize(rootDir string, confSize float64) error {
// TODO: reimplement here when go-git is available
// https://github.com/go-git/go-git/blob/master/COMPATIBILITY.md
cmd := exec.Command(
@ -20,6 +20,7 @@ func RepoSize(confSize float64) error {
"count-objects",
"-v",
)
cmd.Dir = rootDir
output, err := cmd.CombinedOutput()
if err != nil {
slog.Error("running git command:", "err", err, "output", output)