Skip to content

Commit

Permalink
Retry if a release is not yet available (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
unguiculus committed Feb 17, 2021
1 parent 013e427 commit 99aa256
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.sum
Expand Up @@ -607,6 +607,7 @@ github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
Expand Down
6 changes: 4 additions & 2 deletions pkg/github/github.go
Expand Up @@ -163,12 +163,14 @@ func (c *Client) uploadReleaseAsset(ctx context.Context, releaseID int64, filena
Name: filepath.Base(filename),
}

err = retry.Retry(3, 3*time.Second, func() error {
if err := retry.Retry(3, 3*time.Second, func() error {
if _, _, err = c.Repositories.UploadReleaseAsset(context.TODO(), c.owner, c.repo, releaseID, opts, f); err != nil {
return errors.Wrapf(err, "failed to upload release asset: %s\n", filename)
}
return nil
})
}); err != nil {
return err
}

return nil
}
14 changes: 12 additions & 2 deletions pkg/releaser/releaser.go
Expand Up @@ -27,6 +27,8 @@ import (
"strings"
"time"

"github.com/Songmu/retry"

"text/template"

"helm.sh/helm/v3/pkg/chart"
Expand Down Expand Up @@ -152,8 +154,16 @@ func (r *Releaser) UpdateIndexFile() (bool, error) {
if err != nil {
return false, err
}
release, err := r.github.GetRelease(context.TODO(), releaseName)
if err != nil {

var release *github.Release
if err := retry.Retry(3, 3*time.Second, func() error {
rel, err := r.github.GetRelease(context.TODO(), releaseName)
if err != nil {
return err
}
release = rel
return nil
}); err != nil {
return false, err
}

Expand Down

0 comments on commit 99aa256

Please sign in to comment.