Skip to content

Commit

Permalink
docs(readme): add badges in the readme (#25)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
shipengqi authored Mar 11, 2024
1 parent f16ba87 commit b921220
Show file tree
Hide file tree
Showing 15 changed files with 424 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ builds:
- goos: windows
goarch: ppc64le
ldflags:
- -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 }}"
- -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 }}"
archives:
- name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}"
# wrap_in_directory: true
Expand Down
105 changes: 78 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,78 @@
# The project's root import path
PKG := github.com/shipengqi/commitizen
# set version package
VERSION_PKG=github.com/shipengqi/component-base/version

ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --tags --always --match='v*')
endif

# set git commit and tree state
GIT_COMMIT = $(shell git rev-parse HEAD)
ifneq ($(shell git status --porcelain 2> /dev/null),)
GIT_TREE_STATE ?= dirty
else
GIT_TREE_STATE ?= clean
endif

# set ldflags
GO_LDFLAGS += -X $(VERSION_PKG).Version=$(VERSION) \
-X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) \
-X $(VERSION_PKG).GitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PKG).BuildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')

.PHONY: go.build
go.build:
@echo "===========> Building: $(OUTPUT_DIR)/$(BIN)"
@CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(BIN) ${PKG}
.PHONY: all
all: modules lint test build

# ==============================================================================
# Includes

include hack/include/common.mk # make sure include common.mk at the first include line
include hack/include/tools.mk
include hack/include/go.mk
include hack/include/test.mk
include hack/include/release.mk

# ==============================================================================
# Usage

define USAGE_OPTIONS

Options:
VERSION The version information compiled into binaries.
The default is obtained from gsemver or git.
PUBLISH Whether to publish a release to Github. Default is 0.
This option is available when using: make release
GITHUB_TOKEN Token used to access Github.
This option is available when using: make release
V Set to 1 enable verbose build. Default is 0.
DEBUG Whether to generate debug symbols. Default is 0.
endef
export USAGE_OPTIONS

# ==============================================================================
# Targets

## build: build binary file.
.PHONY: build
build: modules
@$(MAKE) go.build

## tag: generate release tag.
.PHONY: tag
tag:
@$(MAKE) release.tag

## release: release a version.
.PHONY: release
release:
@$(MAKE) release.run

## modules: add missing and remove unused modules.
.PHONY: modules
modules:
@go mod tidy

## clean: remove all files that are generated by building.
.PHONY: clean
clean:
@$(MAKE) go.clean

## lint: Check syntax and styling of go sources.
.PHONY: lint
lint:
@$(MAKE) go.lint

## test: run unit test and get test coverage.
.PHONY: test
test:
@$(MAKE) test.cover

## test-e2e: run e2e test.
.PHONY: test-e2e
test-e2e:
@$(MAKE) test.e2e

## help: show help information.
.PHONY: help
help: Makefile
@echo -e "\nUsage: make <TARGETS> <OPTIONS> ...\n\nTargets:"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo "$$USAGE_OPTIONS"
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# commitizen

[![Go Report Card](https://goreportcard.com/badge/github.com/shipengqi/commitizen)](https://goreportcard.com/report/github.com/shipengqi/commitizen)
[![release](https://img.shields.io/github/release/shipengqi/commitizen.svg)](https://github.com/shipengqi/commitizen/releases)
[![license](https://img.shields.io/github/license/shipengqi/commitizen)](https://github.com/shipengqi/commitizen/blob/main/LICENSE)

Command line utility to standardize git commit messages, golang version. Forked from [commitizen-go](https://github.com/lintingzhen/commitizen-go).

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

![demo](docs/images/demo.gif)

## Getting Started

```
Expand All @@ -13,8 +19,9 @@ Usage:
commitizen
commitizen [command]
Available Commands:
init Initialize this tool to git-core as git-cz.
Available Commands:
init Install this tool to git-core as git-cz.
version Print the CLI version information.
help Help about any command
Flags:
Expand All @@ -38,7 +45,7 @@ $ git cz

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

Then initialize this tool to git-core as git-cz:
Then install this tool to git-core as git-cz:
```
$ commitizen init
```
Expand Down Expand Up @@ -100,7 +107,7 @@ items:
- name: subject
desc: "Subject. Concise description of the changes. Imperative, lower case and no final dot:"
type: input
required: true
required: true # (optional) If true, enable a validator that requires the control have a non-empty value.
- name: body
desc: "Body. Motivation for the change and contrast this with previous behavior:"
type: textarea
Expand Down Expand Up @@ -138,4 +145,6 @@ items:
type: input
# ...
format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}"`
```
```

![multiple-templates](docs/images/multiple-templates.png)
7 changes: 4 additions & 3 deletions cmd/cz/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

func NewInitCmd() *cobra.Command {
c := &cobra.Command{
Use: "init",
Short: "Initialize this tool to git-core as git-cz.",
Use: "init",
Aliases: []string{"install"},
Short: "Install this tool to git-core as git-cz.",
RunE: func(_ *cobra.Command, _ []string) error {
src, err := exec.LookPath(os.Args[0])
if err != nil {
Expand All @@ -23,7 +24,7 @@ func NewInitCmd() *cobra.Command {
if err != nil {
return err
}
fmt.Printf("Init commitizen to %s\n", dst)
fmt.Printf("Install commitizen to %s\n", dst)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cz/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func NewVersionCmd() *cobra.Command {
c := &cobra.Command{
Use: "version",
Short: "Print the version information.",
Short: "Print the CLI version information.",
Run: func(_ *cobra.Command, _ []string) {
fmt.Println(version.Get().String())
},
Expand Down
Binary file added docs/images/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/multiple-templates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

# Copyright (c) 2022 PengQi Shi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset

if [[ -z "${PKG}" ]]; then
echo "PKG must be set"
exit 1
fi
if [[ -z "${BIN}" ]]; then
echo "BIN must be set"
exit 1
fi
if [[ -z "${GOOS}" ]]; then
echo "GOOS must be set"
exit 1
fi


if [[ -z "${GO_LDFLAGS}" ]]; then
echo "GO_LDFLAGS must be set"
exit 1
fi

if [[ -z "${OUTPUT_DIR}" ]]; then
echo "OUTPUT_DIR must be set"
exit 1
fi

GCFLAGS=""
if [[ ${DEBUG:-} = "1" ]]; then
GCFLAGS="all=-N -l"
fi

export CGO_ENABLED=0

OUTPUT=${OUTPUT_DIR}/${BIN}
if [[ "${GOOS}" = "windows" ]]; then
OUTPUT="${OUTPUT}.exe"
fi

CGO_ENABLED=0 go build \
-o ${OUTPUT} \
-gcflags "${GCFLAGS}" \
-ldflags "${GO_LDFLAGS}" \
${PKG}

if [[ "$?" -eq 0 ]];then
echo "Build ${OUTPUT} SUCCESS"
else
echo "Build ${OUTPUT} FAILED"
exit 1
fi
24 changes: 24 additions & 0 deletions hack/ensure_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Copyright (c) 2022 PengQi Shi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version="${VERSION}"
if [[ "${version}" == "" ]];then
version=v`gsemver bump` # such as 0.0.0+24.be1f3ad
fi

if [[ -z "`git tag -l ${version}`" ]];then
git tag -a -m "release version ${version}" ${version}
fi
52 changes: 52 additions & 0 deletions hack/include/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# The binary to build.
BIN ?= commitizen

# This repo's root import path
PKG := github.com/shipengqi/commitizen
VERSION_PKG=github.com/shipengqi/component-base/version

ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --tags --always --match='v*')
endif

ifeq ($(origin REPO_ROOT),undefined)
REPO_ROOT := $(shell git rev-parse --show-toplevel)
endif

# set git commit and tree state
GIT_COMMIT = $(shell git rev-parse HEAD)
ifneq ($(shell git status --porcelain 2> /dev/null),)
GIT_TREE_STATE ?= dirty
else
GIT_TREE_STATE ?= clean
endif

ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
platform_temp = $(subst -, ,$(ARCH))
GOOS = $(word 1, $(platform_temp))
GOARCH = $(word 2, $(platform_temp))

ifeq ($(origin OUTPUT_DIR),undefined)
OUTPUT_DIR := $(REPO_ROOT)/_output/$(GOOS)/$(GOARCH)/bin
$(shell mkdir -p $(OUTPUT_DIR))
endif

# Specify tools.
BUILD_TOOLS ?= golangci-lint releaser ginkgo

# Makefile settings
# The --no-print-directory option of 'make' tells 'make' not to print
# the message about entering and leaving the working directory.
ifndef V
MAKEFLAGS += --no-print-directory
endif

ifeq ($(origin PUBLISH),undefined)
PUBLISH := 0
endif


GO_LDFLAGS += -X $(VERSION_PKG).Version=$(VERSION) \
-X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) \
-X $(VERSION_PKG).GitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PKG).BuildTime=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
46 changes: 46 additions & 0 deletions hack/include/go.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2022 PengQi Shi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

GO_SUPPORTED_VERSIONS ?= 1.18|1.19|1.20|1.21|1.22

.PHONY: go.build.verify
go.build.verify:
ifneq ($(shell go version | grep -q -E '\bgo($(GO_SUPPORTED_VERSIONS))\b' && echo 0 || echo 1), 0)
$(error unsupported go version. Please install one of the following supported version: '$(GO_SUPPORTED_VERSIONS)')
endif

.PHONY: go.build.dirs
go.build.dirs:
@mkdir -p $(OUTPUT_DIR)

.PHONY: go.build
go.build: go.build.verify go.build.dirs
@echo "===========> Building: $(OUTPUT_DIR)/$(BIN)"
@GOOS=$(GOOS) \
PKG=$(PKG) BIN=$(BIN) \
OUTPUT_DIR=$(OUTPUT_DIR) \
GO_LDFLAGS="$(GO_LDFLAGS)" \
bash $(REPO_ROOT)/hack/build.sh

.PHONY: go.lint
go.lint: tools.verify.golangci-lint
@echo "===========> Run golangci-lint to lint source codes"
@golangci-lint run -c $(REPO_ROOT)/.golangci.yaml $(REPO_ROOT)/...

# `-` indicates that ignore the command error
# `-rm -vrf $(OUTPUT_DIR)` ignore if rm command execute error.
.PHONY: go.clean
go.clean:
@echo "===========> Cleaning all build output"
@-rm -vrf $(OUTPUT_DIR)
Loading

0 comments on commit b921220

Please sign in to comment.