Skip to content

Commit b921220

Browse files
authored
docs(readme): add badges in the readme (#25)
* docs(readme): add badges in the readme * chore(hack): update makefile and add build scripts * chore(makefile): remove unused command in makefile * docs(readme): add demo images * docs(readme): update demo image
1 parent f16ba87 commit b921220

File tree

15 files changed

+424
-37
lines changed

15 files changed

+424
-37
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ builds:
3030
- goos: windows
3131
goarch: ppc64le
3232
ldflags:
33-
- -X "github.com/shipengqi/component-base/version.Version={{ .Tag }}" -X "github.com/shipengqi/component-base/version.GitCommit={{ .ShortCommit }}" -X "github.com/shipengqi/component-base/version.BuildDate={{ .Date }}" -X "github.com/shipengqi/component-base/version.GitTreeState={{ .Env.GIT_TREE_STATE }}"
33+
- -X "github.com/shipengqi/component-base/version.Version={{ .Tag }}" -X "github.com/shipengqi/component-base/version.GitCommit={{ .ShortCommit }}" -X "github.com/shipengqi/component-base/version.BuildTime={{ .Date }}" -X "github.com/shipengqi/component-base/version.GitTreeState={{ .Env.GIT_TREE_STATE }}"
3434
archives:
3535
- name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}"
3636
# wrap_in_directory: true

Makefile

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,78 @@
1-
# The project's root import path
2-
PKG := github.com/shipengqi/commitizen
3-
# set version package
4-
VERSION_PKG=github.com/shipengqi/component-base/version
5-
6-
ifeq ($(origin VERSION), undefined)
7-
VERSION := $(shell git describe --tags --always --match='v*')
8-
endif
9-
10-
# set git commit and tree state
11-
GIT_COMMIT = $(shell git rev-parse HEAD)
12-
ifneq ($(shell git status --porcelain 2> /dev/null),)
13-
GIT_TREE_STATE ?= dirty
14-
else
15-
GIT_TREE_STATE ?= clean
16-
endif
17-
18-
# set ldflags
19-
GO_LDFLAGS += -X $(VERSION_PKG).Version=$(VERSION) \
20-
-X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) \
21-
-X $(VERSION_PKG).GitTreeState=$(GIT_TREE_STATE) \
22-
-X $(VERSION_PKG).BuildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
23-
24-
.PHONY: go.build
25-
go.build:
26-
@echo "===========> Building: $(OUTPUT_DIR)/$(BIN)"
27-
@CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(BIN) ${PKG}
1+
.PHONY: all
2+
all: modules lint test build
3+
4+
# ==============================================================================
5+
# Includes
6+
7+
include hack/include/common.mk # make sure include common.mk at the first include line
8+
include hack/include/tools.mk
9+
include hack/include/go.mk
10+
include hack/include/test.mk
11+
include hack/include/release.mk
12+
13+
# ==============================================================================
14+
# Usage
15+
16+
define USAGE_OPTIONS
17+
18+
Options:
19+
VERSION The version information compiled into binaries.
20+
The default is obtained from gsemver or git.
21+
PUBLISH Whether to publish a release to Github. Default is 0.
22+
This option is available when using: make release
23+
GITHUB_TOKEN Token used to access Github.
24+
This option is available when using: make release
25+
V Set to 1 enable verbose build. Default is 0.
26+
DEBUG Whether to generate debug symbols. Default is 0.
27+
endef
28+
export USAGE_OPTIONS
29+
30+
# ==============================================================================
31+
# Targets
32+
33+
## build: build binary file.
34+
.PHONY: build
35+
build: modules
36+
@$(MAKE) go.build
37+
38+
## tag: generate release tag.
39+
.PHONY: tag
40+
tag:
41+
@$(MAKE) release.tag
42+
43+
## release: release a version.
44+
.PHONY: release
45+
release:
46+
@$(MAKE) release.run
47+
48+
## modules: add missing and remove unused modules.
49+
.PHONY: modules
50+
modules:
51+
@go mod tidy
52+
53+
## clean: remove all files that are generated by building.
54+
.PHONY: clean
55+
clean:
56+
@$(MAKE) go.clean
57+
58+
## lint: Check syntax and styling of go sources.
59+
.PHONY: lint
60+
lint:
61+
@$(MAKE) go.lint
62+
63+
## test: run unit test and get test coverage.
64+
.PHONY: test
65+
test:
66+
@$(MAKE) test.cover
67+
68+
## test-e2e: run e2e test.
69+
.PHONY: test-e2e
70+
test-e2e:
71+
@$(MAKE) test.e2e
72+
73+
## help: show help information.
74+
.PHONY: help
75+
help: Makefile
76+
@echo -e "\nUsage: make <TARGETS> <OPTIONS> ...\n\nTargets:"
77+
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
78+
@echo "$$USAGE_OPTIONS"

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# commitizen
22

3+
[![Go Report Card](https://goreportcard.com/badge/github.com/shipengqi/commitizen)](https://goreportcard.com/report/github.com/shipengqi/commitizen)
4+
[![release](https://img.shields.io/github/release/shipengqi/commitizen.svg)](https://github.com/shipengqi/commitizen/releases)
5+
[![license](https://img.shields.io/github/license/shipengqi/commitizen)](https://github.com/shipengqi/commitizen/blob/main/LICENSE)
6+
37
Command line utility to standardize git commit messages, golang version. Forked from [commitizen-go](https://github.com/lintingzhen/commitizen-go).
48

59
The [survey](https://github.com/AlecAivazis/survey) project is no longer maintained. Therefore, this project uses [bubbletea](https://github.com/charmbracelet/bubbletea) instead.
610

11+
![demo](docs/images/demo.gif)
12+
713
## Getting Started
814

915
```
@@ -13,8 +19,9 @@ Usage:
1319
commitizen
1420
commitizen [command]
1521
16-
Available Commands:
17-
init Initialize this tool to git-core as git-cz.
22+
Available Commands:
23+
init Install this tool to git-core as git-cz.
24+
version Print the CLI version information.
1825
help Help about any command
1926
2027
Flags:
@@ -38,7 +45,7 @@ $ git cz
3845

3946
Download the pre-compiled binaries from the [releases page](https://github.com/shipengqi/commitizen/releases) and copy them to the desired location.
4047

41-
Then initialize this tool to git-core as git-cz:
48+
Then install this tool to git-core as git-cz:
4249
```
4350
$ commitizen init
4451
```
@@ -100,7 +107,7 @@ items:
100107
- name: subject
101108
desc: "Subject. Concise description of the changes. Imperative, lower case and no final dot:"
102109
type: input
103-
required: true
110+
required: true # (optional) If true, enable a validator that requires the control have a non-empty value.
104111
- name: body
105112
desc: "Body. Motivation for the change and contrast this with previous behavior:"
106113
type: textarea
@@ -138,4 +145,6 @@ items:
138145
type: input
139146
# ...
140147
format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}"`
141-
```
148+
```
149+
150+
![multiple-templates](docs/images/multiple-templates.png)

cmd/cz/init.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212

1313
func NewInitCmd() *cobra.Command {
1414
c := &cobra.Command{
15-
Use: "init",
16-
Short: "Initialize this tool to git-core as git-cz.",
15+
Use: "init",
16+
Aliases: []string{"install"},
17+
Short: "Install this tool to git-core as git-cz.",
1718
RunE: func(_ *cobra.Command, _ []string) error {
1819
src, err := exec.LookPath(os.Args[0])
1920
if err != nil {
@@ -23,7 +24,7 @@ func NewInitCmd() *cobra.Command {
2324
if err != nil {
2425
return err
2526
}
26-
fmt.Printf("Init commitizen to %s\n", dst)
27+
fmt.Printf("Install commitizen to %s\n", dst)
2728
return nil
2829
},
2930
}

cmd/cz/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func NewVersionCmd() *cobra.Command {
1111
c := &cobra.Command{
1212
Use: "version",
13-
Short: "Print the version information.",
13+
Short: "Print the CLI version information.",
1414
Run: func(_ *cobra.Command, _ []string) {
1515
fmt.Println(version.Get().String())
1616
},

docs/images/demo.gif

160 KB
Loading

docs/images/multiple-templates.png

11.6 KB
Loading

hack/build.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2022 PengQi Shi
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
20+
if [[ -z "${PKG}" ]]; then
21+
echo "PKG must be set"
22+
exit 1
23+
fi
24+
if [[ -z "${BIN}" ]]; then
25+
echo "BIN must be set"
26+
exit 1
27+
fi
28+
if [[ -z "${GOOS}" ]]; then
29+
echo "GOOS must be set"
30+
exit 1
31+
fi
32+
33+
34+
if [[ -z "${GO_LDFLAGS}" ]]; then
35+
echo "GO_LDFLAGS must be set"
36+
exit 1
37+
fi
38+
39+
if [[ -z "${OUTPUT_DIR}" ]]; then
40+
echo "OUTPUT_DIR must be set"
41+
exit 1
42+
fi
43+
44+
GCFLAGS=""
45+
if [[ ${DEBUG:-} = "1" ]]; then
46+
GCFLAGS="all=-N -l"
47+
fi
48+
49+
export CGO_ENABLED=0
50+
51+
OUTPUT=${OUTPUT_DIR}/${BIN}
52+
if [[ "${GOOS}" = "windows" ]]; then
53+
OUTPUT="${OUTPUT}.exe"
54+
fi
55+
56+
CGO_ENABLED=0 go build \
57+
-o ${OUTPUT} \
58+
-gcflags "${GCFLAGS}" \
59+
-ldflags "${GO_LDFLAGS}" \
60+
${PKG}
61+
62+
if [[ "$?" -eq 0 ]];then
63+
echo "Build ${OUTPUT} SUCCESS"
64+
else
65+
echo "Build ${OUTPUT} FAILED"
66+
exit 1
67+
fi

hack/ensure_tag.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2022 PengQi Shi
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
version="${VERSION}"
18+
if [[ "${version}" == "" ]];then
19+
version=v`gsemver bump` # such as 0.0.0+24.be1f3ad
20+
fi
21+
22+
if [[ -z "`git tag -l ${version}`" ]];then
23+
git tag -a -m "release version ${version}" ${version}
24+
fi

hack/include/common.mk

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# The binary to build.
2+
BIN ?= commitizen
3+
4+
# This repo's root import path
5+
PKG := github.com/shipengqi/commitizen
6+
VERSION_PKG=github.com/shipengqi/component-base/version
7+
8+
ifeq ($(origin VERSION), undefined)
9+
VERSION := $(shell git describe --tags --always --match='v*')
10+
endif
11+
12+
ifeq ($(origin REPO_ROOT),undefined)
13+
REPO_ROOT := $(shell git rev-parse --show-toplevel)
14+
endif
15+
16+
# set git commit and tree state
17+
GIT_COMMIT = $(shell git rev-parse HEAD)
18+
ifneq ($(shell git status --porcelain 2> /dev/null),)
19+
GIT_TREE_STATE ?= dirty
20+
else
21+
GIT_TREE_STATE ?= clean
22+
endif
23+
24+
ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
25+
platform_temp = $(subst -, ,$(ARCH))
26+
GOOS = $(word 1, $(platform_temp))
27+
GOARCH = $(word 2, $(platform_temp))
28+
29+
ifeq ($(origin OUTPUT_DIR),undefined)
30+
OUTPUT_DIR := $(REPO_ROOT)/_output/$(GOOS)/$(GOARCH)/bin
31+
$(shell mkdir -p $(OUTPUT_DIR))
32+
endif
33+
34+
# Specify tools.
35+
BUILD_TOOLS ?= golangci-lint releaser ginkgo
36+
37+
# Makefile settings
38+
# The --no-print-directory option of 'make' tells 'make' not to print
39+
# the message about entering and leaving the working directory.
40+
ifndef V
41+
MAKEFLAGS += --no-print-directory
42+
endif
43+
44+
ifeq ($(origin PUBLISH),undefined)
45+
PUBLISH := 0
46+
endif
47+
48+
49+
GO_LDFLAGS += -X $(VERSION_PKG).Version=$(VERSION) \
50+
-X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) \
51+
-X $(VERSION_PKG).GitTreeState=$(GIT_TREE_STATE) \
52+
-X $(VERSION_PKG).BuildTime=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')

0 commit comments

Comments
 (0)