-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
185 lines (162 loc) · 4.54 KB
/
Copy pathTaskfile.yaml
File metadata and controls
185 lines (162 loc) · 4.54 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
version: '3'
vars:
LOCALBIN:
sh: echo "$(pwd)/bin"
GOBIN:
sh: |
gobin=$(go env GOBIN)
[ -n "$gobin" ] && echo "$gobin" || echo "$(go env GOPATH)/bin"
GOLANGCI_LINT: '{{.LOCALBIN}}/golangci-lint'
YAMLFMT: '{{.LOCALBIN}}/yamlfmt'
GO_LICENSES: '{{.LOCALBIN}}/go-licenses'
GOLANGCI_LINT_VERSION: v2.12.2
YAMLFMT_VERSION: v0.21.0
GO_LICENSES_VERSION: v1.6.0
tasks:
default:
silent: true
cmds:
- task --list
##
## Development
##
fmt:
desc: Format code
run: once
cmds:
- go fmt ./...
vet:
desc: Vet code
run: once
cmds:
- GOOS=linux go vet ./...
ci:
desc: Run the full CI pipeline (lint, build, test:unit, test:e2e)
cmds:
- task: lint
- task: build
- task: test:unit
- task: test:e2e
test:
desc: Run all tests
cmds:
- task: test:unit
- task: test:e2e
lint:
desc: Lint
deps: [golangci-lint, yamlfmt, yaml-ext]
cmds:
- '{{.GOLANGCI_LINT}} run'
- '{{.YAMLFMT}} -lint'
lint-fix:
desc: Lint and apply fixes
deps: [golangci-lint, yamlfmt]
cmds:
- '{{.GOLANGCI_LINT}} run --fix'
- '{{.YAMLFMT}}'
notice:
desc: Regenerate NOTICE file
deps: [go-licenses]
cmds:
- '{{.GO_LICENSES}} report ./... --ignore go.datum.net/galactic --template scripts/licenses/notice.tmpl > NOTICE'
##
## Build
##
build:
desc: Build binaries
deps: [fmt, vet]
vars:
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo "dev"
GIT_COMMIT:
sh: git rev-parse --short HEAD
GIT_TREE_STATE:
sh: git diff --quiet && echo "clean" || echo "dirty"
BUILD_DATE:
sh: date -u +%Y-%m-%dT%H:%M:%SZ
SPDX_LICENSE: AGPL-3.0-or-later
GIT_URL: https://github.com/datum-cloud/galactic
LDFLAGS: >-
-s -w
-X go.datum.net/galactic/internal/metadata.Version={{.VERSION}}
-X go.datum.net/galactic/internal/metadata.GitCommit={{.GIT_COMMIT}}
-X go.datum.net/galactic/internal/metadata.GitTreeState={{.GIT_TREE_STATE}}
-X go.datum.net/galactic/internal/metadata.BuildDate={{.BUILD_DATE}}
-X go.datum.net/galactic/internal/metadata.SPDXLicense={{.SPDX_LICENSE}}
-X go.datum.net/galactic/internal/metadata.GitURL={{.GIT_URL}}
cmds:
- go build -ldflags "{{.LDFLAGS}}" -o bin/galactic-cni ./cmd/galactic-cni
- go build -ldflags "{{.LDFLAGS}}" -o bin/galactic-router ./cmd/galactic-router
- GOBIN={{.LOCALBIN}} go install github.com/containernetworking/plugins/plugins/main/host-device@v1.9.1
##
## CI
##
test:unit:
desc: Unit tests with race detection and coverage
cmds:
- bash scripts/ci.sh unittest
test:e2e:
desc: E2E tests (Kind cluster, build+load image, lifecycle)
cmds:
- bash scripts/ci.sh e2etest
##
## Cleanup
##
clean:
desc: Remove build artifacts
cmds:
- rm -rf bin/
- rm -rf dist/
- rm -f cover.out
##
## Dependencies
##
golangci-lint:
desc: Download golangci-lint if needed
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.GOLANGCI_LINT}}'
PACKAGE: github.com/golangci/golangci-lint/v2/cmd/golangci-lint
VERSION: '{{.GOLANGCI_LINT_VERSION}}'
yamlfmt:
desc: Download yamlfmt if needed
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.YAMLFMT}}'
PACKAGE: github.com/google/yamlfmt/cmd/yamlfmt
VERSION: '{{.YAMLFMT_VERSION}}'
yaml-ext:
desc: Enforce .yaml extension (no .yml)
run: once
cmds:
- |
if find . -name "*.yml" -not -path "./.git/*" -not -path "./deploy/containerlab/clab-gvpc/*" | grep -q .; then
find . -name "*.yml" -not -path "./.git/*" -not -path "./deploy/containerlab/clab-gvpc/*"
echo "ERROR: .yml files found; rename to .yaml"
exit 1
fi
go-licenses:
internal: true
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.GO_LICENSES}}'
PACKAGE: github.com/google/go-licenses
VERSION: '{{.GO_LICENSES_VERSION}}'
install-tool:
internal: true
cmds:
- mkdir -p {{.LOCALBIN}}
- |
if [ ! -f "{{.TARGET}}-{{.VERSION}}" ]; then
echo "Downloading {{.PACKAGE}}@{{.VERSION}}"
rm -f "{{.TARGET}}" || true
GOBIN={{.LOCALBIN}} go install {{.PACKAGE}}@{{.VERSION}}
mv "{{.TARGET}}" "{{.TARGET}}-{{.VERSION}}"
fi
ln -sf "{{.TARGET}}-{{.VERSION}}" "{{.TARGET}}"