Taskfile: update
This commit is contained in:
parent
a49908b96c
commit
7ea74ef927
134
Taskfile.yml
134
Taskfile.yml
@ -1,17 +1,30 @@
|
||||
version: '3'
|
||||
|
||||
env:
|
||||
vars:
|
||||
GOOS:
|
||||
sh: go env GOOS
|
||||
GOARCH:
|
||||
sh: go env GOARCH
|
||||
DESTDIR: /usr/local/sbin
|
||||
|
||||
env:
|
||||
DESTDIR: /usr/local/bin
|
||||
|
||||
tasks:
|
||||
|
||||
default:
|
||||
cmds:
|
||||
- task: build-all
|
||||
desc: display usage info
|
||||
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:
|
||||
desc: setup directories
|
||||
@ -21,30 +34,57 @@ tasks:
|
||||
status:
|
||||
- test -d bin
|
||||
|
||||
build-all:
|
||||
desc: build all binaries
|
||||
build-*:
|
||||
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:
|
||||
- for: { var: BINARIES }
|
||||
task: native-build-{{.ITEM}}
|
||||
task: build-{{.ITEM}}
|
||||
vars:
|
||||
BINARY: '{{.ITEM}}'
|
||||
vars:
|
||||
BINARIES:
|
||||
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
|
||||
deps:
|
||||
- build
|
||||
cmds:
|
||||
- for: { var: BINARIES }
|
||||
task: install
|
||||
vars:
|
||||
BINARY: '{{.ITEM}}'
|
||||
task: install-{{.ITEM}}
|
||||
vars:
|
||||
BINARIES:
|
||||
sh: ls cmd/
|
||||
|
||||
matrix-build-all:
|
||||
desc: build all binaries
|
||||
matrix-build:
|
||||
desc: build all binaries for multiple os & architectures
|
||||
cmds:
|
||||
- for: { var: BINARIES }
|
||||
task: matrix-build-{{.ITEM}}
|
||||
@ -54,10 +94,28 @@ tasks:
|
||||
BINARIES:
|
||||
sh: ls cmd/
|
||||
|
||||
build-*:
|
||||
desc: build a binary
|
||||
matrix-build-*:
|
||||
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: |
|
||||
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:
|
||||
BINARY: '{{index .MATCH 0}}'
|
||||
sources:
|
||||
@ -67,49 +125,9 @@ tasks:
|
||||
deps:
|
||||
- setup
|
||||
|
||||
native-build-*:
|
||||
desc: build a native binary
|
||||
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
|
||||
update-deps:
|
||||
desc: update go dependencies
|
||||
cmds:
|
||||
- go get -u ./...
|
||||
- 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