Contents
Task 是一个任务运行器/构建工具,旨在比 GNU Make 等更简单易用。
由于它是用 Go 编写的,Task 只是一个二进制文件,没有其他依赖项,这意味着您不需要为了使用构建工具而烦恼任何复杂的安装设置。
安装 后,您只需在名为 Taskfile.yml
的文件中使用简单的 YAML 规则描述您的构建任务:
task 支持发文件名称
- Taskfile.yml
- taskfile.yml
- Taskfile.yaml
- taskfile.yaml
- Taskfile.dist.yml
- taskfile.dist.yml
- Taskfile.dist.yaml
- taskfile.dist.yaml
示例:
version: '3'
vars:
PROJECT_NAME: cli
BRANCH:
sh: git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
VERSION: "{{ .BRANCH }}"
# 获取最新的tag
# sh: git fetch --tags && git tag | sort -V | tail -1
APP_NAME: "{{ .PROJECT_NAME }}"
GIT_COMMIT:
# 短hash
# sh: git log -n 1 --format=%h
# 长hash
sh: git rev-parse HEAD
GoVersion:
sh: go version | cut -d " " -f 3
BuildTime: '{{now | date "Mon Jan 02 15:04:05 SGT 2006"}}'
Maintainer: tserialt@gmail.com
PKGFLAGS: " -s -w -X 'main.APPVersion={{ .VERSION }}' -X 'main.GoVersion={{ .GoVersion }}' -X 'main.BuildTime={{ .BuildTime }}' -X 'main.GitCommit={{ .GIT_COMMIT }}' "
tasks:
clean:
cmds:
- rm -rf dist/{{ .PROJECT_NAME }}*
run:
cmds:
- go run .
build:
cmds:
- go build -trimpath -ldflags "{{ .PKGFLAGS }}" -o "dist/{{ .APP_NAME }}"
build-linux:
vars:
OS_TYPE: linux
cmds:
- GOOS="{{ .OS_TYPE }}" GOARCH="amd64" go build -trimpath -ldflags "{{ .PKGFLAGS }}" -v -o "dist/{{ .APP_NAME }}-{{ .OS_TYPE }}-amd64"
- GOOS="{{ .OS_TYPE }}" GOARCH="arm64" go build -trimpath -ldflags "{{ .PKGFLAGS }}" -v -o "dist/{{ .APP_NAME }}-{{ .OS_TYPE }}-arm64"
build-mac:
vars:
OS_TYPE: darwin
cmds:
- GOOS="{{ .OS_TYPE }}" GOARCH="amd64" go build -trimpath -ldflags "{{ .PKGFLAGS }}" -v -o "dist/{{ .APP_NAME }}-{{ .OS_TYPE }}-amd64"
- GOOS="{{ .OS_TYPE }}" GOARCH="arm64" go build -trimpath -ldflags "{{ .PKGFLAGS }}" -v -o "dist/{{ .APP_NAME }}-{{ .OS_TYPE }}-arm64"
build-win:
vars:
OS_TYPE: windows
cmds:
- GOOS="{{ .OS_TYPE }}" GOARCH="amd64" go build -trimpath -ldflags "{{ .PKGFLAGS }}" -v -o "dist/{{ .APP_NAME }}-{{ .OS_TYPE }}-amd64.exe"
release:
cmds:
- task: build-linux
- task: build-mac
- task: build-win
- task: banner
banner:
cmds:
- cmd: echo -e "\n******************************\n\n build succeed \n\n******************************\n"
silent: true
default:
deps: [clean]
cmds:
- task: build
- task: banner