From 2ca13e45389877f979225a634404495380e133c4 Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Tue, 20 Dec 2022 23:15:19 +0900 Subject: [PATCH 1/7] add ci --- .github/workflows/check.yml | 56 +++++++++++++++++++++++++++++++++++++ .gitignore | 4 +-- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..1d6087f --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,56 @@ +name: Check + +on: pull_request + +jobs: + build: + timeout-minutes: 5 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - run: make build + + fmt: + timeout-minutes: 5 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - run: make fmt + + vet: + timeout-minutes: 5 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - run: make vet + + test: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - run: make install + + - run: make test diff --git a/.gitignore b/.gitignore index 30b3c74..24120ed 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,5 @@ go.work # End of https://www.toptal.com/developers/gitignore/api/go .envrc -/chart.html -/generate.json +/*.html +/*.json From d0c82f69a1a80b74584018feb900cbc56ffcf189 Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Tue, 20 Dec 2022 23:16:29 +0900 Subject: [PATCH 2/7] fix --- .github/workflows/check.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1d6087f..90c422b 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -51,6 +51,4 @@ jobs: with: go-version: 1.19 - - run: make install - - run: make test From b02abc6274c99432f6010ea4d2515650bae1b0fa Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Tue, 20 Dec 2022 23:21:37 +0900 Subject: [PATCH 3/7] fix token --- .envrc.sample | 4 +++- .github/workflows/check.yml | 2 ++ pkg/github.go | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.envrc.sample b/.envrc.sample index b2754be..2179a77 100644 --- a/.envrc.sample +++ b/.envrc.sample @@ -1 +1,3 @@ -export GITHUB_ACCESS_TOKEN= +export KUNITORI_GITHUB_ACCESS_TOKEN= +export KUNITORI_USE_GIT_COMMAND= +export KUNITORI_SKIP_REQUEST_GITHUB_API= diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 90c422b..e61182d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -52,3 +52,5 @@ jobs: go-version: 1.19 - run: make test + env: + KUNITORI_SKIP_REQUEST_GITHUB_API: 1 diff --git a/pkg/github.go b/pkg/github.go index 5c6f66b..2fb3900 100644 --- a/pkg/github.go +++ b/pkg/github.go @@ -12,7 +12,7 @@ import ( "time" ) -const GitHubAccessTokenKey = "GITHUB_ACCESS_TOKEN" +const GitHubAccessTokenKey = "KUNITORI_GITHUB_ACCESS_TOKEN" const KunitoriSkipRequestGitHubApi = "KUNITORI_SKIP_REQUEST_GITHUB_API" func FindLoginByEmail(email string) (string, error) { From 6f9e8fd4ecc171f359cc1c3338aa6d57effc274b Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Tue, 20 Dec 2022 23:30:45 +0900 Subject: [PATCH 4/7] add fetch-depth --- .github/workflows/check.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e61182d..4be294d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -46,11 +46,10 @@ jobs: - uses: actions/checkout@v3 with: submodules: recursive + fetch-depth: 0 - uses: actions/setup-go@v3 with: go-version: 1.19 - run: make test - env: - KUNITORI_SKIP_REQUEST_GITHUB_API: 1 From 8c8fbc8872d1ea9ff5b39935d7973917586b2f36 Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Tue, 20 Dec 2022 23:39:03 +0900 Subject: [PATCH 5/7] fix message --- cmd/kunitori/main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/kunitori/main.go b/cmd/kunitori/main.go index 474639b..dacc92a 100644 --- a/cmd/kunitori/main.go +++ b/cmd/kunitori/main.go @@ -32,7 +32,9 @@ func main() { } defaultHelpMessage := `Kunitori -- generate ... generate chart + +[subcommands] +generate ... generate Kunitori chart ` if len(os.Args) < 2 { @@ -47,7 +49,7 @@ func main() { generateJson := generateCmd.Bool("json", false, "export as json format") generateUrl := generateCmd.String("url", "", "repository url") generatePath := generateCmd.String("path", "", "repository path") - generateRegion := generateCmd.String("region", "JP", "chart region (default: JP)") + generateRegion := generateCmd.String("region", "JP", "chart region") generateSince := generateCmd.String( "since", "", @@ -61,12 +63,12 @@ func main() { generateInterval := generateCmd.Duration( "interval", time.Hour*24*30, - "commit pick interval (default: 30 days)", + "commit pick interval", ) generateLimit := generateCmd.Int( "limit", 12, - fmt.Sprintf("commit pick limit (default: 12, max: %v)", pkg.SearchCommitMaxLimit), + "commit pick limit", ) var filters arrayFlags From df6535cd2d3b5c7fe8bb079fd5363afc50ac9d4e Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Wed, 21 Dec 2022 00:12:32 +0900 Subject: [PATCH 6/7] add goreleaser --- .github/workflows/release.yml | 26 ++++++++++++++++++++++++++ .gitignore | 2 ++ .goreleaser.yml | 21 +++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e375d94 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 24120ed..9702a30 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ go.work .envrc /*.html /*.json + +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..3c6dfe5 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,21 @@ +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + main: ./cmd/kunitori +archives: + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + skip: true From 27c6aceff42bbe67cccc51a524652334c5fc5c1a Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Wed, 21 Dec 2022 00:30:46 +0900 Subject: [PATCH 7/7] add release --- .gitignore | 2 +- .goreleaser.yml | 5 +++++ Makefile | 2 +- bin/.gitignore | 2 -- cmd/kunitori/main.go | 16 ++++++++++++---- 5 files changed, 19 insertions(+), 8 deletions(-) delete mode 100644 bin/.gitignore diff --git a/.gitignore b/.gitignore index 9702a30..1460bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -29,5 +29,5 @@ go.work .envrc /*.html /*.json - +/kunitori dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml index 3c6dfe5..1f68ab4 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -6,6 +6,11 @@ builds: - windows - darwin main: ./cmd/kunitori + binary: kunitori + ldflags: + - -s -w + - -X main.Version={{.Version}} + - -X main.ShortCommit={{.ShortCommit}} archives: - replacements: darwin: Darwin diff --git a/Makefile b/Makefile index 255a6a3..ac2fc40 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ testall: .PHONY: build build: - go build -o ./bin/kunitori -v ./cmd/kunitori/ + go build -v ./cmd/kunitori/ .PHONY: fmt fmt: diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/cmd/kunitori/main.go b/cmd/kunitori/main.go index dacc92a..9febf58 100644 --- a/cmd/kunitori/main.go +++ b/cmd/kunitori/main.go @@ -15,6 +15,11 @@ import ( "time" ) +var ( + Version = "unset" + ShortCommit = "unset" +) + type arrayFlags []string func (i *arrayFlags) String() string { @@ -31,11 +36,14 @@ func main() { log.SetOutput(io.Discard) } - defaultHelpMessage := `Kunitori + defaultHelpMessage := fmt.Sprintf(`Kunitori (国盗り) + +Version: %v +Commit: %v -[subcommands] -generate ... generate Kunitori chart -` +SubCommands: + generate ... generate Kunitori chart +`, Version, ShortCommit) if len(os.Args) < 2 { fmt.Print(defaultHelpMessage)