From fef7081a431a8e0b450d6d1104e3b63813a9b4a7 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:20:42 +0900 Subject: [PATCH 1/7] Set log --- .github/workflows/ci.yml | 2 ++ cmd/root.go | 13 +++++++++++-- setup/setup.go | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ba3459..9ae6a13 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 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/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 } From e3f4a6d674f5e15a8f2c046aa78a7d1ee68ab65f Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:23:22 +0900 Subject: [PATCH 2/7] debug --- .github/workflows/ci.yml | 4 ++-- gh/gh.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ae6a13..6fcf425 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,8 @@ jobs: - name: Run setup test run: | - go run cmd/gh-setup/main.go --repo k1LoW/gh-setup --version v0.6.0 --force - gh-setup version + go run cmd/gh-setup/main.go --repo k1LoW/colr --force + colr -v shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/gh/gh.go b/gh/gh.go index 77794b8..1cf6edc 100644 --- a/gh/gh.go +++ b/gh/gh.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "io/fs" + "log" "net/http" "regexp" "runtime" @@ -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))) From 6f6eed5cfaed81e711085410dee96aabb71f0776 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:36:16 +0900 Subject: [PATCH 3/7] Revert --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fcf425..9ae6a13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,8 @@ jobs: - name: Run setup test run: | - go run cmd/gh-setup/main.go --repo k1LoW/colr --force - colr -v + go run cmd/gh-setup/main.go --repo k1LoW/gh-setup --version v0.6.0 --force + gh-setup version shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 73c9b273e619ee821f71705df18273b4f1d07087 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:37:20 +0900 Subject: [PATCH 4/7] Fix detecting content-type of asset --- gh/gh.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/gh/gh.go b/gh/gh.go index 1cf6edc..93cca2f 100644 --- a/gh/gh.go +++ b/gh/gh.go @@ -177,11 +177,12 @@ 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": + 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 @@ -206,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, @@ -297,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 +} From 67e4c478a9243e5ef4889abcdee85e685c4604a6 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:38:41 +0900 Subject: [PATCH 5/7] detect test --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ae6a13..6fcf425 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,8 @@ jobs: - name: Run setup test run: | - go run cmd/gh-setup/main.go --repo k1LoW/gh-setup --version v0.6.0 --force - gh-setup version + go run cmd/gh-setup/main.go --repo k1LoW/colr --force + colr -v shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 31f6c50369815521f4b5cedfc23aa198c7a62ce3 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:40:34 +0900 Subject: [PATCH 6/7] Revert --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fcf425..9ae6a13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,8 @@ jobs: - name: Run setup test run: | - go run cmd/gh-setup/main.go --repo k1LoW/colr --force - colr -v + go run cmd/gh-setup/main.go --repo k1LoW/gh-setup --version v0.6.0 --force + gh-setup version shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 9b9f0b883c557d8bf05e50606269912fe5057fbf Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:41:13 +0900 Subject: [PATCH 7/7] Fix --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ae6a13..6315e06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,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 @@ -82,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