Task

website·Indexed 36 days ago

https://taskfile.dev/

A task runner and build tool that uses Taskfiles to define and execute commands. The documentation provides a comprehensive guide on creating Taskfiles, managing environment variables, handling dependencies, and using CLI flags such as --dry, --summary, and --list.

Tokens
23.1K
Snippets
154
Records
187
Agent score
73%

What's inside Task

  1. Overview of Task Go Package API

    Task can be used as a Go package to extend its functionality or integrate it into Go projects. Note that the package API is currently experimental and subject to breaking changes in minor or patch releases. It is recommended to pin the version in your go.mod file.

    Key packages include:

    • github.com/go-task/task/v3: Core functionality, primarily exposed via task.Executor for fetching and executing tasks.
    • github.com/go-task/task/v3/taskfile: Utilities for reading Taskfiles from local files, HTTP/HTTPS, Git, or stdin.
    • github.com/go-task/task/v3/taskfile/ast: Tools for parsing Taskfile YAML into an Abstract Syntax Tree (AST).
    • github.com/go-task/task/v3/errors: Custom error types implementing the errors.TaskError interface, which provides a Code() method for unique exit codes.
  2. Access Task documentation for AI/LLM Assistants

    Task provides structured, context-optimized documentation for AI assistants (like Claude Code and Cursor) via the following endpoints:

    • llms.txt: A lightweight overview of the documentation.
    • llms-full.txt: The complete documentation containing all content.
  3. Inspect task status and metadata

    Retrieve information about tasks without necessarily executing them:

    • --status: Check if tasks are up-to-date.
    • --summary: Show detailed information about a specific task.
    • --json: Output task information in JSON format (must be used with --list or --list-all).
    • --sort <mode>: Change listing order. Modes: default (root tasks first, then alphabetical), alphanumeric, or none (Taskfile order).
    task build --status
    task build --summary
    task --list --json
    task --list --sort alphanumeric
  4. Understand the Task project security incident response process

    The Task project follows a five-step incident response plan to handle reported vulnerabilities:

    1. Detect: Issues are reported privately or identified via scanners/alerts.
    2. Triage: Maintainers notify each other via secure channels, acknowledge the reporter, and categorize the issue by severity (Critical, High, Medium, or Low). A draft GitHub Security Advisory (GHSA) is opened, and a CVE may be created for high/critical issues.
    3. Mitigate: Immediate actions are taken to stop further harm (e.g., rotating secrets, rebuilding services), followed by root cause analysis, patching, testing, and releasing new versions.
    4. Disclose: The GHSA is published, detailing affected versions, impact, root cause, and resolution steps. Public communication via blogs or social media may follow.
    5. Learn: The disclosure is permanently documented, and preventative changes are implemented to avoid future occurrences.
  5. Understand Task's security threat model and trust boundaries

    Task identifies several critical trust boundaries that users and contributors should be aware of: the boundary between the project repository and CI/CD environments, the boundary between the Task binary and remote Taskfiles fetched over the network, the boundary between artifact generation and distribution, and the boundary between the Task binary and user-defined shell commands.

    Crucial Note: Task is designed to execute user-defined shell commands. Users are solely responsible for the security and integrity of the commands they define within their Taskfiles.

  6. Loop over a matrix of permutations

    Use the matrix property within for to loop over all possible permutations of multiple lists. This is useful for cross-platform or cross-architecture builds. You can use literal lists or reference other list variables using the ref key. Values are accessed via {{.ITEM.KEY_NAME}}.
    version: '3'
    
    vars:
      OS_VAR: ['windows', 'linux', 'darwin']
      ARCH_VAR: ['amd64', 'arm64']
    
    tasks:
      default:
        silent: true
        cmds:
          - for:
              matrix:
                OS:
                  ref: .OS_VAR
                ARCH:
                  ref: .ARCH_VAR
            cmd: echo "{{.ITEM.OS}}/{{.ITEM.ARCH}}"
  7. Loop over tasks and dependencies

    The for property can be used with the task keyword to execute a specific task multiple times with different variables, or to dynamically determine which task to run based on the loop value. This also applies to the deps property, allowing for parallel execution of looped dependencies (though the order of execution is not guaranteed).
    version: '3'
    
    tasks:
      default:
        deps:
          - for: [foo, bar]
            task: my-task
            vars:
              FILE: '{{.ITEM}}'
    
      my-task:
        cmds:
          - echo '{{.FILE}}'
  8. Install Task on macOS and Linux using Homebrew

    Task can be installed via the official Homebrew tap or the official Homebrew repository.
    # Via official tap
    brew install go-task/tap/go-task
    
    # Via official Homebrew repository
    brew install go-task
  9. Implement warning prompts for Task tasks

    Warning prompts allow you to require user confirmation before a specific task is executed. You can define a prompt as a single string or a list of strings. If the user denies the prompt, Task exits with code 205. If approved, the task continues normally. Prompts are executed before the commands in the task.
    version: '3'
    
    tasks:
      # Example with a single prompt
      dangerous:
        prompt: This is a dangerous command... Do you want to continue?
        cmds:
          - echo 'dangerous command'
    
      # Example with multiple prompts
      very-dangerous:
        prompt:
          - This is a dangerous command... Do you want to continue?
          - Are you sure?
        cmds:
          - echo 'dangerous command'
  10. Parse JSON or YAML strings into map variables

    Combine the ref keyword with the fromJson or fromYaml templating functions to convert a raw string into a usable map variable.
    version: '3'
    
    tasks:
      task-with-map:
        vars:
          JSON: '{"a": 1, "b": 2, "c": 3}'
          FOO:
            ref: 'fromJson .JSON'
        cmds:
          - echo {{.FOO}}
  11. Install Task via the official install script

    The install script is recommended for CI environments. By default, it installs to the ./bin directory relative to the working directory. You can override the installation directory using the -b parameter and specify a version tag as the final argument.
    # Default installation
    sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d
    
    # Install to a specific directory (e.g., ~/.local/bin)
    sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
    
    # Install a specific version
    sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d v3.36.0
    
    # Install specific version to specific directory
    sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin v3.42.1