-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
15 changed files
with
424 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.