added git clone retry
This commit is contained in:
parent
55aa18f218
commit
c59a6ed2be
@ -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")
|
||||
|
||||
|
1
utils.go
1
utils.go
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user