added git clone retry
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/c2h5oh/datasize"
|
"github.com/c2h5oh/datasize"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/otiai10/copy"
|
"github.com/otiai10/copy"
|
||||||
|
"github.com/sethvargo/go-retry"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -342,13 +343,23 @@ func (p *ProtoPackage) setupBuildDir() (string, error) {
|
|||||||
gitlabPath = reReplaceUnderscore.ReplaceAllString(gitlabPath, "-")
|
gitlabPath = reReplaceUnderscore.ReplaceAllString(gitlabPath, "-")
|
||||||
gitlabPath = reReplaceTree.ReplaceAllString(gitlabPath, "unix-tree")
|
gitlabPath = reReplaceTree.ReplaceAllString(gitlabPath, "unix-tree")
|
||||||
|
|
||||||
|
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,
|
cmd := exec.Command("git", "clone", "--depth", "1", "--branch", p.State.TagVer,
|
||||||
fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir)
|
fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir)
|
||||||
res, err := cmd.CombinedOutput()
|
res, err := cmd.CombinedOutput()
|
||||||
log.Debug(string(res))
|
log.Debug(string(res))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error cloning package repo %s: %v (%s)", p.Pkgbase, err, string(res))
|
gitHTTPMatch := reGitHTTPError.FindAllStringSubmatch(string(res), -1)
|
||||||
return "", err
|
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")
|
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_\-.]`)
|
reReplaceSpecialChars = regexp.MustCompile(`(?m)[^a-zA-Z0-9_\-.]`)
|
||||||
reReplaceUnderscore = regexp.MustCompile(`(?m)[_\-]{2,}`)
|
reReplaceUnderscore = regexp.MustCompile(`(?m)[_\-]{2,}`)
|
||||||
reReplaceTree = regexp.MustCompile(`(?m)^tree$`)
|
reReplaceTree = regexp.MustCompile(`(?m)^tree$`)
|
||||||
|
reGitHTTPError = regexp.MustCompile(`(?mi)The requested URL returned error: (\d+)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
|
Reference in New Issue
Block a user