fix: build script

pull/34/head
CXM 2 years ago
parent 0fcc85df24
commit b4329e5f5c

6
.gitignore vendored

@ -1,5 +1,7 @@
.idea
.vscode
__debug_bin
!*.example
dist/
config.yaml
*.log
paopao-api
paopao-ce*

@ -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

@ -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
Loading…
Cancel
Save