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 new file mode 100644 index 0000000..4be294d --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,55 @@ +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 + fetch-depth: 0 + + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - run: make test 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 30b3c74..1460bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,7 @@ go.work # End of https://www.toptal.com/developers/gitignore/api/go .envrc -/chart.html -/generate.json +/*.html +/*.json +/kunitori +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..1f68ab4 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,26 @@ +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + main: ./cmd/kunitori + binary: kunitori + ldflags: + - -s -w + - -X main.Version={{.Version}} + - -X main.ShortCommit={{.ShortCommit}} +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 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 474639b..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,9 +36,14 @@ func main() { log.SetOutput(io.Discard) } - defaultHelpMessage := `Kunitori -- generate ... generate chart -` + defaultHelpMessage := fmt.Sprintf(`Kunitori (国盗り) + +Version: %v +Commit: %v + +SubCommands: + generate ... generate Kunitori chart +`, Version, ShortCommit) if len(os.Args) < 2 { fmt.Print(defaultHelpMessage) @@ -47,7 +57,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 +71,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 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) {