Skip to content

[Proposal] Inline platform/arch key for commands #978

@leaanthony

Description

@leaanthony

Firstly, thanks for such an awesome project!

I've been trying to write a simple taskfile that does slightly different things depending on platform/arch. This has led me to try the 2 current methods for doing this:

  • Go Template method
  • Multiple Taskfiles

The first is hard to read and I had issues with it outside of simple echos (easy to make invalid YAML). For multiple platforms, this would get messier:

- echo '{{if eq OS "windows"}}windows-command{{else}}unix-command{{end}}'

The second option can lead to many Taskfiles on disk making it harder to manage.

As an example scenario, I want to run a go build on linux, darwin & windows but need to do slightly different things on each:

  • On Windows, generate a .syso file
  • Run go build
  • On Darwin, create an app structure
  • On Darwin, copy the app to the app structure
  • On windows, copy the correct 3rd party dll for the architecture
  • On linux, copy a .desktop file to the directory

For the templating option, Taskfile.yaml would be very messy and I'm not even sure it's achievable in any elegant way.
The multi-taskfile option would be better IMHO, but now there's potentially 4 task files and 1 main.go file which seems overkill, not to mention code duplication. I mean it's possible but....

When I break down the problem, I simply want to be able to run certain commands on certain platforms within a task. This led me to think about an alternative approach:

For a cmd, allow the following syntax: - [platform/arch:] command

Example:

version: '3'

tasks:
  build:
    cmds:
      - darwin: mkdir -p x/y/z
      - windows: winres -I app.manifest -o app.syso
      - go build
      - windows/386: copy ..\32bit\app.dll .
      - windows/amd64: copy ..\64bit\app.dll .
      - linux: cp ../app.desktop .

I've created a PoC and it's a reasonably simple change and works well. I'm not well-versed in Task and the nuances this may introduce so I thought I'd put it out there and see what people think. If there's agreement that it's a good addition, I'll create a PR so I can get feedback on the best way to implement it.

Cheers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions