Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
153 lines (147 loc) · 5.38 KB
/
Copy pathTaskfile.yml
File metadata and controls
153 lines (147 loc) · 5.38 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
version: "3"
vars:
BIN_NAME: gdg
VERSION: { sh: grep "const Version " pkg/version/version.go | sed -E 's/.*"(.+)"$$/\1/' }
GIT_COMMIT: { sh: git rev-parse HEAD }
GIT_DIRTY: { sh: test -n "`git status --porcelain`" && echo "+CHANGES" || true }
BUILD_DATE: { sh: date '+%Y-%m-%d-%H:%M:%S' }
IMAGE_NAME: "esnet/gdg"
LD_FLAGS: "-s -w -X github.com/esnet/gdg/pkg/version.GitCommit={{ .GIT_COMMIT}}{{ .GIT_DIRTY}} -X github.com/esnet/gdg/pkg/version.BuildDate={{ .BUILD_DATE }} "
TOOLS_ARG: "-modfile tools/go.mod"
TOOL_MODULES: >-
github.com/client9/misspell/cmd/misspell
github.com/evilmartians/lefthook/v2
github.com/golangci/golangci-lint/v2/cmd/golangci-lint
github.com/goreleaser/goreleaser/v2
github.com/securego/gosec/v2/cmd/gosec
github.com/vektra/mockery/v3
golang.org/x/vuln/cmd/govulncheck
gotest.tools/gotestsum
mvdan.cc/gofumpt
dotenv: [ '.env' ]
tasks:
default:
cmds:
- task: build_all
install_tools:
desc: "Install required Dev tools by GDG"
cmds:
- go tool {{ .TOOLS_ARG}} github.com/evilmartians/lefthook/v2 install
update_tools:
desc: "Bump every dev tool pinned in tools/go.mod to its latest version"
dir: tools
cmds:
# NOTE: intentionally not using {{ .TOOLS_ARG }}/-modfile here. -modfile only swaps
# which go.mod is read; it does NOT move the module root used for package discovery.
# Run from repo root, `go mod tidy -modfile tools/go.mod` treats the whole repo tree
# (cli/, internal/, pkg/, ...) as if it belonged to the "tools" module and fails trying
# to resolve their imports. Running with dir: tools makes tools/ the actual cwd, so
# plain `go get`/`go mod tidy` operate correctly scoped to that module.
- |
for mod in {{ .TOOL_MODULES }}; do
echo "==> updating $mod"
go get -tool "$mod@latest"
done
- go mod tidy
- echo "Done. Review the diff in tools/go.mod and tools/go.sum, then run 'task install_tools' to refresh lefthook."
security:
desc: "Run security scan"
cmds:
- go tool {{ .TOOLS_ARG}} gosec ./...
format:
desc: reformat the code to match stricter conventions
cmds:
- go tool {{ .TOOLS_ARG}} gofumpt -l -w .
lint:
desc: "Lint project, skipping test files."
cmds:
- go tool {{ .TOOLS_ARG}} github.com/golangci/golangci-lint/v2/cmd/golangci-lint run --timeout=30m ./...
# - go tool {{ .TOOLS_ARG}} golangci-lint run --timeout=30m ./...
spellcheck:
desc: "Check Spelling across code"
cmds:
- go tool {{ .TOOLS_ARG}} misspell . | grep -v "website"
lint_tests:
desc: "Lint project, including test files."
cmds:
- go tool {{ .TOOLS_ARG}} golangci-lint run ./...
authors:
desc: "Building GDG"
cmds:
- echo "Authors\n=======\n" > AUTHORS.md
- "git log --raw | grep \"^Author: \" | sort | uniq | cut -d ' ' -f2 | sed 's/^/- /' >> AUTHORS.md"
silent: false
mocks:
desc: "Re-generate Mocks"
cmds:
- rm -fr internal/ports/mocks/ internal/ports/outbound/mocks/
- go tool {{ .TOOLS_ARG}} mockery
linux:
desc: "Build linux binary"
cmds:
- env GOOS='linux' GOARCH='amd64' go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}_linux cmd/gdg/main.go
build_all:
desc: "Buiding All binaries"
cmds:
- task: build
- task: build_generate
build:
desc: "Buiding {{ .BIN_NAME }} {{ .VERSION }}"
cmds:
- echo "GOPATH=${GOPATH}"
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }} cmd/gdg/main.go
build_generate:
desc: "Buiding {{ .BIN_NAME }}-generate {{ .VERSION }}"
cmds:
- echo "GOPATH=${GOPATH}"
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}-generate cmd/gdg-generate/main.go
install:
desc: "installing {{ .BIN_NAME }} {{ .VERSION }}"
cmds:
- echo "GOPATH=${GOPATH}"
- go install -ldflags "{{ .LD_FLAGS}}" cmd/gdg/main.go
silent: false
push:
desc: "Pushing docker image to registry: latest {{ .VERSION }} {{ .GIT_COMMIT }}"
deps: [ tag ]
cmds:
- docker push $(IMAGE_NAME):{{ .GIT_COMMIT }}
- docker push $(IMAGE_NAME):{{ .VERSION }}
- docker push $(IMAGE_NAME):latest
clean:
desc: "clean up data"
cmds:
- "test ! -e bin/{{ .BIN_NAME }} || rm bin/{{ .BIN_NAME }}"
- "rm -fr dist/"
release-snapshot:
deps: [ clean ]
desc: "Release Snapshot"
cmds:
- go tool {{ .TOOLS_ARG}} goreleaser build --snapshot
release:
deps: [ clean ]
desc: "TEST Release of GDG, no validation, no publish"
cmds:
- go tool {{ .TOOLS_ARG}} goreleaser release --skip=publish,validate
pipeline_test:
desc: "Run test as close to the CICD pipiline as possible"
cmds:
- go tool {{ .TOOLS_ARG}} gotestsum --format testname -- -covermode=atomic -coverpkg=$(go list ./... | egrep -v "mocks" | tr '\n' ',' ) ./...
test:
desc: "test check"
cmds:
- go test -v -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./...
- go tool cover -html=coverage.out
env:
TEST_TOKEN_CONFIG: "0"
test_tokens:
desc: "test Token Based Only"
cmds:
- go test -v -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./...
- go tool cover -html=coverage.out
env:
TEST_TOKEN_CONFIG: "1"
vuln_check:
desc: "Vulnerability check"
cmds:
- go tool {{ .TOOLS_ARG}} govulncheck ./...