Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: matrix support #1766

Closed
nikaro opened this issue Aug 17, 2024 · 5 comments · Fixed by #1767
Closed

Feature: matrix support #1766

nikaro opened this issue Aug 17, 2024 · 5 comments · Fixed by #1767
Labels
area: loops Changes related to looping over tasks/commands.

Comments

@nikaro
Copy link

nikaro commented Aug 17, 2024

Hello,

It would be nice to be able to do something like this:

env:
  APP: myapp
  CGO_ENABLED: 0
  GOARCH:
    sh: go env GOARCH
  GOOS:
    sh: go env GOOS

tasks:
  build:
    desc: Build application
    cmd: go build -o build/${APP}-${GOOS}-${GOARCH} .

  build:all:
    desc: Build for all targets
    matrix:
      ARCH: [amd64, arm64]
      OS: [linux, darwin, windows]
    env:
      GOARCH: "{{.matrix.ARCH}}"
      GOOS: "{{.matrix.OS}}"
    cmds:
      - task: build

Previous issue on the subject: #675

Current workaround:

  build:all:
    desc: Build for all targets
    cmds:
      - for: [linux/amd64, linux/arm64, darwin/amd64, darwin/arm64, windows/amd64, windows/arm64]
        cmd: >-
          export GOOS=$(echo {{.ITEM}} | cut -d/ -f1);
          export GOARCH=$(echo {{.ITEM}} | cut -d/ -f2);
          go build -o build/${APP}-${GOOS}-${GOARCH} .
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Aug 17, 2024
@andreynering
Copy link
Member

Hey @nikaro,

We already have for: so you can loop though variables. That would sove your use case.

https://taskfile.dev/usage/#looping-over-values

@andreynering andreynering closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2024
@andreynering andreynering added type: question Further information is requested. and removed state: needs triage Waiting to be triaged by a maintainer. labels Aug 19, 2024
@nikaro
Copy link
Author

nikaro commented Aug 19, 2024

Hello @andreynering,

You mean something like this?

  build:all:
    desc: Build for all targets
    vars:
      matrix:
        - os: linux
          arch: arm64
        - os: linux
          arch: amd64
        - os: darwin
          arch: arm64
        - os: darwin
          arch: darwin
        - os: windows
          arch: arm64
        - os: windows
          arch: amd64
    cmds:
      - for:
          var: matrix
        cmd: go build -o build/${APP}-{{.ITEM.os}}-{{.ITEM.arch}} .

This is a bit cleaner (as it avoids the | cut -d hack), but still a proper matrix support would be better in terms of readability :-)

@pd93
Copy link
Member

pd93 commented Aug 19, 2024

@andreynering I'm inclined to agree that there is a valid use-case here even if it is only to reduce a bit of repetition. Can I propose the following syntax:

  build:all:
    desc: Build for all targets
    cmds:
      - for:
          matrix:
            ARCH: [amd64, arm64]
            OS: [linux, darwin, windows]
        cmd: go build -o build/${APP}-{{.ITEM.OS}}-{{.ITEM.ARCH}} .

This way it is any extension to the existing for functionality rather than another looping keyword. This should be relatively simple to plug into the existing code.

Edit: Also related: #675

@andreynering
Copy link
Member

Yeah, thinking in it as an extension to for: makes more sense 👍

@andreynering andreynering reopened this Aug 19, 2024
@pd93 pd93 added type: enhancement area: loops Changes related to looping over tasks/commands. and removed type: question Further information is requested. labels Aug 19, 2024
@vmaerten
Copy link
Member

I totally agree. I would add this is implemented like that in Github action and it works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: loops Changes related to looping over tasks/commands.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants