diff --git a/Dockerfile b/Dockerfile index 5d52565..67cb492 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN set -e; for pkg in $(go list ./...); do \ done FROM alpine:edge AS resource -RUN apk add --update bash tzdata ca-certificates +RUN apk add --update bash tzdata ca-certificates mailcap COPY --from=builder /assets /opt/resource FROM resource AS tests diff --git a/out_command.go b/out_command.go index c5fb5eb..402e740 100644 --- a/out_command.go +++ b/out_command.go @@ -7,6 +7,9 @@ import ( "os" "path/filepath" "strings" + "mime" + "errors" + "time" "github.com/google/go-github/github" ) @@ -159,9 +162,14 @@ func (c *OutCommand) fileContents(path string) (string, error) { } func (c *OutCommand) upload(release *github.RepositoryRelease, filePath string) error { - fmt.Fprintf(c.writer, "uploading %s\n", filePath) - name := filepath.Base(filePath) + mediaType := mime.TypeByExtension(filepath.Ext(name)) + + if mediaType == "" { + return errors.New("no mime type found for file") + } + + fmt.Fprintf(c.writer, "uploading %s as type %s \n", name, mediaType) var retryErr error for i := 0; i < 10; i++ { @@ -177,6 +185,8 @@ func (c *OutCommand) upload(release *github.RepositoryRelease, filePath string) break } + fmt.Fprintf(c.writer, "\tfailed to upload %s\n", name) + assets, err := c.github.ListReleaseAssets(*release) if err != nil { return err @@ -184,6 +194,7 @@ func (c *OutCommand) upload(release *github.RepositoryRelease, filePath string) for _, asset := range assets { if asset.Name != nil && *asset.Name == name { + fmt.Fprintf(c.writer, "\tdeleting failed upload %s from assets\n", name) err = c.github.DeleteReleaseAsset(*asset) if err != nil { return err @@ -191,6 +202,8 @@ func (c *OutCommand) upload(release *github.RepositoryRelease, filePath string) break } } + + time.Sleep(2 * time.Second) } if retryErr != nil { diff --git a/vendor/github.com/google/go-github/github/repos_releases.go b/vendor/github.com/google/go-github/github/repos_releases.go index 5c27565..df78258 100644 --- a/vendor/github.com/google/go-github/github/repos_releases.go +++ b/vendor/github.com/google/go-github/github/repos_releases.go @@ -313,6 +313,8 @@ func (s *RepositoriesService) UploadReleaseAsset(ctx context.Context, owner, rep } mediaType := mime.TypeByExtension(filepath.Ext(file.Name())) + os.Stderr.WriteString("MediaType: " + mediaType + "\n") + req, err := s.client.NewUploadRequest(u, file, stat.Size(), mediaType) if err != nil { return nil, nil, err