-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
93 lines (78 loc) · 2.83 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
# florist/Taskfile (see https://taskfile.dev)
version: '3'
tasks:
build:example:
desc: Build the example provisioner.
cmds:
- go build -o bin/example ./example
build:dev:
desc: Build the provisioner for the project
cmds:
- go build -o bin/dev ./florist/roles/dev
- GOOS=linux go build -o bin/linux/dev ./florist/roles/dev
build:
desc: Test successful build.
cmds:
- go build ./...
lint:
cmds:
- golangci-lint run ./...
test:all:
desc: Run all the unit tests; makes sense only if invoking from the VM.
cmds:
- gotestsum -- -count=1 -coverprofile=./bin/cover.out ./...
test:all:vm:clean:
desc: Run all the tests on a VM from a clean snapshot
cmds:
- task: _vm:restore
- task: test:all:vm:dirty
test:all:vm:dirty:
desc: Run all the tests on a VM on the current snapshot (thus dirty) (faster but inaccurate and flaky)
cmds:
- task: vm:set_date
- ssh -F ssh.config.vagrant florist-dev "cd florist && sudo task test:all"
vm:set_date:
desc: Set the current date in the VM (expects the VM to be running).
cmds:
- ssh -F ssh.config.vagrant florist-dev sudo sntp --step 0.pool.ntp.org
browser:
desc: "Show code coverage in browser (usage: task test:<subtarget> browser)"
cmds:
- go tool cover -html=./bin/cover.out
clean:
desc: Remove the build artifacts
cmds:
- rm -rf bin
vm:init:
desc: Create a VM from scratch, provision and take a snapshot. Use `vm:restore` to restore the snapshot to pristine state.
cmds:
- task: build:dev
- vagrant destroy --force
- vagrant up
# Generate a SSH configuration file
- vagrant ssh-config > ssh.config.vagrant
# For some reason, vagrant adds "LogLevel FATAL" to the generated file.
# We want the default logging level instead.
- sed -i "" 's/LogLevel FATAL//' ssh.config.vagrant
# Mark this VM as a target for destructive tests.
- ssh -F ssh.config.vagrant florist-dev sudo mkdir -p /opt/florist/disposable
# Provision the VM with the "dev" bouquet.
- ssh -F ssh.config.vagrant florist-dev sudo "./florist/bin/linux/dev install"
# Install other deps. I am unsure this is the best approach...
- ssh -F ssh.config.vagrant florist-dev "GOBIN=/usr/local/bin sudo --preserve-env=GOBIN task -d florist install-deps"
# Take snapshot, name `pristine`
- vagrant snapshot save pristine
- vagrant halt
vm:restore:
desc: Restore the VM snapshot to pristine state and set the current date
cmds:
- task: _vm:restore
- task: vm:set_date
_vm:restore:
cmds:
- vagrant snapshot restore pristine
install:deps:
desc: Install tool dependencies.
cmds:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- go install gotest.tools/gotestsum@latest