Skip to content

Commit ee901fe

Browse files
committed
v3.37.0
1 parent 7fa06ee commit ee901fe

File tree

12 files changed

+196
-111
lines changed

12 files changed

+196
-111
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## Unreleased
3+
## v3.37.0 - 2024-05-08
44

55
- Released the
66
[Any Variables experiment](https://taskfile.dev/blog/any-variables), but

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@go-task/cli",
3-
"version": "3.36.0",
3+
"version": "3.37.0",
44
"description": "A task runner / simpler Make alternative written in Go",
55
"scripts": {
66
"postinstall": "go-npm install",

website/docs/changelog.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ sidebar_position: 14
55

66
# Changelog
77

8+
## v3.37.0 - 2024-05-08
9+
10+
- Released the
11+
[Any Variables experiment](https://taskfile.dev/blog/any-variables), but
12+
[_without support for maps_](https://github.com/go-task/task/issues/1415#issuecomment-2044756925)
13+
(#1415, #1547 by @pd93).
14+
- Refactored how Task reads, parses and merges Taskfiles using a DAG (#1563,
15+
#1607 by @pd93).
16+
- Fix a bug which stopped tasks from using `stdin` as input (#1593, #1623 by
17+
@pd03).
18+
- Fix error when a file or directory in the project contained a special char
19+
like `&`, `(` or `)` (#1551, #1584 by @andreynering).
20+
- Added alias `q` for template function `shellQuote` (#1601, #1603 by @vergenzt)
21+
- Added support for `~` on ZSH completions (#1613 by @jwater7).
22+
- Added the ability to pass variables by reference using Go template syntax when
23+
the
24+
[Map Variables experiment](https://taskfile.dev/experiments/map-variables/) is
25+
enabled (#1612 by @pd93).
26+
- Added support for environment variables in the templating engine in `includes`
27+
(#1610 by @vmaerten).
28+
829
## v3.36.0 - 2024-04-08
930

1031
- Added support for

website/versioned_docs/version-latest/changelog.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ sidebar_position: 14
55

66
# Changelog
77

8+
## v3.37.0 - 2024-05-08
9+
10+
- Released the
11+
[Any Variables experiment](https://taskfile.dev/blog/any-variables), but
12+
[_without support for maps_](https://github.com/go-task/task/issues/1415#issuecomment-2044756925)
13+
(#1415, #1547 by @pd93).
14+
- Refactored how Task reads, parses and merges Taskfiles using a DAG (#1563,
15+
#1607 by @pd93).
16+
- Fix a bug which stopped tasks from using `stdin` as input (#1593, #1623 by
17+
@pd03).
18+
- Fix error when a file or directory in the project contained a special char
19+
like `&`, `(` or `)` (#1551, #1584 by @andreynering).
20+
- Added alias `q` for template function `shellQuote` (#1601, #1603 by @vergenzt)
21+
- Added support for `~` on ZSH completions (#1613 by @jwater7).
22+
- Added the ability to pass variables by reference using Go template syntax when
23+
the
24+
[Map Variables experiment](https://taskfile.dev/experiments/map-variables/) is
25+
enabled (#1612 by @pd93).
26+
- Added support for environment variables in the templating engine in `includes`
27+
(#1610 by @vmaerten).
28+
829
## v3.36.0 - 2024-04-08
930

1031
- Added support for

website/versioned_docs/version-latest/experiments/gentle_force.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ if you want to adopt the new behavior, you can continue to use the `--force`
4545
flag as you do now!
4646

4747
{/* prettier-ignore-start */}
48-
[enabling-experiments]: /experiments/#enabling-experiments
48+
[enabling-experiments]: ./experiments.mdx#enabling-experiments
4949
{/* prettier-ignore-end */}

website/versioned_docs/version-latest/experiments/any_variables.mdx renamed to website/versioned_docs/version-latest/experiments/map_variables.mdx

Lines changed: 78 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
slug: /experiments/any-variables/
2+
slug: /experiments/map-variables/
33
---
44

55
import Tabs from '@theme/Tabs';
66
import TabItem from '@theme/TabItem';
77

8-
# Any Variables (#1415)
8+
# Map Variables (#1585)
99

1010
:::caution
1111

@@ -15,19 +15,9 @@ environment. They are intended for testing and feedback only.
1515

1616
:::
1717

18-
Currently, Task only supports string variables. This experiment allows you to
19-
specify and use the following variable types:
20-
21-
- `string`
22-
- `bool`
23-
- `int`
24-
- `float`
25-
- `array`
26-
- `map`
27-
28-
This allows you to have a lot more flexibility in how you use variables in
29-
Task's templating engine. There are two active proposals for this experiment.
30-
Click on the tabs below to switch between them.
18+
Currently, Task supports all variable types except for maps. This experiment
19+
adds two different proposals for map variables. Click on the tabs below to
20+
switch between them.
3121

3222
<Tabs defaultValue="1" queryString="proposal"
3323
values={[
@@ -48,13 +38,11 @@ This experiment proposal breaks the following functionality:
4838
:::info
4939

5040
To enable this experiment, set the environment variable:
51-
`TASK_X_ANY_VARIABLES=1`. Check out [our guide to enabling experiments
41+
`TASK_X_MAP_VARIABLES=1`. Check out [our guide to enabling experiments
5242
][enabling-experiments] for more information.
5343

5444
:::
5545

56-
## Maps
57-
5846
This proposal removes support for the `sh` keyword in favour of a new syntax for
5947
dynamically defined variables, This allows you to define a map directly as you
6048
would for any other type:
@@ -111,19 +99,16 @@ will now need to escape the `$` with a backslash (`\`) to stop Task from
11199
executing it as a command.
112100

113101
</TabItem>
114-
115102
<TabItem value="2">
116103

117104
:::info
118105

119106
To enable this experiment, set the environment variable:
120-
`TASK_X_ANY_VARIABLES=2`. Check out [our guide to enabling experiments
107+
`TASK_X_MAP_VARIABLES=2`. Check out [our guide to enabling experiments
121108
][enabling-experiments] for more information.
122109

123110
:::
124111

125-
## Maps
126-
127112
This proposal maintains backwards-compatibility and the `sh` subkey and adds
128113
another new `map` subkey for defining map variables:
129114

@@ -150,7 +135,13 @@ objects/arrays. This is similar to the `fromJSON` template function, but means
150135
that you only have to parse the JSON/YAML once when you declare the variable,
151136
instead of every time you want to access a value.
152137

153-
Before:
138+
<Tabs defaultValue="2"
139+
values={[
140+
{label: 'Before', value: '1'},
141+
{label: 'After', value: '2'}
142+
]}>
143+
144+
<TabItem value="1">
154145

155146
```yaml
156147
version: 3
@@ -164,7 +155,8 @@ tasks:
164155
- 'echo {{(fromJSON .FOO).b}}'
165156
```
166157

167-
After:
158+
</TabItem>
159+
<TabItem value="2">
168160

169161
```yaml
170162
version: 3
@@ -179,12 +171,26 @@ tasks:
179171
- 'echo {{.FOO.b}}'
180172
```
181173

174+
</TabItem></Tabs>
175+
182176
## Variables by reference
183177

184178
Lastly, this proposal adds support for defining and passing variables by
185179
reference. This is really important now that variables can be types other than a
186-
string. Previously, to send a variable from one task to another, you would have
187-
to use the templating system to pass it:
180+
string.
181+
182+
Previously, to send a variable from one task to another, you would have to use
183+
the templating system. Unfortunately, the templater _always_ outputs a string
184+
and operations on the passed variable may not have behaved as expected. With
185+
this proposal, you can now pass variables by reference using the `ref` subkey:
186+
187+
<Tabs defaultValue="2"
188+
values={[
189+
{label: 'Before', value: '1'},
190+
{label: 'After', value: '2'}
191+
]}>
192+
193+
<TabItem value="1">
188194

189195
```yaml
190196
version: 3
@@ -202,10 +208,8 @@ tasks:
202208
- 'echo {{index .FOO 0}}' # <-- FOO is a string so the task outputs '91' which is the ASCII code for '[' instead of the expected 'A'
203209
```
204210

205-
Unfortunately, this results in the value always being passed as a string as this
206-
is the output type of the templater and operations on the passed variable may
207-
not behave as expected. With this proposal, you can now pass variables by
208-
reference using the `ref` subkey:
211+
</TabItem>
212+
<TabItem value="2">
209213

210214
```yaml
211215
version: 3
@@ -218,12 +222,14 @@ tasks:
218222
- task: bar
219223
vars:
220224
FOO:
221-
ref: FOO # <-- FOO gets passed by reference to bar and maintains its type
225+
ref: .FOO # <-- FOO gets passed by reference to bar and maintains its type
222226
bar:
223227
cmds:
224228
- 'echo {{index .FOO 0}}' # <-- FOO is still a map so the task outputs 'A' as expected
225229
```
226230

231+
</TabItem></Tabs>
232+
227233
This means that the type of the variable is maintained when it is passed to
228234
another Task. This also works the same way when calling `deps` and when defining
229235
a variable and can be used in any combination:
@@ -236,111 +242,94 @@ tasks:
236242
vars:
237243
FOO: [A, B, C] # <-- FOO is defined as an array
238244
BAR:
239-
ref: FOO # <-- BAR is defined as a reference to FOO
245+
ref: .FOO # <-- BAR is defined as a reference to FOO
240246
deps:
241247
- task: bar
242248
vars:
243249
BAR:
244-
ref: BAR # <-- BAR gets passed by reference to bar and maintains its type
250+
ref: .BAR # <-- BAR gets passed by reference to bar and maintains its type
245251
bar:
246252
cmds:
247253
- 'echo {{index .BAR 0}}' # <-- BAR still refers to FOO so the task outputs 'A'
248254
```
249255

250-
</TabItem></Tabs>
251-
252-
---
253-
254-
## Common to both proposals
255-
256-
Both proposals add support for all other variable types by directly defining
257-
them in the Taskfile. For example:
258-
259-
### Evaluating booleans
256+
All references use the same templating syntax as regular templates, so in
257+
addition to simply calling `.FOO`, you can also pass subkeys (`.FOO.BAR`) or
258+
indexes (`index .FOO 0`) and use functions (`len .FOO`):
260259

261260
```yaml
262261
version: 3
263262
264263
tasks:
265264
foo:
266265
vars:
267-
BOOL: false
266+
FOO: [A, B, C] # <-- FOO is defined as an array
268267
cmds:
269-
- '{{if .BOOL}}echo foo{{end}}'
270-
```
271-
272-
### Arithmetic
273-
274-
```yaml
275-
version: 3
276-
277-
tasks:
278-
foo:
279-
vars:
280-
INT: 10
281-
FLOAT: 3.14159
268+
- task: bar
269+
vars:
270+
FOO:
271+
ref: index .FOO 0 # <-- The element at index 0 is passed by reference to bar
272+
bar:
282273
cmds:
283-
- 'echo {{add .INT .FLOAT}}'
274+
- 'echo {{.MYVAR}}' # <-- FOO is just the letter 'A'
284275
```
285276

286-
### Ranging
287-
288-
```yaml
289-
version: 3
277+
</TabItem></Tabs>
290278

291-
tasks:
292-
foo:
293-
vars:
294-
ARRAY: [1, 2, 3]
295-
cmds:
296-
- 'echo {{range .ARRAY}}{{.}}{{end}}'
297-
```
279+
## Looping over maps
298280

299-
There are many more templating functions which can be used with the new types of
300-
variables. For a full list, see the [slim-sprig][slim-sprig] documentation.
281+
This experiment also adds support for looping over maps using the `for` keyword,
282+
just like arrays. In addition to the `{{.ITEM}}` variable being populated when
283+
looping over a map, we also make an additional `{{.KEY}}` variable available
284+
that holds the string value of the map key.
301285

302-
## Looping over variables
286+
<Tabs defaultValue="1" queryString="proposal"
287+
values={[
288+
{label: 'Proposal 1', value: '1'},
289+
{label: 'Proposal 2', value: '2'}
290+
]}>
303291

304-
Previously, you would have to use a delimiter separated string to loop over an
305-
arbitrary list of items in a variable and split them by using the `split` subkey
306-
to specify the delimiter:
292+
<TabItem value="1">
307293

308294
```yaml
309295
version: 3
310296
311297
tasks:
312298
foo:
313299
vars:
314-
LIST: 'foo,bar,baz'
300+
MAP: {a: 1, b: 2, c: 3}
315301
cmds:
316302
- for:
317-
var: LIST
318-
split: ','
319-
cmd: echo {{.ITEM}}
303+
var: MAP
304+
cmd: 'echo "{{.KEY}}: {{.ITEM}}"'
320305
```
321306

322-
Both of these proposals add support for looping over "collection-type" variables
323-
using the `for` keyword, so now you are able to loop over a map/array variable
324-
directly:
307+
</TabItem>
308+
<TabItem value="2">
325309

326310
```yaml
327311
version: 3
328312
329313
tasks:
330314
foo:
331315
vars:
332-
LIST: [foo, bar, baz]
316+
map:
317+
MAP: {a: 1, b: 2, c: 3}
333318
cmds:
334319
- for:
335-
var: LIST
336-
cmd: echo {{.ITEM}}
320+
var: MAP
321+
cmd: 'echo "{{.KEY}}: {{.ITEM}}"'
337322
```
338323

339-
When looping over a map we also make an additional `{{.KEY}}` variable availabe
340-
that holds the string value of the map key. Remember that maps are unordered, so
324+
:::note
325+
326+
Remember that maps are unordered, so
341327
the order in which the items are looped over is random.
342328

329+
:::
330+
331+
</TabItem></Tabs>
332+
343333
{/* prettier-ignore-start */}
344-
[enabling-experiments]: /experiments/#enabling-experiments
345-
[slim-sprig]: https://go-task.github.io/slim-sprig/
334+
[enabling-experiments]: ./experiments.mdx#enabling-experiments
346335
{/* prettier-ignore-end */}

0 commit comments

Comments
 (0)