Taskfile: update
This commit is contained in:
parent
a49908b96c
commit
7ea74ef927
134
Taskfile.yml
134
Taskfile.yml
@ -1,17 +1,30 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
|
|
||||||
env:
|
vars:
|
||||||
GOOS:
|
GOOS:
|
||||||
sh: go env GOOS
|
sh: go env GOOS
|
||||||
GOARCH:
|
GOARCH:
|
||||||
sh: go env GOARCH
|
sh: go env GOARCH
|
||||||
DESTDIR: /usr/local/sbin
|
|
||||||
|
env:
|
||||||
|
DESTDIR: /usr/local/bin
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cmds:
|
desc: display usage info
|
||||||
- task: build-all
|
summary: |
|
||||||
|
This Taskfile can be used to build and install Go programs. A specific project structure is assumed:
|
||||||
|
- cmd/<binary> - code for a specific command / application
|
||||||
|
- bin/ - where binaries will be output
|
||||||
|
|
||||||
|
The 'update-deps' task updates dependencies for the application.
|
||||||
|
|
||||||
|
Binaries can be installed using the 'install' task to DESTDIR.
|
||||||
|
|
||||||
|
The 'matrix-build' task creates binaries for linux, macos, and windows.
|
||||||
|
|
||||||
|
cmd: go-task --list
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
desc: setup directories
|
desc: setup directories
|
||||||
@ -21,30 +34,57 @@ tasks:
|
|||||||
status:
|
status:
|
||||||
- test -d bin
|
- test -d bin
|
||||||
|
|
||||||
build-all:
|
build-*:
|
||||||
desc: build all binaries
|
desc: build a specific native binary
|
||||||
|
cmds:
|
||||||
|
- task: x-build-{{.BINARY}}
|
||||||
|
- cp bin/{{.BINARY}}_{{.GOOS}}_{{.GOARCH}} bin/{{.BINARY}}
|
||||||
|
vars:
|
||||||
|
BINARY: '{{index .MATCH 0}}'
|
||||||
|
sources:
|
||||||
|
- '**/*.go'
|
||||||
|
generates:
|
||||||
|
- bin/{{.BINARY}}
|
||||||
|
|
||||||
|
build:
|
||||||
|
desc: build all native binaries
|
||||||
cmds:
|
cmds:
|
||||||
- for: { var: BINARIES }
|
- for: { var: BINARIES }
|
||||||
task: native-build-{{.ITEM}}
|
task: build-{{.ITEM}}
|
||||||
vars:
|
vars:
|
||||||
BINARY: '{{.ITEM}}'
|
BINARY: '{{.ITEM}}'
|
||||||
vars:
|
vars:
|
||||||
BINARIES:
|
BINARIES:
|
||||||
sh: ls cmd/
|
sh: ls cmd/
|
||||||
|
|
||||||
install-all:
|
clean:
|
||||||
|
desc: clean up
|
||||||
|
cmd: rm -rf bin/*
|
||||||
|
|
||||||
|
install-*:
|
||||||
|
desc: install a binary
|
||||||
|
cmd: |
|
||||||
|
sudo install -m 0755 bin/{{.BINARY}} {{.DESTDIR}}/{{.BINARY}}
|
||||||
|
vars:
|
||||||
|
BINARY: '{{index .MATCH 0}}'
|
||||||
|
sources:
|
||||||
|
- bin/{{.BINARY}}
|
||||||
|
generates:
|
||||||
|
- '{{.DESTDIR}}/{{.BINARY}}'
|
||||||
|
|
||||||
|
install:
|
||||||
desc: install all binaries
|
desc: install all binaries
|
||||||
|
deps:
|
||||||
|
- build
|
||||||
cmds:
|
cmds:
|
||||||
- for: { var: BINARIES }
|
- for: { var: BINARIES }
|
||||||
task: install
|
task: install-{{.ITEM}}
|
||||||
vars:
|
|
||||||
BINARY: '{{.ITEM}}'
|
|
||||||
vars:
|
vars:
|
||||||
BINARIES:
|
BINARIES:
|
||||||
sh: ls cmd/
|
sh: ls cmd/
|
||||||
|
|
||||||
matrix-build-all:
|
matrix-build:
|
||||||
desc: build all binaries
|
desc: build all binaries for multiple os & architectures
|
||||||
cmds:
|
cmds:
|
||||||
- for: { var: BINARIES }
|
- for: { var: BINARIES }
|
||||||
task: matrix-build-{{.ITEM}}
|
task: matrix-build-{{.ITEM}}
|
||||||
@ -54,10 +94,28 @@ tasks:
|
|||||||
BINARIES:
|
BINARIES:
|
||||||
sh: ls cmd/
|
sh: ls cmd/
|
||||||
|
|
||||||
build-*:
|
matrix-build-*:
|
||||||
desc: build a binary
|
desc: build a specific binary for multiple os & architectures
|
||||||
|
cmds:
|
||||||
|
- for:
|
||||||
|
matrix:
|
||||||
|
GOOS: [linux, darwin]
|
||||||
|
GOARCH: [amd64, arm64]
|
||||||
|
task: x-build-{{.BINARY}}
|
||||||
|
vars:
|
||||||
|
GOOS: '{{.ITEM.GOOS}}'
|
||||||
|
GOARCH: '{{.ITEM.GOARCH}}'
|
||||||
|
- task: x-build-{{.BINARY}}
|
||||||
|
vars:
|
||||||
|
GOOS: windows
|
||||||
|
GOARCH: amd64
|
||||||
|
vars:
|
||||||
|
BINARY: '{{index .MATCH 0}}'
|
||||||
|
|
||||||
|
x-build-*:
|
||||||
|
desc: build a binary for the OS / Arch specified by $GOOS and $GOARCH
|
||||||
cmd: |
|
cmd: |
|
||||||
GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -o bin/{{.BINARY}}_{{.GOOS}}_{{.GOARCH}} ./cmd/{{.BINARY}}
|
GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -v -o bin/{{.BINARY}}_{{.GOOS}}_{{.GOARCH}} ./cmd/{{.BINARY}}
|
||||||
vars:
|
vars:
|
||||||
BINARY: '{{index .MATCH 0}}'
|
BINARY: '{{index .MATCH 0}}'
|
||||||
sources:
|
sources:
|
||||||
@ -67,49 +125,9 @@ tasks:
|
|||||||
deps:
|
deps:
|
||||||
- setup
|
- setup
|
||||||
|
|
||||||
native-build-*:
|
update-deps:
|
||||||
desc: build a native binary
|
desc: update go dependencies
|
||||||
cmd: |
|
|
||||||
go build -o bin/{{.BINARY}} ./cmd/{{.BINARY}}
|
|
||||||
vars:
|
|
||||||
BINARY: '{{index .MATCH 0}}'
|
|
||||||
sources:
|
|
||||||
- '**/*.go'
|
|
||||||
generates:
|
|
||||||
- bin/{{.BINARY}}
|
|
||||||
deps:
|
|
||||||
- setup
|
|
||||||
|
|
||||||
matrix-build-*:
|
|
||||||
desc: cross compile a binary
|
|
||||||
cmds:
|
|
||||||
- for:
|
|
||||||
matrix:
|
|
||||||
GOOS: [linux, darwin]
|
|
||||||
GOARCH: [amd64, arm64]
|
|
||||||
task: build-{{.BINARY}}
|
|
||||||
vars:
|
|
||||||
GOOS: '{{.ITEM.GOOS}}'
|
|
||||||
GOARCH: '{{.ITEM.GOARCH}}'
|
|
||||||
- task: build-{{.BINARY}}
|
|
||||||
vars:
|
|
||||||
GOOS: windows
|
|
||||||
GOARCH: amd64
|
|
||||||
vars:
|
|
||||||
BINARY: '{{index .MATCH 0}}'
|
|
||||||
|
|
||||||
update:
|
|
||||||
desc: update dependencies
|
|
||||||
cmds:
|
cmds:
|
||||||
- go get -u ./...
|
- go get -u ./...
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
|
|
||||||
install:
|
|
||||||
desc: install a binary
|
|
||||||
cmd: |
|
|
||||||
sudo install -m 0755 bin/{{.BINARY}} $DESTDIR/{{.BINARY}}
|
|
||||||
env:
|
|
||||||
DESTDIR: /usr/local/sbin
|
|
||||||
requires:
|
|
||||||
vars: [BINARY]
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user