added git clone retry

This commit is contained in:
Giovanni Harting 2023-05-21 21:19:24 +02:00
parent 55aa18f218
commit c59a6ed2be
2 changed files with 19 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/c2h5oh/datasize"
"github.com/google/uuid"
"github.com/otiai10/copy"
"github.com/sethvargo/go-retry"
log "github.com/sirupsen/logrus"
"io"
"os"
@ -342,13 +343,23 @@ func (p *ProtoPackage) setupBuildDir() (string, error) {
gitlabPath = reReplaceUnderscore.ReplaceAllString(gitlabPath, "-")
gitlabPath = reReplaceTree.ReplaceAllString(gitlabPath, "unix-tree")
cmd := exec.Command("git", "clone", "--depth", "1", "--branch", p.State.TagVer,
fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir)
res, err := cmd.CombinedOutput()
log.Debug(string(res))
if err != nil {
log.Fatalf("error cloning package repo %s: %v (%s)", p.Pkgbase, err, string(res))
return "", err
if err := retry.Fibonacci(context.Background(), 1*time.Second, func(ctx context.Context) error {
cmd := exec.Command("git", "clone", "--depth", "1", "--branch", p.State.TagVer,
fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir)
res, err := cmd.CombinedOutput()
log.Debug(string(res))
if err != nil {
gitHTTPMatch := reGitHTTPError.FindAllStringSubmatch(string(res), -1)
if len(gitHTTPMatch) > 0 && gitHTTPMatch[0][1] == "429" {
log.Infof("unable to clone %s->%s repo, trying again later", p.March, p.Pkgbase)
return retry.RetryableError(err)
} else {
return fmt.Errorf("git clone failed: %s", string(res))
}
}
return nil
}); err != nil {
log.Fatal(err)
}
p.Pkgbuild = filepath.Join(buildDir, "PKGBUILD")

View File

@ -50,6 +50,7 @@ var (
reReplaceSpecialChars = regexp.MustCompile(`(?m)[^a-zA-Z0-9_\-.]`)
reReplaceUnderscore = regexp.MustCompile(`(?m)[_\-]{2,}`)
reReplaceTree = regexp.MustCompile(`(?m)^tree$`)
reGitHTTPError = regexp.MustCompile(`(?mi)The requested URL returned error: (\d+)`)
)
type Conf struct {