Skip to content

Commit

Permalink
4.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-yurchenko committed Feb 20, 2022
1 parent ea6f994 commit d95e9c1
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 52 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Changelog

## [Unreleased]
## [4.2.3] - 2022-02-20

### Changed

- Keep retrying assets upload even if `422/UnprocessableEntity`/`502/BadGateway` is encountered and asset was not found on the partially created release (this will make git-release more robust to unexpected API responses)
- Keep retrying assets upload even if `422/UnprocessableEntity`/`502/BadGateway` is encountered and asset was not found on the partially created release

### Fixed

- [Issue #64](https://github.com/anton-yurchenko/git-release/issues/64) Panic on missing API response (*Thanks to [rgriebl](https://github.com/rgriebl)*)

## [4.2.2] - 2022-02-05

Expand Down Expand Up @@ -334,7 +338,7 @@ This is a major release as most of the code was refactored and some behavior was
- Control Release Draft through env.var 'DRAFT_RELEASE'
- Control Release Pre Release through env.var 'PRE_RELEASE'

[Unreleased]: https://github.com/anton-yurchenko/git-release/compare/v4.2.2...HEAD
[4.2.3]: https://github.com/anton-yurchenko/git-release/compare/v4.2.2...v4.2.3
[4.2.2]: https://github.com/anton-yurchenko/git-release/compare/v4.2.1...v4.2.2
[4.2.1]: https://github.com/anton-yurchenko/git-release/compare/v4.2.0...v4.2.1
[4.2.0]: https://github.com/anton-yurchenko/git-release/compare/v4.1.2...v4.2.0
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /opt/app

FROM scratch
LABEL org.opencontainers.image.source="https://github.com/anton-yurchenko/git-release"
LABEL org.opencontainers.image.version="v4.2.2"
LABEL org.opencontainers.image.version="v4.2.3"
LABEL org.opencontainers.image.authors="Anton Yurchenko <[email protected]>"
LABEL org.opencontainers.image.licenses="MIT"
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
Expand Down
Binary file modified bin/git-release-linux-amd64
Binary file not shown.
Binary file modified bin/git-release-windows-amd64.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// Version contains current application version
const Version string = "4.2.2"
const Version string = "4.2.3"

func init() {
log.SetReportCaller(false)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "git-release",
"version": "4.2.2",
"version": "4.2.3",
"description": "A GitHub Action for creating a GitHub Release with Assets and Changelog whenever a new Tag is pushed to the repository.",
"main": "wrapper.js",
"directories": {
Expand Down
50 changes: 27 additions & 23 deletions release/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,38 @@ func (a *Asset) uploadHandler(release *Release, cli RepositoriesClient, id int64
if err != nil {
log.WithField("asset", a.Name).Warnf("error uploading asset: %v", err.Error())

if !lastTry && (res.StatusCode == http.StatusBadGateway || res.StatusCode == http.StatusUnprocessableEntity) {
rel, _, err := cli.GetReleaseByTag(
context.Background(),
release.Slug.Owner,
release.Slug.Name,
release.Reference.Tag,
)
if err != nil {
return errors.Wrap(err, "error retrieving release")
}
if !lastTry && res.Response != nil {
if res.StatusCode == http.StatusBadGateway || res.StatusCode == http.StatusUnprocessableEntity {
rel, _, err := cli.GetReleaseByTag(
context.Background(),
release.Slug.Owner,
release.Slug.Name,
release.Reference.Tag,
)
if err != nil {
return errors.Wrap(err, "error retrieving release")
}

for _, s := range rel.Assets {
if *s.Name == strings.ReplaceAll(a.Name, "/", "-") {
_, err = cli.DeleteReleaseAsset(
context.Background(),
release.Slug.Owner,
release.Slug.Name,
*s.ID,
)
if err != nil {
return errors.Wrap(err, "error deleting ghost release asset")
for _, s := range rel.Assets {
if *s.Name == strings.ReplaceAll(a.Name, "/", "-") {
_, err = cli.DeleteReleaseAsset(
context.Background(),
release.Slug.Owner,
release.Slug.Name,
*s.ID,
)
if err != nil {
return errors.Wrap(err, "error deleting ghost release asset")
}

return errors.New("ghost release asset deleted")
}

return errors.New("ghost release asset deleted")
}

return errors.New("ghost release asset not found")
}

return errors.New("ghost release asset not found")
log.WithField("asset", a.Name).Debugf("received unexpected http response code during asset upload: %v", res.StatusCode)
}

return err
Expand Down
79 changes: 57 additions & 22 deletions release/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,39 @@ func TestUpload(t *testing.T) {
Error: "",
},
},
"No API Response [long test]": {
Asset: release.Asset{
Name: "test/File1",
Path: "testFile1",
},
Release: &release.Release{
Slug: &release.Slug{
Owner: "anton-yurchenko",
Name: "git-release",
},
Reference: &release.Reference{
Tag: "v1.0.0",
},
},
MockResponses: []mockResponses{
{
UploadReleaseAssetResponse: &github.Response{
Response: nil,
},
UploadReleaseAssetError: errors.New("reason-a"),
},
{
LastTry: true,
UploadReleaseAssetResponse: &github.Response{
Response: &http.Response{StatusCode: http.StatusOK},
},
UploadReleaseAssetError: nil,
},
},
Expected: expected{
Error: "",
},
},
"File Does Not Exists": {
Asset: release.Asset{
Name: "testFile3",
Expand Down Expand Up @@ -543,30 +576,32 @@ func TestUpload(t *testing.T) {
mock.AnythingOfType("*os.File"),
).Return(nil, res.UploadReleaseAssetResponse, res.UploadReleaseAssetError).Once()

if !res.LastTry && (res.UploadReleaseAssetResponse.StatusCode == http.StatusBadGateway || res.UploadReleaseAssetResponse.StatusCode == http.StatusUnprocessableEntity) {
m.On("GetReleaseByTag",
context.Background(),
test.Release.Slug.Owner,
test.Release.Slug.Name,
test.Release.Reference.Tag,
).Return(res.GetReleaseByTagRelease, nil, res.GetReleaseByTagError).Once()

if res.GetReleaseByTagError == nil {
var assetID int64
for _, s := range res.GetReleaseByTagRelease.Assets {
if *s.Name == strings.ReplaceAll(test.Asset.Name, "/", "-") {
assetID = *s.ID
break
if !res.LastTry && res.UploadReleaseAssetResponse.Response != nil {
if res.UploadReleaseAssetResponse.StatusCode == http.StatusBadGateway || res.UploadReleaseAssetResponse.StatusCode == http.StatusUnprocessableEntity {
m.On("GetReleaseByTag",
context.Background(),
test.Release.Slug.Owner,
test.Release.Slug.Name,
test.Release.Reference.Tag,
).Return(res.GetReleaseByTagRelease, nil, res.GetReleaseByTagError).Once()

if res.GetReleaseByTagError == nil {
var assetID int64
for _, s := range res.GetReleaseByTagRelease.Assets {
if *s.Name == strings.ReplaceAll(test.Asset.Name, "/", "-") {
assetID = *s.ID
break
}
}
}

if res.GetReleaseByTagError == nil && assetID != 0 {
m.On("DeleteReleaseAsset",
context.Background(),
test.Release.Slug.Owner,
test.Release.Slug.Name,
assetID,
).Return(nil, res.DeleteReleaseAssetError).Once()
if res.GetReleaseByTagError == nil && assetID != 0 {
m.On("DeleteReleaseAsset",
context.Background(),
test.Release.Slug.Owner,
test.Release.Slug.Name,
assetID,
).Return(nil, res.DeleteReleaseAssetError).Once()
}
}
}
}
Expand Down

0 comments on commit d95e9c1

Please sign in to comment.