Skip to content

Commit c934a0c

Browse files
committed
prepare envtest dependency
1 parent e983ac5 commit c934a0c

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ includes:
108108

109109
Adding new specialized tasks in addition to the imported generic ones is straightforward: simply add the task definitions in the importing Taskfile.
110110

111-
It is also possible to exclude or overwrite generic tasks. The following example uses an `external-apis` task that should be executed as part of the generic `generate:code` task.
111+
It is also possible to exclude or overwrite generic tasks. The following example uses an `external-apis` task that should be executed as part of the generic `generate:code` task, and it adds a envtest dependency to the `validate:test` task.
112112

113113
Overwriting basically works by excluding and re-defining the generic task that should be overwritten. If the generic task's logic should be kept as part of the overwritten definition, the generic file needs to be imported a second time with `internal: true`, so that the original task can be called.
114114

@@ -128,14 +128,30 @@ includes:
128128
tasks:
129129
generate:code: # overwrites shared code task to add external API fetching
130130
desc: " Generate code (mainly DeepCopy functions) and fetches external APIs."
131+
aliases:
132+
- gen:code
133+
- g:code
131134
run: once
132135
cmds:
133136
- task: external-apis
134137
- task: c:generate:code
135138
136139
external-apis:
137140
desc: " Fetch external APIs."
141+
run: once
138142
<...>
143+
internal: true
144+
145+
validate:test: # overwrites the test task to add a dependency towards envtest
146+
desc: " Run all tests."
147+
aliases:
148+
- val:test
149+
- v:test
150+
run: once
151+
deps:
152+
- tools:envtest
153+
cmds:
154+
- task: c:validate:test
139155
```
140156

141157
### Makefile

Taskfile_library.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ vars:
5858
YAML2JSON_VERSION: '{{ .YAML2JSON_VERSION | default "v1.3.5" }}'
5959
OCM: '{{ .OCM | default (print .LOCALBIN "/ocm") }}'
6060
OCM_VERSION: '{{ .OCM_VERSION | default "v0.21.0" }}'
61+
ENVTEST: '{{ .ENVTEST | default (print .LOCALTMP "/setup-envtest") }}'
62+
ENVTEST_VERSION: '{{ .ENVTEST_VERSION | default "release-0.16" }}'
6163

6264
DOCKER_BUILDER_NAME: # move to build taskfile later
6365
sh: 'echo -n ${DOCKER_BUILDER_NAME:-"openmcp-multiarch-builder"}'
@@ -98,13 +100,13 @@ tasks:
98100
desc: " Combines all code generation tasks, including formatting."
99101
run: once
100102
deps:
101-
- gen:generate
103+
- generate:generate
102104

103105
test:
104106
desc: " Run all tests."
105107
run: once
106108
deps:
107-
- val:test
109+
- validate:test
108110

109111
validate:
110112
desc: " Combines all validation tasks except for tests."
@@ -113,7 +115,7 @@ tasks:
113115
- verify
114116
- check
115117
deps:
116-
- val:validate
118+
- validate:validate
117119

118120
version:
119121
desc: " Print the version of the project. Use VERSION_OVERRIDE to make this task print a specific version."

tasks_tools.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,20 @@ tasks:
157157
- 'curl -sSfL https://ocm.software/install.sh | OCM_VERSION="{{.OCM_VERSION | trimPrefix "v"}}" bash -s "{{.tmpdir}}"'
158158
- 'mv "{{.tmpdir}}/ocm" "{{.OCM}}"'
159159
internal: true
160+
161+
envtest:
162+
desc: " Ensure that envtest is installed."
163+
run: once
164+
requires:
165+
vars:
166+
- ENVTEST
167+
- ENVTEST_VERSION
168+
deps:
169+
- localbin
170+
status:
171+
- 'test -x "{{.ENVTEST}}"'
172+
- test -f {{.LOCALBIN}}/envtest_version
173+
- 'cat {{.LOCALBIN}}/envtest_version | grep -q "{{.ENVTEST_VERSION}}"'
174+
cmds:
175+
- 'GOBIN="{{.LOCALBIN}}" go install sigs.k8s.io/controller-runtime/tools/setup-envtest@{{.ENVTEST_VERSION}}'
176+
internal: true

0 commit comments

Comments
 (0)