diff --git a/.gitignore b/.gitignore index 4b772892..4f7e39cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +.idea .vscode -__debug_bin +!*.example +dist/ config.yaml *.log -paopao-api \ No newline at end of file +paopao-ce* diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0c3a847f --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +.PHONY: all build clean fmt help +BUILD_VERSION := $(shell cat version) +BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S') +SHA_SHORT := $(shell git rev-parse --short HEAD) +all: fmt build +build: + @go mod download + @echo Build paopao-ce + bash build.sh paopao-ce +clean: + @go clean + @find ./dist -type f -exec rm -r {} + + @find ./tmp -type f -exec rm -r {} + +fmt: + @echo Formatting... + @go fmt ./global/... + @go fmt ./internal/... + @go fmt ./pkg/... + @go vet -composites=false ./global/... + @go vet -composites=false ./internal/... + @go vet -composites=false ./pkg/... +help: + @echo "make: make" + @echo "make build: build executables" +.EXPORT_ALL_VARIABLES: +GO111MODULE = on diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..a0284a5e --- /dev/null +++ b/build.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2155 +set -e +DIST_PREFIX=${1} +DEBUG_MODE=${2} +TARGET_DIR="dist" +PLATFORMS="darwin/arm64 linux/amd64 windows/amd64" + +rm -rf ${TARGET_DIR} +mkdir ${TARGET_DIR} + +for pl in ${PLATFORMS}; do + export CGO_ENABLED=0 + export GOOS=$(echo "${pl}" | cut -d'/' -f1) + export GOARCH=$(echo "${pl}" | cut -d'/' -f2) + export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH} + if [ "${GOOS}" == "windows" ]; then + export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}.exe + fi + + echo "build => ${TARGET}" + if [ "${DEBUG_MODE}" == "debug" ]; then + go build -trimpath -gcflags "all=-N -l" -o "${TARGET}" \ + -ldflags "-X 'main.version=${BUILD_VERSION}' \ + -X 'main.buildDate=${BUILD_DATE}' \ + -X 'main.commitID=${SHA_SHORT}'\ + -w -s" + else + go build -trimpath -o "${TARGET}" \ + -ldflags "-X 'main.version=${BUILD_VERSION}' \ + -X 'main.buildDate=${BUILD_DATE}' \ + -X 'main.commitID=${SHA_SHORT}'\ + -w -s" + fi +done diff --git a/version b/version new file mode 100644 index 00000000..e69de29b