Repository navigation
Expand file tree
/
Copy pathgolang.yml
More file actions
73 lines (66 loc) · 2.91 KB
/
Copy pathgolang.yml
File metadata and controls
73 lines (66 loc) · 2.91 KB
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
version: '3'
# Defaults are task-level vars for the reason given in terraform.yml.
tasks:
fmt:
desc: Rewrite Go files with gofmt -s
vars: &vars
GO_BIN: '{{.GO_BIN | default "go"}}'
GO_DIR: '{{.GO_DIR | default "."}}'
GO_BUILD_PKG: '{{.GO_BUILD_PKG | default "."}}'
GO_BUILD_OUTPUT: '{{.GO_BUILD_OUTPUT | default (printf "%s/bin/" .ROOT_DIR)}}'
GO_BUILD_OS: '{{.GO_BUILD_OS | default ""}}'
GO_BUILD_ARCH: '{{.GO_BUILD_ARCH | default ""}}'
GO_BUILD_CGO_ENABLED: '{{.GO_BUILD_CGO_ENABLED | default ""}}'
GO_BUILD_FLAGS: '{{.GO_BUILD_FLAGS | default ""}}'
GO_TEST_PKGS: '{{.GO_TEST_PKGS | default "./..."}}'
GO_TEST_FLAGS: '{{.GO_TEST_FLAGS | default ""}}'
GO_COVER_PROFILE: '{{if hasKey . "GO_COVER_PROFILE"}}{{.GO_COVER_PROFILE}}{{else}}cover.out{{end}}'
GO_COVER_HTML: '{{.GO_COVER_HTML | default "cover.html"}}'
# gofmt from GO_BIN's GOROOT, so formatting matches the selected toolchain rather than whichever gofmt is on PATH.
gofmt: '"$({{.GO_BIN}} env GOROOT)/bin/gofmt"'
# cd, not the dir key: dir creates a missing directory, so go:fmt succeeds on a mistyped GO_DIR.
cmds:
- cd {{q .GO_DIR}} && {{.gofmt}} -s -w .
tidy:
desc: Add missing and remove unused module requirements
vars: *vars
cmds:
- cd {{q .GO_DIR}} && {{.GO_BIN}} mod tidy
lint:
desc: Check gofmt -s formatting and run go vet
vars: *vars
cmds:
- cmd: |
cd {{q .GO_DIR}} && files=$({{.gofmt}} -s -l .) && if [ -n "$files" ]; then
echo "These files need formatting (run the fmt task):"; echo "$files"; exit 1
fi
silent: true
- cd {{q .GO_DIR}} && {{.GO_BIN}} vet ./...
test:
desc: Run tests, writing GO_COVER_PROFILE when set
run: when_changed
vars: *vars
cmds:
- cd {{q .GO_DIR}} && {{.GO_BIN}} test {{.GO_TEST_FLAGS}} {{if .GO_COVER_PROFILE}}-coverprofile={{q .GO_COVER_PROFILE}}{{end}} {{.GO_TEST_PKGS}}
cover-html:
desc: Run tests and render the coverage profile as HTML
vars: *vars
preconditions:
- sh: '{{if .GO_COVER_PROFILE}}true{{else}}false{{end}}'
msg: GO_COVER_PROFILE must be set for the cover-html task
cmds:
- task: test
vars:
GO_BIN: '{{.GO_BIN}}'
GO_DIR: '{{.GO_DIR}}'
GO_TEST_PKGS: '{{.GO_TEST_PKGS}}'
GO_TEST_FLAGS: '{{.GO_TEST_FLAGS}}'
GO_COVER_PROFILE: '{{.GO_COVER_PROFILE}}'
- cd {{q .GO_DIR}} && {{.GO_BIN}} tool cover -html={{q .GO_COVER_PROFILE}} -o {{q .GO_COVER_HTML}}
build:
desc: Build GO_BUILD_PKG into GO_BUILD_OUTPUT
vars: *vars
cmds:
- >-
cd {{q .GO_DIR}} &&
{{if .GO_BUILD_OS}}GOOS={{.GO_BUILD_OS}} {{end}}{{if .GO_BUILD_ARCH}}GOARCH={{.GO_BUILD_ARCH}} {{end}}{{if .GO_BUILD_CGO_ENABLED}}CGO_ENABLED={{.GO_BUILD_CGO_ENABLED}} {{end}}{{.GO_BIN}} build {{.GO_BUILD_FLAGS}} -o {{q .GO_BUILD_OUTPUT}} {{.GO_BUILD_PKG}}