From fef7081a431a8e0b450d6d1104e3b63813a9b4a7 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 22:20:42 +0900 Subject: [PATCH 1/3] 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/3] 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/3] 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 }}