generated from veerendra2/go-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
122 lines (109 loc) · 3.1 KB
/
Taskfile.yml
File metadata and controls
122 lines (109 loc) · 3.1 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
version: "3"
silent: true
vars:
MAIN_FILE: main.go
APP_NAME: speedtest_exporter
GOPATH_BIN:
sh: echo "$(go env GOPATH)/bin"
BRANCH:
sh: git rev-parse --abbrev-ref HEAD
BUILD_TIME:
sh: date '+%Y-%m-%d@%H:%M:%S'
BUILD_USER:
sh: id -un
REVISION:
sh: git rev-parse --short HEAD
VERSION:
sh: git describe --tags --always
env:
GOBIN: "{{.GOPATH_BIN }}"
CGO_ENABLED: 0
tasks:
run:
desc: "Runs the main application"
deps:
- vet
cmds:
- go run {{.MAIN_FILE}}
env:
LOG_FORMAT: console
LOG_ADD_SOURCE: false
LOG_LEVEL: debug
lint:
desc: "Run static analysis and code linting using golangci-lint"
deps:
- install
cmds:
- golangci-lint run --timeout 3m
fmt:
desc: "Formats all Go source files"
cmds:
- go fmt ./...
vet:
desc: "Examines Go source code and reports suspicious constructs"
cmds:
- go vet ./...
test:
desc: "Runs all tests in the project"
aliases:
- tests
deps:
- vet
cmds:
- go test ./...
build:
desc: "Build the application binary for the current platform"
deps:
- vet
cmd: |
go build -ldflags "\
-X github.com/veerendra2/gopackages/version.Version={{.VERSION}} \
-X github.com/veerendra2/gopackages/version.Revision={{.REVISION}} \
-X github.com/veerendra2/gopackages/version.Branch={{.BRANCH}} \
-X github.com/veerendra2/gopackages/version.BuildUser={{.BUILD_USER}} \
-X github.com/veerendra2/gopackages/version.BuildDate={{.BUILD_TIME}}" \
-o dist/{{.APP_NAME}} {{.MAIN_FILE}}
build-platforms:
desc: "Build the application binaries for multiple platforms and architectures"
deps:
- vet
cmds:
- for:
matrix:
OS: ["linux", "darwin"]
ARCH: ["amd64", "arm64"]
cmd: |
GOOS={{.ITEM.OS}} GOARCH={{.ITEM.ARCH}} go build -ldflags "\
-X github.com/veerendra2/gopackages/version.Version={{.VERSION}} \
-X github.com/veerendra2/gopackages/version.Revision={{.REVISION}} \
-X github.com/veerendra2/gopackages/version.Branch={{.BRANCH}} \
-X github.com/veerendra2/gopackages/version.BuildUser={{.BUILD_USER}} \
-X github.com/veerendra2/gopackages/version.BuildDate={{.BUILD_TIME}}" \
-o dist/{{.APP_NAME}}-{{.ITEM.OS}}-{{.ITEM.ARCH}} {{.MAIN_FILE}}
build-docker:
desc: "Build Docker image"
cmds:
- docker build -t {{.APP_NAME}} .
security:
desc: "Run security vulnerability scan"
deps:
- install
cmds:
- govulncheck ./...
install:
desc: "Install required tools and dependencies"
cmds:
- go install golang.org/x/vuln/cmd/govulncheck@latest
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
status:
- test -f {{.GOPATH_BIN}}/govulncheck
- test -f {{.GOPATH_BIN}}/golangci-lint
all:
desc: "Run comprehensive checks: format, lint, security and test"
cmds:
- task fmt
- task lint
- task vet
- task security
- task test