Skip to content

Commit

Permalink
Merge 6f6eed5 into a7a2539
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW authored Feb 13, 2023
2 parents a7a2539 + 6f6eed5 commit 567900b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
env:
DEBUG: true
steps:
- name: Check out source code
uses: actions/checkout@v3
Expand Down
13 changes: 11 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"context"
"errors"
"fmt"
"io"
"log"
"os"

"github.com/k1LoW/gh-setup/gh"
Expand Down Expand Up @@ -88,8 +90,15 @@ var rootCmd = &cobra.Command{
}

func Execute() {
err := rootCmd.Execute()
if err != nil {
rootCmd.SetOut(os.Stdout)
rootCmd.SetErr(os.Stderr)

log.SetOutput(io.Discard)
if env := os.Getenv("DEBUG"); env != "" {
log.SetOutput(os.Stderr)
}

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
Expand Down
2 changes: 2 additions & 0 deletions gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"io/fs"
"log"
"net/http"
"regexp"
"runtime"
Expand Down Expand Up @@ -176,6 +177,7 @@ func makeFS(owner, repo string, a *github.ReleaseAsset) (fs.FS, error) {
if err != nil {
return nil, err
}
log.Println("asset content type:", a.GetContentType())
switch a.GetContentType() {
case "application/zip", "application/x-zip-compressed":
return zip.NewReader(bytes.NewReader(b), int64(len(b)))
Expand Down
4 changes: 4 additions & 0 deletions setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"path/filepath"
Expand All @@ -24,6 +25,7 @@ func Bin(fsys fs.FS, bd string, force bool) (map[string]string, error) {
}
}
if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
log.Println("extract file:", path)
if err != nil {
return err
}
Expand Down Expand Up @@ -158,13 +160,15 @@ func isBinary(b []byte) bool {
// FIXME: On Windows, it can't be detected at all.
const binaryContentType = "application/octet-stream"
contentType := http.DetectContentType(b)
log.Println("content type:", contentType)
if contentType == binaryContentType {
return true
}
typ, err := filetype.Match(b)
if err != nil {
return false
}
log.Printf("file type: %v\n", typ)
if typ == filetype.Unknown {
return true
}
Expand Down

0 comments on commit 567900b

Please sign in to comment.