-
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.
Signed-off-by: xiexianbin <me@xiexianbin.cn>
- Loading branch information
1 parent
b93567d
commit c3b43bc
Showing
9 changed files
with
245 additions
and
41 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
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
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,30 +1,108 @@ | ||
# https://www.xiexianbin.cn/program/tools/2016-01-09-makefile/index.html | ||
.PHONY: all test clean build build-linux build-mac build-windows | ||
|
||
GOCMD=go | ||
GOBUILD=$(GOCMD) build | ||
GOCLEAN=$(GOCMD) clean | ||
GOTEST=$(GOCMD) test | ||
BINARY_NAME=xca | ||
BINARY_LINUX=$(BINARY_NAME)-linux | ||
BINARY_MAC=$(BINARY_NAME)-darwin | ||
BINARY_WIN=$(BINARY_NAME)-windows | ||
|
||
help: ## Show this help. | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | ||
|
||
all: clean test build build-linux build-mac build-windows ## Build all | ||
test: ## run test | ||
export SHELL:=bash | ||
export SHELLOPTS:=$(if $(SHELLOPTS),$(SHELLOPTS):)pipefail:errexit | ||
|
||
# https://stackoverflow.com/questions/4122831/disable-make-builtin-rules-and-variables-from-inside-the-make-file | ||
MAKEFLAGS += --no-builtin-rules | ||
.SUFFIXES: | ||
|
||
VERSION := latest | ||
BUILD_DATE := $(shell TZ=UTC-8 date +'%Y-%m-%dT%H:%M:%SZ+08:00') | ||
GIT_COMMIT := $(shell git rev-parse HEAD || echo unknown) | ||
GIT_BRANCH := $(shell git rev-parse --symbolic-full-name --verify --quiet --abbrev-ref HEAD) | ||
GIT_TAG := $(shell git describe --exact-match --tags --abbrev=0 2> /dev/null || echo untagged) | ||
GIT_TREE_STATE := $(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi) | ||
RELEASE_TAG := $(shell if [[ "$(GIT_TAG)" =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$$ ]]; then echo "true"; else echo "false"; fi) | ||
DEV_BRANCH := $(shell [ "$(GIT_BRANCH)" = master ] || [ `echo $(GIT_BRANCH) | cut -c -8` = release- ] || [ `echo $(GIT_BRANCH) | cut -c -4` = dev- ] || [ $(RELEASE_TAG) = true ] && echo false || echo true) | ||
|
||
GOCMD ?= go | ||
GOBUILD ?= $(GOCMD) build -v | ||
GOCLEAN ?= $(GOCMD) clean | ||
GOTEST ?= $(GOCMD) test -v -p 20 | ||
|
||
linux-amd64: GOARGS = GOOS=linux GOARCH=amd64 | ||
linux-arm64: GOARGS = GOOS=linux GOARCH=arm64 | ||
linux-ppc64le: GOARGS = GOOS=linux GOARCH=ppc64le | ||
linux-s390x: GOARGS = GOOS=linux GOARCH=s390x | ||
darwin-amd64: GOARGS = GOOS=darwin GOARCH=amd64 | ||
darwin-arm64: GOARGS = GOOS=darwin GOARCH=arm64 | ||
windows-amd64: GOARGS = GOOS=windows GOARCH=amd64 | ||
|
||
BINARY_NAME ?= main | ||
IMG ?= xiexianbin/go-actions-demo:latest | ||
|
||
ifeq ($(RELEASE_TAG),true) | ||
VERSION := $(GIT_TAG) | ||
endif | ||
|
||
# $(info GIT_COMMIT=$(GIT_COMMIT) GIT_BRANCH=$(GIT_BRANCH) GIT_TAG=$(GIT_TAG) GIT_TREE_STATE=$(GIT_TREE_STATE) RELEASE_TAG=$(RELEASE_TAG) DEV_BRANCH=$(DEV_BRANCH) VERSION=$(VERSION)) | ||
# $(info MAKEFILE_LIST=${MAKEFILE_LIST}) | ||
|
||
# -X github.com/xiexianbin/go-actions-demo.version=$(VERSION) | ||
override LDFLAGS += \ | ||
-X main.version=$(VERSION) \ | ||
-X main.buildDate=$(BUILD_DATE) \ | ||
-X main.gitCommit=$(GIT_COMMIT) \ | ||
-X main.gitTreeState=$(GIT_TREE_STATE) | ||
|
||
ifneq ($(GIT_TAG),) | ||
override LDFLAGS += -X main.gitTag=${GIT_TAG} | ||
endif | ||
|
||
SUB_BUILD_CMD ?= $(GOBUILD) -gcflags '${GCFLAGS}' -ldflags '${LDFLAGS} -extldflags -static' | ||
|
||
.PHONY: help | ||
help: ## Show this help | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | ||
|
||
.PHONY: all | ||
all: clean test build linux-amd64 linux-arm64 linux-ppc64le linux-s390x darwin-amd64 darwin-arm64 windows-amd64 ## Build all | ||
|
||
.PHONY: test | ||
test: ## Run test | ||
$(GOTEST) -v ./... | ||
clean: ## run clean bin files | ||
|
||
.PHONY: clean | ||
clean: ## Run clean bin files | ||
$(GOCLEAN) | ||
rm -f bin/$(BINARY_NAME) | ||
build: ## build for current os | ||
$(GOBUILD) -o bin/$(BINARY_NAME) -v | ||
|
||
build-linux: ## build linux amd64 | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY_LINUX) -v | ||
build-mac: ## build mac amd64 | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY_MAC) -v | ||
build-windows: ## build windows amd64 | ||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY_WIN) -v | ||
rm -f bin/* | ||
|
||
.PHONY: build | ||
build: ## Build for current os | ||
${SUB_BUILD_CMD} -o bin/$(BINARY_NAME) | ||
|
||
.PHONY: linux-amd64 | ||
linux-amd64: ## Build linux amd64 | ||
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ | ||
|
||
.PHONY: linux-arm64 | ||
linux-arm64: ## Build linux arm64 | ||
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ | ||
|
||
.PHONY: linux-ppc64le | ||
linux-ppc64le: ## Build linux ppc64le | ||
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ | ||
|
||
.PHONY: linux-s390x | ||
linux-s390x: ## Build linux s390x | ||
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ | ||
|
||
.PHONY: darwin-amd64 | ||
darwin-amd64: ## Build darwin amd64 | ||
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ | ||
|
||
.PHONY: darwin-arm64 | ||
darwin-arm64: ## Build darwin arm64 | ||
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@ | ||
|
||
.PHONY: windows-amd64 | ||
windows-amd64: ## Build windows amd64 | ||
CGO_ENABLED=0 ${GOARGS} ${SUB_BUILD_CMD} -o bin/${BINARY_NAME}-$@.exe | ||
|
||
.PHONY: docker-build | ||
docker-build: test ## Build docker image | ||
docker build -t ${IMG} . | ||
|
||
.PHONY: docker-push | ||
docker-push: ## Push docker image | ||
docker push ${IMG} |
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,18 @@ | ||
# Security Policy | ||
|
||
If you have discovered a security vulnerability in this project, please report it | ||
privately. **Do not disclose it as a public issue.** This gives us time to work with you | ||
to fix the issue before public exposure, reducing the chance that the exploit will be | ||
used before a patch is released. | ||
|
||
You may submit the report in the following ways: | ||
|
||
- send an email to me@xiexianbin.cn | ||
- send us a [private vulnerability report](https://github.com/x-ca/go-ca/security/advisories/new) | ||
|
||
Please provide the following information in your report: | ||
|
||
- A description of the vulnerability and its impact | ||
- How to reproduce the issue | ||
|
||
We ask that you give us 90 days to work on a fix before public exposure. |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
var ( | ||
version = "v0.0.0" // value from VERSION file | ||
buildDate = "1970-01-01T00:00:00Z" // output from `TZ=UTC-8 date +'%Y-%m-%dT%H:%M:%SZ+08:00'` | ||
gitCommit = "" // output from `git rev-parse HEAD` | ||
gitTag = "" // output from `git describe --exact-match --tags HEAD` (if clean tree state) | ||
gitTreeState = "" // determined from `git status --porcelain`. either 'clean' or 'dirty' | ||
) | ||
|
||
type Version struct { | ||
Version string `json:"version"` | ||
BuildDate string `json:"buildDate"` | ||
GitCommit string `json:"gitCommit"` | ||
GitTag string `json:"gitTag"` | ||
GitTreeState string `json:"gitTreeState"` | ||
GoVersion string `json:"goVersion"` | ||
Compiler string `json:"compiler"` | ||
Platform string `json:"platform"` | ||
} | ||
|
||
// GetVersion returns the version information | ||
func GetVersion() Version { | ||
var versionStr string | ||
if gitCommit != "" && gitTag != "" && gitTreeState == "clean" { | ||
// if we have a clean tree state and the current commit is tagged, | ||
// this is an official release. | ||
versionStr = gitTag | ||
} else { | ||
// otherwise formulate a version string based on as much metadata | ||
// information we have available. | ||
versionStr = version | ||
if len(gitCommit) >= 7 { | ||
versionStr += "+" + gitCommit[0:7] | ||
if gitTreeState != "clean" { | ||
versionStr += ".dirty" | ||
} | ||
} else { | ||
versionStr += "+unknown" | ||
} | ||
} | ||
return Version{ | ||
Version: versionStr, | ||
BuildDate: buildDate, | ||
GitCommit: gitCommit, | ||
GitTag: gitTag, | ||
GitTreeState: gitTreeState, | ||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
} | ||
} | ||
|
||
func PrintVersion(cliName string, version Version, short bool) { | ||
fmt.Printf("%s: %s\n", cliName, version.Version) | ||
if short { | ||
return | ||
} | ||
fmt.Printf(" BuildDate: %s\n", version.BuildDate) | ||
fmt.Printf(" GitCommit: %s\n", version.GitCommit) | ||
fmt.Printf(" GitTreeState: %s\n", version.GitTreeState) | ||
if version.GitTag != "" { | ||
fmt.Printf(" GitTag: %s\n", version.GitTag) | ||
} | ||
fmt.Printf(" GoVersion: %s\n", version.GoVersion) | ||
fmt.Printf(" Compiler: %s\n", version.Compiler) | ||
fmt.Printf(" Platform: %s\n", version.Platform) | ||
} |