Skip to content

Commit

Permalink
fix(build): imp makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
ccebot committed Dec 19, 2023
1 parent 1edb9ba commit 36026ae
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 45 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
/ui/package-lock.json
/demo/mock/output/
/upload/
/tmp/cache/.data.db
/tmp/.temp.yaml
/tmp/.default.yaml
/tmp/.config.yaml
Expand Down
2 changes: 1 addition & 1 deletion .zd.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version =
Version = 3.1
Language = zh

68 changes: 25 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
VERSION=$(head -n 1 VERSION)
PROJECT=zd

ifeq ($(OS),Windows_NT)
OS="Windows"
else
ifeq ($(shell uname),Darwin)
OS="Mac"
else
OS="Unix"
endif
endif

QINIU_DIR="${HOME}/work/zentao/qiniu/"

QINIU_DIST_DIR=${QINIU_DIR}${PROJECT}/${VERSION}/
PACKAGE=${PROJECT}-${VERSION}
BIN_DIR=bin
BIN_ZIP_DIR=${BIN_DIR}/zip/${PROJECT}/${VERSION}/
BIN_OUT=${BIN_DIR}/${PROJECT}/${VERSION}/
CLIENT_OUT_DIR=client/out/

CLIENT_BIN_DIR=client/bin/
CLIENT_OUT_DIR=client/out/
CLIENT_OUT_DIR_EXECUTABLE=${CLIENT_OUT_DIR}executable/
CLIENT_OUT_DIR_UPGRADE=${CLIENT_OUT_DIR}upgrade/

CLIENT_UI_DIR=client/ui/

COMMAND_MAIN_DIR=cmd/command/
COMMAND_MAIN_FILE=${COMMAND_MAIN_DIR}main.go

SERVER_MAIN_FILE=cmd/server/main.go

BUILD_TIME=`git show -s --format=%cd`
GO_VERSION=`go version`
GIT_HASH=`git show -s --format=%H`
BUILD_CMD_UNIX=go build -ldflags "-X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'"
BUILD_CMD_WIN=go build -ldflags "-s -w -X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'"
.EXPORT_ALL_VARIABLES:
VERSION := $(shell head -n 1 VERSION)
PROJECT := zd
QINIU_DIR := "${HOME}/work/zentao/qiniu/"
QINIU_DIST_DIR := ${QINIU_DIR}${PROJECT}/${VERSION}/
PACKAGE := ${PROJECT}-${VERSION}
BIN_DIR := bin
BIN_ZIP_DIR := ${BIN_DIR}/zip/${PROJECT}/${VERSION}/
BIN_OUT := ${BIN_DIR}/${PROJECT}/${VERSION}/
CLIENT_OUT_DIR := client/out/
CLIENT_BIN_DIR := client/bin/
CLIENT_OUT_DIR := client/out/
CLIENT_OUT_DIR_EXECUTABLE := ${CLIENT_OUT_DIR}executable/
CLIENT_OUT_DIR_UPGRADE := ${CLIENT_OUT_DIR}upgrade/
CLIENT_UI_DIR := client/ui/
COMMAND_MAIN_DIR := cmd/command/
COMMAND_MAIN_FILE := ${COMMAND_MAIN_DIR}main.go
SERVER_MAIN_FILE := cmd/server/main.go
BUILD_TIME := $(shell git show -s --format=%cd)
GO_VERSION := $(go version)
GIT_HASH := $(git show -s --format=%H)
BUILD_CMD_UNIX := go build -ldflags "-X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'"
BUILD_CMD_WIN := go build -ldflags "-s -w -X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'"

default: clear build_ui prepare_build compile_all copy_files package package_upgrade
clear:
Expand Down Expand Up @@ -292,11 +276,9 @@ package_upgrade:
done

update_version_in_config:
ifeq ($(OS),"Mac")
@gsed -i "s/Version.*/Version = ${VERSION}/" .zd.conf
else
@echo 'update version in config ${VERSION}'
@echo 'gen version'
@sed -i "s/Version.*/Version = ${VERSION}/" .zd.conf
endif

gen_version_file:
@echo 'gen version'
Expand Down
81 changes: 81 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ version: '3'
vars:
GOOS: $(go env GOOS)
GOARCH: $(go env GOARCH)
BIN_DIR: bin
CLIENT_OUT_DIR: client/out
CLIENT_BIN_DIR: client/bin
QINIU_DIR: .release/qiniu
VERSION:
sh: head -n 1 VERSION
PROJECT: zd
GO_VERSION:
sh: go version
BUILD_TIME:
sh: git show -s --format=%cd
GIT_HASH:
sh: git show -s --format=%H
LDFLAGS: "-w -s \
-X 'main.AppVersion={{.VERSION}}' \
-X 'main.BuildTime={{.BUILD_TIME}}' \
-X 'main.GoVersion={{.GO_VERSION}' \
-X 'main.GitHash={{.GIT_HASH}}'"

tasks:
gofmt:
Expand All @@ -35,3 +46,73 @@ tasks:
desc: build ui
cmds:
- cd ui && yarn install && yarn build --dest ../client/ui

clear:
desc: clear
cmds:
- rm -rf {{.BIN_DIR}}
- rm -rf {{.CLIENT_OUT_DIR}}

update_version_in_config:
desc: update_version_in_config
cmds:
- sed -i "s/Version.*/Version = {{.VERSION}}/" .zd.conf

gen_version_file:
desc: gen_version_file
cmds:
- echo 'gen version'
- mkdir -p {{.QINIU_DIR}}/{{.PROJECT}}/
- echo '{"version":"{{.VERSION}}"}' > {{.QINIU_DIR}}/{{.PROJECT}}/version.json

prepare_res:
desc: prepare_res
cmds:
- echo 'start prepare res'
- cp res/zh/sample.yaml demo/default.yaml
- rm -rf {{.BIN_DIR}}

prepare_build:
desc: prepare_build
cmds:
- task: clear
- task: update_version_in_config
- task: gen_version_file
- task: prepare_res

compile_all:
desc: compile_all
cmds:
- task: compile_linux

compile_linux:
desc: compile_linux
cmds:
- task: compile_server_linux
- task: package_gui_linux_client
- task: compile_command_linux

compile_server_linux:
desc: compile_server_linux
cmds:
- echo 'start compile server linux'
- rm -rf {{.BIN_DIR}}/linux/server
- GOOS=linux GOARCH=amd64 go build -ldflags "{{.LDFLAGS}}" -o {{.BIN_DIR}}/linux/server cmd/server/main.go

package_gui_linux_client:
desc: package_gui_linux_client
cmds:
- echo 'start package gui linux'
- rm -rf {{.CLIENT_BIN_DIR}}/* && mkdir -p {{.CLIENT_BIN_DIR}}linux
- cp -rf {{.BIN_DIR}}/linux/server {{.CLIENT_BIN_DIR}}linux/server
- cd client && npm run package-linux && cp -r icon out/{{.PROJECT}}-linux-x64 && cd ..

default:
cmds:
- task: clear
- task: build_ui
- task: prepare_build
- task: compile_all
- task: copy_files
- task: package
- task: package_upgrade
Binary file added tmp/cache/.data.db
Binary file not shown.

0 comments on commit 36026ae

Please sign in to comment.