In our daily work, we may want to do some tasks, such as build or compile. There is a very useful tool task which can help us to define our work in a yaml file, then it can help us to run those commands. For remote, you can refer Ansible, which is a very useful tool for Linux automation.
Here is an example for build mstrbak, in that repo, we define an internal task file as follow:
version: '3'
tasks:
clean:
internal: true
cmds:
- rm -rf {{.TOOL}} build.txt lib {{.TOOL}}.exe {{.TOOL}}.zip
build-linux:
internal: true
deps: [jar]
cmds:
- GOOS=linux GOARCH=amd64 go build -o {{.TOOL}} main.go
- zip -r {{.TOOL}}.zip lib {{.CONFIG}}.yaml {{.TOOL}}
- task: post-clean
build-windows:
internal: true
deps: [jar]
cmds:
- GOOS=linux GOARCH=amd64 go build -o {{.TOOL}}.exe main.go
- zip -r {{.TOOL}}.zip lib {{.CONFIG}}.yaml {{.TOOL}}.exe
- task: post-clean
test:
cmds:
- go test -v -gcflags=all=-l -count=1 */*.go
jar:
deps: [pom]
cmds:
- mvn clean dependency:copy-dependencies dependency:tree -DoutputFile=build.txt
- mv lib/DBMigrator*.jar lib/DBMigrator.jar
pom:
deps: [clean]
cmds:
- cp ../dbmigrator/pom.xml .
status:
- test -f pom.xml
post-clean:
deps: [clean-pom]
cmds:
- rm -rf {{.TOOL}} build.txt lib {{.TOOL}}.exe
clean-pom:
interal: true
cmds:
- |
if test {{.CLEAN_POM}} = true; then
rm -rf pom.xml
fi
Then we define a task file refer the internal yaml file, which can work very well.
version: '3'
includes:
dbmigrator:
taskfile: ./Taskfile-Internal.yaml
dir: ./dbmigrator
vars:
TOOL: DBMigrator
CONFIG: config
CLEAN_POM: false
backup:
taskfile: ./Taskfile-Internal.yaml
dir: ./backup
vars:
TOOL: mstrbak
CONFIG: config
CLEAN_POM: true
restore:
taskfile: ./Taskfile-Internal.yaml
dir: ./restore
vars:
TOOL: restore
CONFIG: restore
CLEAN_POM: true
tasks:
build-linux:
deps: [dbmigrator:build-linux, backup:build-linux, restore:build-linux]
build-windows:
deps: [dbmigrator:build-windows, backup:build-windows, restore:build-windows]
test:
deps: [dbmigrator:test, backup:test, restore:test]
cmds:
- |
for t in "service" "logger" "utilities"
do
go test -v -gcflags=all=-l -count=1 $t/*.go
done
clean:
deps: [dbmigrator:clean, backup:clean, restore:clean]
You can also use make to do build and compile work. Current I always use shell or python to do build work, but task or make may more useful, in the future, I can try to convert them with task or make.