Skip to content

Task doesn't expand correctly YAML anchors in for: matrix #2203

@marco-m-pix4d

Description

@marco-m-pix4d

Description

Consider the following Taskfile:

version: '3'

dev_ws: &dev_ws
  - dev-user-1
  - dev-user-2

tasks:
  foo:
    cmds:
      - for:
          matrix:
            ENV:
              - dev
              - prod
            WS: *dev_ws
        silent: true
        cmd: |
          echo +++ {{.ITEM.ENV}} {{.ITEM.WS}}

If I run it, I get:

$ task -t foo.yml foo
err:  matrix values must be an array or a reference
file: foo.yml:14:13
  12 |       - for:
  13 |           matrix:
> 14 |             ENV:
     |             ^
  15 |               - dev
  16 |               - prod

On the other hand, the input file is correct YAML. If I ask yq (https://github.com/mikefarah/yq) to expand the YAML anchor, I get:

$ yq 'explode(.)' < foo.yml
version: '3'
dev_ws:
  - dev-user-1
  - dev-user-2
tasks:
  foo:
    cmds:
      - for:
          matrix:
            ENV:
              - dev
              - prod
            WS:
              - dev-user-1
              - dev-user-2
        silent: true
        cmd: |
          echo +++ {{.ITEM.ENV}} {{.ITEM.WS}}

and the irony, if I pass the output of yq to the stdin of Task, I get what I expected:

$ yq 'explode(.)' < foo.yml | task -t - foo
+++ dev dev-user-1
+++ dev dev-user-2
+++ prod dev-user-1
+++ prod dev-user-2

Version

3.43.2

Operating system

macOS, Linux

Experiments Enabled

None.

Example Taskfile

version: '3'

dev_ws: &dev_ws
  - dev-user-1
  - dev-user-2

tasks:
  foo:
    cmds:
      - for:
          matrix:
            ENV:
              - dev
              - prod
            WS: *dev_ws
        silent: true
        cmd: |
          echo +++ {{.ITEM.ENV}} {{.ITEM.WS}}

Thank you for Task! :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions