Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mime type lookup files #81

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions out_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"os"
"path/filepath"
"strings"
"mime"
"errors"
"time"

"github.com/google/go-github/github"
)
Expand Down Expand Up @@ -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++ {
Expand All @@ -177,20 +185,25 @@ 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
}

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
}
break
}
}

time.Sleep(2 * time.Second)
}

if retryErr != nil {
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/google/go-github/github/repos_releases.go

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