forked from MartialBE/one-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
95 lines (82 loc) · 2.07 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# https://taskfile.dev
version: '3'
vars:
GOPROXY: 'https://goproxy.cn,direct'
GOSUMDB: sum.golang.google.cn
ROOT_DIR: $(pwd)
BUILD_DIR: $(pwd)/_output
BIN_DIR: $(pwd)/_output/one-hub
VERSION_PKG: one-api/common/config
BUILD_VERSION: $(git describe --tags || echo "dev")
BUILD_DATE: $(date +%Y%m%d)
GIT_BRANCH: $(git branch -r --contains | head -1 | sed -E -e "s%(HEAD ->|origin|upstream)/?%%g" | xargs)
GIT_COMMIT: $(git rev-parse --short HEAD || echo "abcdefgh")
BUILD_RELEASE: "{{.BUILD_VERSION}}-{{.BUILD_DATE}}-{{.GIT_COMMIT}}"
IMAGE: "ttl.sh/one-hub:{{.BUILD_RELEASE}}"
LOCAL_OS: $(go version | awk '{print $NF}')
GOOS: $(go env GOOS)
GOARCH: $(go env GOARCH)
LDFLAGS: "-w -s \
-extldflags '-static' \
-X '{{.VERSION_PKG}}.Version={{.BUILD_VERSION}}' \
-X '{{.VERSION_PKG}}.BuildTime={{.BUILD_DATE}}' \
-X '{{.VERSION_PKG}}.Commit={{.GIT_COMMIT}}'"
tasks:
web:
desc: build web
cmds:
- hack/scripts/genui.sh {{.BUILD_VERSION}}
status:
- test -f web/build/index.html
gomod:
desc: update go mod
cmds:
- go mod tidy
gofmt:
cmds:
- go install golang.org/x/tools/cmd/goimports@latest
- gofmt -s -w .
- goimports -w .
golint:
cmds:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- golangci-lint run -v ./...
lint:
cmds:
- task: gofmt
- task: golint
fmt:
cmds:
- task: gomod
- task: gofmt
- task: golint
clean:
desc: clean
run: once
cmds:
- rm -rf web/build
- rm -rf {{.BUILD_DIR}}
run:
desc: run
deps:
- build
cmds:
- "{{.BIN_DIR}}"
build:
desc: build binary
deps:
- gomod
- web
cmds:
- go build -o {{.BIN_DIR}} -ldflags "{{.LDFLAGS}}"
docker:
desc: build docker image
deps:
- gomod
- web
cmds:
- GOOS=linux GOARCH=amd64 go build -o {{.BIN_DIR}} -ldflags "{{.LDFLAGS}}"
- docker buildx build --pull --push --platform linux/amd64 -t "{{.IMAGE}}" .
default:
cmds:
- task: build