Files
oam/knowledge base/task.md
2024-11-03 12:55:03 +01:00

2.7 KiB

Task

Task runner aiming to be simpler and easier to use than GNU Make.

  1. TL;DR
  2. Further readings
    1. Sources

TL;DR

Taskfiles are Task's Makefile counterpart.
Taskfiles are written in YAML.

Task leverages mvdan.cc/sh to run commands, which is a native Go shell interpreter.
This allows to write sh/bash commands and have them work even where sh or bash are usually not available (e.g.: Windows) as long as any called executable is available in PATH.

Pros:

  • Taskfiles are more readable than Makefiles. Specifically:

    • No need to use tabs.
    • No need for special symbols.
    • Easier environment variables management.

Cons:

  • Taskfiles are written in YAML. ≈(・ཀ・≈)
    That makes them very much similar to [Gitlab / Azure Devops]'s pipelines, and if one has any experience with them one knows what a pain that can be.
Setup
# Install the executable.
brew install 'go-task'
choco install 'go-task'
dnf install 'go-task'
snap install 'task' --classic
zypper install 'https://github.com/go-task/task/releases/download/v3.39.2/task_linux_amd64.rpm'

# Setup the shell's completion.
task --completion 'fish' > ~/'.config/fish/completions/task.fish'
task --completion 'zsh'  > '/usr/local/share/zsh/site-functions/_task'
task --completion 'bash' > '/etc/bash_completion.d/task'
Usage
  1. Create a file called Taskfile.yml, taskfile.yml, Taskfile.yaml, taskfile.yaml, Taskfile.dist.yml, taskfile.dist.yml, Taskfile.dist.yaml, or taskfile.dist.yaml (ordered by priority) in the root of one's project.
    The cmds keys shall contain the commands for their own tasks:

    version: '3'
    
    tasks:
      build:
        cmds:
          - go build -v -i main.go
    
      assets:
        cmds:
          - esbuild --bundle --minify css/index.css > public/bundle.css
    
  2. Run tasks by their name:

    task 'assets' 'build'
    task --dry 'bootstrap'
    

    If task names are omitted, a task named default will be assumed.

Further readings

Sources