-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTaskfile.yml
More file actions
190 lines (174 loc) · 6.3 KB
/
Taskfile.yml
File metadata and controls
190 lines (174 loc) · 6.3 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
186
187
188
189
190
---
version: "3"
includes:
test: .taskfiles/test.yml
deps: .taskfiles/deps.yml
lint: .taskfiles/lint.yml
hooks: .taskfiles/hooks.yml
opentelemetry:
taskfile: ci/tests/tracing/Taskfile.yml
dir: ci/tests/tracing/
opentelemetry-metrics:
taskfile: ci/tests/metrics/Taskfile.yml
dir: ci/tests/metrics/
services:
taskfile: docker/services/Taskfile.yml
dir: docker/services/
coprocess:
taskfile: coprocess/Taskfile.yml
dir: coprocess/
config:
taskfile: config/Taskfile.yml
dir: config/
apidef-oas:
taskfile: apidef/oas/Taskfile.yml
dir: apidef/oas/
vars:
path: ./...
# BASE_BRANCH: Determines the base branch for diff-based operations (linting, codegen)
# This variable is inherited by all included taskfiles.
#
# Detection logic:
# 1. If BASE_BRANCH env var is set, use it
# 2. If current branch follows release bot naming convention (merge/release-X.X/*),
# extract and use the release branch (e.g., merge/release-5.8/foo -> release-5.8)
# 3. Otherwise, default to master
#
# This ensures git hooks and linting compare against the correct baseline branch.
BASE_BRANCH:
sh: |
if [ -n "${BASE_BRANCH}" ]; then
echo "${BASE_BRANCH}"
else
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
case "$current_branch" in
merge/release-*/*)
echo "$current_branch" | sed -n 's|^merge/\(release-[^/]*\)/.*|\1|p'
;;
*)
echo "master"
;;
esac
fi
tasks:
build:
desc: "Build tyk gateway"
sources:
- '**/*.go'
- 'go.mod'
- 'go.sum'
generates:
- '.task-build-cache'
cmds:
- go build .
- cd gateway && go test -c . && cd ..
- touch .task-build-cache
docker:
desc: "build Tyk gateway internal/tyk-gateway"
cmds:
- docker build --build-arg GO_VERSION="$(go mod edit -json | jq .Go -r)" --platform "linux/amd64" --rm -t internal/tyk-gateway .
sources:
- go.mod
- go.sum
- "./**/*.go"
test:plugin-compiler:
desc: "Plugin compiler local build/test"
cmds:
- docker build --build-arg GO_VERSION=1.22 --build-arg BASE_IMAGE=tykio/golang-cross:1.22-bullseye --build-arg GITHUB_TAG=v5.1.0-alpha18 --build-arg GITHUB_SHA=$(git rev-parse HEAD) --platform=linux/amd64 --rm -t internal/plugin-compiler -f ci/images/plugin-compiler/Dockerfile .
- docker run -it -e GOARCH=arm64 -e GOOS=linux --rm -v $(readlink -f .)/ci/images/plugin-compiler/data/basic-plugin:/plugin-source internal/plugin-compiler basic-plugin.so
- docker run -it --rm -v $PWD:/go/src/github.com/TykTechnologies/tyk -w /go/src/github.com/TykTechnologies/tyk tykio/golang-cross:1.22-bullseye go build -trimpath -tags=goplugin .
- ./tyk plugin load -f ./ci/images/plugin-compiler/data/basic-plugin/basic-plugin*.so -s MyPluginPre
- docker rmi internal/plugin-compiler
test:goreleaser:
desc: "Test goreleaser locally"
vars:
pluginTemp: /tmp/plugin-compiler.extra_paths
cmds:
- go list ./... | perl -p -e 's/.+tyk\///g' | grep -v github | perl -p -e 's/\/.+//g' | sort | uniq > {{.pluginTemp}}
- echo -e "go.mod\ngo.sum\nmain.go\nci/images/plugin-compiler" >> {{.pluginTemp}}
- |
set -x
replacement=$(cat {{.pluginTemp}} | paste -sd , - | sed -e 's/,/","/g')
yq -i ".dockers[4].extra_files |= [\"$replacement\"]" ci/goreleaser/goreleaser-5.0.yml
yq -i ".dockers[0].extra_files |= [\"$replacement\"]" ci/goreleaser/goreleaser-el7.yml
yq -i ".dockers[4].extra_files |= [\"$replacement\"]" ci/goreleaser/goreleaser.yml
- echo goreleaser release --clean --snapshot -f ci/goreleaser/goreleaser.yml
codegen:
deps: [deps]
desc: "Run code generation steps"
cmds:
- go generate ./...
codegen:smart:
deps: [deps:mockgen]
desc: "Run code generation only if files with go:generate changed vs base branch"
sources:
- '**/*.go'
generates:
- .task-codegen-cache
cmds:
- |
# Only check files that changed vs base branch, avoiding grep on unchanged files
changed=$(git diff --name-only origin/{{.BASE_BRANCH}}...HEAD -- '*.go' 2>/dev/null || true)
if [ -z "$changed" ]; then
echo "✓ No Go files changed vs origin/{{.BASE_BRANCH}} - skipping codegen"
touch .task-codegen-cache
exit 0
fi
# Only grep in changed files for go:generate directive
files_with_generate=$(echo "$changed" | xargs grep -l "//go:generate" 2>/dev/null || true)
if [ -z "$files_with_generate" ]; then
echo "✓ No files with go:generate changed vs origin/{{.BASE_BRANCH}} - skipping codegen"
touch .task-codegen-cache
exit 0
fi
echo "Files with go:generate changed: $(echo $files_with_generate | tr '\n' ' ')"
go generate ./...
touch .task-codegen-cache
# Used in CI
lint:
desc: "Tidy the codebase"
cmds:
- task: codegen:smart
- task: lint:run
- task: lint:extras
tidy:
desc: "Tidy the codebase without auto-fixing"
cmds:
- task: codegen:smart
- task: lint:basic
- task: lint:extras
lint:extras:
desc: "Run more specific linters"
deps:
- task: coprocess:lint
- task: apidef-oas:lint
# Used in CI by hooks, lint.
fmt:
desc: "Reformat import groups"
cmds:
- task: lint:fmt
# This reformats imports using golangci-lint fmt with gci formatter
#
# To limit reformatting scope to packages or files, set `path`:
#
# - `task fmt:imports path="./ctx ./rpc"`
#
# Uses gci formatter configured in .golangci.yml with Tyk import ordering
fmt:imports:
desc: "Format imports using golangci-lint fmt"
cmds:
- golangci-lint fmt {{.path | default "./..."}}
setup:
desc: "Setup the project including dependencies and git hooks using lefthooks"
cmds:
- task: deps:default
- lefthook install
clean:
desc: "Clean test files"
cmds:
- find -name '*.so' -delete -print
- find -name '*.test' -delete -print
generate-bento-config-validator-schema:
desc: "Generate Bento Config Validator Schema"
cmds:
- go run apidef/streams/bento/schema/generate_bento_config_schema.go -o apidef/streams/bento/schema/bento-config-schema.json