diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ba3459..6315e06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -68,7 +70,7 @@ jobs: with: repo: k1LoW/tbls force: true - gh-setup-version: v0.7.0 + gh-setup-version: v0.7.1 - name: Run setup as a action (2/2) run: tbls version @@ -80,7 +82,7 @@ jobs: github-token: '' repo: k1LoW/colr force: true - gh-setup-version: v0.7.0 + gh-setup-version: v0.7.1 - name: Run setup as a action (no credentials) (2/2) run: colr -v diff --git a/cmd/root.go b/cmd/root.go index 59e72b2..7a11e51 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -25,6 +25,8 @@ import ( "context" "errors" "fmt" + "io" + "log" "os" "github.com/k1LoW/gh-setup/gh" @@ -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) } } diff --git a/gh/gh.go b/gh/gh.go index 77794b8..93cca2f 100644 --- a/gh/gh.go +++ b/gh/gh.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "io/fs" + "log" "net/http" "regexp" "runtime" @@ -176,10 +177,12 @@ func makeFS(owner, repo string, a *github.ReleaseAsset) (fs.FS, error) { if err != nil { return nil, err } - switch a.GetContentType() { - case "application/zip", "application/x-zip-compressed": + cts := []string{a.GetContentType(), http.DetectContentType(b)} + log.Println("asset content type:", cts) + switch { + case matchContentTypes([]string{"application/zip", "application/x-zip-compressed"}, cts): return zip.NewReader(bytes.NewReader(b), int64(len(b))) - case "application/gzip": + case matchContentTypes([]string{"application/gzip", "application/x-gzip"}, cts): gr, err := gzip.NewReader(bytes.NewReader(b)) if err != nil { return nil, err @@ -204,7 +207,7 @@ func makeFS(owner, repo string, a *github.ReleaseAsset) (fs.FS, error) { } return fsys, nil } - case "application/octet-stream": + case matchContentTypes([]string{"application/octet-stream"}, cts): fsys := fstest.MapFS{} fsys[repo] = &fstest.MapFile{ Data: b, @@ -295,3 +298,14 @@ func httpClient() (*http.Client, error) { } return client, nil } + +func matchContentTypes(m, ct []string) bool { + for _, v := range m { + for _, vv := range ct { + if v == vv { + return true + } + } + } + return false +} diff --git a/setup/setup.go b/setup/setup.go index d25156d..daa70db 100644 --- a/setup/setup.go +++ b/setup/setup.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io/fs" + "log" "net/http" "os" "path/filepath" @@ -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 } @@ -158,6 +160,7 @@ 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 } @@ -165,6 +168,7 @@ func isBinary(b []byte) bool { if err != nil { return false } + log.Printf("file type: %v\n", typ) if typ == filetype.Unknown { return true }