Skip to content

Commit 1a49ee5

Browse files
author
openshift-pipelines-bot
committed
[bot] Update release-v1.20.x from tektoncd-catalog/git-clone to 688f02a
$ git diff --stat 688f02a..81a5a95 .github/workflows/build.yaml | 4 +- .github/workflows/release.yaml | 10 +- image/git-init/git/git.go | 76 +------- image/git-init/git/git_test.go | 200 +-------------------- image/git-init/go.mod | 12 +- image/git-init/go.sum | 24 +-- image/git-init/main.go | 26 +-- .../vendor/golang.org/x/net/http2/frame.go | 11 -- .../vendor/golang.org/x/net/http2/server.go | 5 +- image/git-init/vendor/golang.org/x/oauth2/pkce.go | 4 +- image/git-init/vendor/modules.txt | 22 +-- task/git-clone/README.md | 3 - task/git-clone/git-clone.yaml | 12 +- task/git-clone/tests/run.yaml | 19 -- 14 files changed, 55 insertions(+), 373 deletions(-) https://github.com/tektoncd-catalog/git-clone/compare/688f02aa76d36c52470ee8e9e1e111d170f529ff..81a5a95626ca87305d349d6fdd0cef3c2dd786b0
1 parent c3559ac commit 1a49ee5

File tree

15 files changed

+374
-56
lines changed

15 files changed

+374
-56
lines changed

head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
81a5a95626ca87305d349d6fdd0cef3c2dd786b0
1+
688f02aa76d36c52470ee8e9e1e111d170f529ff

upstream/.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ jobs:
1919
runs-on: ubuntu-latest
2020

2121
steps:
22-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23-
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
22+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
23+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
2424
with:
2525
go-version-file: "image/git-init/go.mod"
2626
cache-dependency-path: "image/git-init/go.sum"

upstream/.github/workflows/release.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ jobs:
2626
# run:
2727
# working-directory: ./image/git-init
2828
steps:
29-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
3030

3131
- run: git fetch --prune --unshallow
3232

33-
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
33+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
3434
with:
3535
go-version-file: "image/git-init/go.mod"
3636
cache-dependency-path: "image/git-init/go.sum"
3737

3838
# This installs the current latest release.
39-
- uses: ko-build/setup-ko@d982fec422852203cfb2053a8ec6ad302280d04d # v0.8
39+
- uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
4040

4141
- uses: imjasonh/setup-crane@31b88efe9de28ae0ffa220711af4b60be9435f6e # v0.4
4242

43-
- uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1
43+
- uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
4444

4545
- name: Set tag output
4646
id: tag
4747
run: echo "tag_name=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT"
4848

49-
- uses: goreleaser/goreleaser-action@90a3faa9d0182683851fbfa97ca1a2cb983bfca3 # v6.2.1
49+
- uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
5050
id: run-goreleaser
5151
with:
5252
version: latest

upstream/image/git-init/git/git.go

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ package git
1919
import (
2020
"bytes"
2121
"fmt"
22+
"math"
23+
"math/rand"
2224
"os"
2325
"os/exec"
2426
"path/filepath"
2527
"regexp"
2628
"strconv"
2729
"strings"
30+
"time"
2831

2932
homedir "github.com/mitchellh/go-homedir"
3033
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
@@ -64,15 +67,23 @@ type FetchSpec struct {
6467
Path string
6568
Depth uint
6669
Submodules bool
70+
SubmodulePaths []string
6771
SSLVerify bool
6872
HTTPProxy string
6973
HTTPSProxy string
7074
NOProxy string
7175
SparseCheckoutDirectories string
7276
}
7377

78+
type RetryConfig struct {
79+
Initial time.Duration
80+
Max time.Duration
81+
Factor float64
82+
MaxAttempts int
83+
}
84+
7485
// Fetch fetches the specified git repository at the revision into path, using the refspec to fetch if provided.
75-
func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
86+
func Fetch(logger *zap.SugaredLogger, spec FetchSpec, retryConfig RetryConfig) error {
7687
homepath, err := homedir.Dir()
7788
if err != nil {
7889
logger.Errorf("Unexpected error getting the user home directory: %v", err)
@@ -177,7 +188,14 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
177188
// when the refspec specifies the same destination twice)
178189
fetchArgs = append(fetchArgs, "origin", "--update-head-ok", "--force")
179190
fetchArgs = append(fetchArgs, fetchParam...)
180-
if _, err := run(logger, spec.Path, fetchArgs...); err != nil {
191+
if _, _, err := retryWithBackoff(
192+
func() (string, error) { return run(logger, spec.Path, fetchArgs...) },
193+
retryConfig.Initial,
194+
retryConfig.Max,
195+
retryConfig.Factor,
196+
retryConfig.MaxAttempts,
197+
logger,
198+
); err != nil {
181199
return fmt.Errorf("failed to fetch %v: %v", fetchParam, err)
182200
}
183201
// After performing a fetch, verify that the item to checkout is actually valid
@@ -199,7 +217,7 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
199217
}
200218
logger.Infof("Successfully cloned %s @ %s (%s) in path %s", trimmedURL, commit, ref, spec.Path)
201219
if spec.Submodules {
202-
if err := submoduleFetch(logger, spec); err != nil {
220+
if err := submoduleFetch(logger, spec, retryConfig); err != nil {
203221
return err
204222
}
205223
}
@@ -223,17 +241,27 @@ func showRef(logger *zap.SugaredLogger, revision, path string) (string, error) {
223241
return strings.TrimSuffix(output, "\n"), nil
224242
}
225243

226-
func submoduleFetch(logger *zap.SugaredLogger, spec FetchSpec) error {
244+
func submoduleFetch(logger *zap.SugaredLogger, spec FetchSpec, retryConfig RetryConfig) error {
227245
if spec.Path != "" {
228246
if err := os.Chdir(spec.Path); err != nil {
229247
return fmt.Errorf("failed to change directory with path %s; err: %w", spec.Path, err)
230248
}
231249
}
232-
updateArgs := []string{"submodule", "update", "--recursive", "--init"}
250+
updateArgs := []string{"submodule", "update", "--recursive", "--init", "--force"}
233251
if spec.Depth > 0 {
234252
updateArgs = append(updateArgs, fmt.Sprintf("--depth=%d", spec.Depth))
235253
}
236-
if _, err := run(logger, "", updateArgs...); err != nil {
254+
if len(spec.SubmodulePaths) > 0 {
255+
updateArgs = append(updateArgs, spec.SubmodulePaths...)
256+
}
257+
if _, _, err := retryWithBackoff(
258+
func() (string, error) { return run(logger, "", updateArgs...) },
259+
retryConfig.Initial,
260+
retryConfig.Max,
261+
retryConfig.Factor,
262+
retryConfig.MaxAttempts,
263+
logger,
264+
); err != nil {
237265
return err
238266
}
239267
logger.Infof("Successfully initialized and updated submodules in path %s", spec.Path)
@@ -336,3 +364,39 @@ func configSparseCheckout(logger *zap.SugaredLogger, spec FetchSpec) error {
336364
}
337365
return nil
338366
}
367+
368+
type operation[T any] func() (T, error)
369+
370+
// retryWithBackoff runs `operation` until it succeeds or the context is done,
371+
// with exponential backoff and jitter between retries.
372+
func retryWithBackoff[T any](
373+
operation operation[T],
374+
initial time.Duration,
375+
max time.Duration,
376+
factor float64,
377+
maxAttempts int,
378+
logger *zap.SugaredLogger,
379+
) (T, time.Duration, error) {
380+
381+
waitTime := time.Duration(0)
382+
383+
for attempt := 0; ; attempt++ {
384+
logger.Infof("Retrying operation (attempt %d)", attempt+1)
385+
result, err := operation()
386+
if err == nil {
387+
return result, waitTime, nil
388+
}
389+
390+
if attempt+1 == maxAttempts {
391+
return result, waitTime, err
392+
}
393+
394+
// compute backoff: exponential
395+
backoff := min(time.Duration(float64(initial)*math.Pow(factor, float64(attempt))), max)
396+
// add jitter: random in [0, next)
397+
jitter := time.Duration(rand.Int63n(int64(backoff)))
398+
wait := backoff + jitter/2
399+
time.Sleep(wait)
400+
waitTime += wait
401+
}
402+
}

0 commit comments

Comments
 (0)