Skip to content

What is Task?

Introduction

For full documentation visit taskfile.dev.

Go Task is a popular task runner tool written in Go, known for its simplicity and ease of installation and use. Go Task uses a YAML file named Taskfile.yml to define your build tasks. This file resides in the root directory of your project. A basic task definition looks like this:

Taskfile.yml
version: '3'  # Specify Taskfile version

tasks:
  hello:  # Task name
    cmds:  # Commands to execute
      - echo "Hello, world!"

Once you have defined your tasks, you can run them using the task command followed by the task name:

task hello

This will execute the commands defined in the hello task and print Hello, world!.

A replacement for the GNU Make build tool

Features

  • Dependencies: You can specify dependencies between tasks using the deps key in the task definition.
  • Conditional execution: Use status, preconditions, or requires to conditionally run tasks.
  • Variables: Define and use variables within your tasks.
  • Custom build commands: Your commands are plain shell.
  • Prevent unnecessary work: Fingerprints locally generated files and their sources to skip tasks that are already up to date.

Example:

Taskfile.yml
version: '3'

tasks:
  build:
    desc: "Build Go application"
    deps: [js]
    cmds:
      - go build -v main.go

  js:
    desc: "Build Javascript assets"
    cmds:
      - esbuild --bundle --minify js/index.js > public/bundle.js
    sources:
      - src/js/**/*.js
    generates:
      - public/bundle.js

A simple task runner as a local CI

An easy way to simplify complex workflows with simple tasks. An example to execute acceptance tests (e2e) with prerequisites:

Taskfile.yml
version: '3'

tasks:
  test-e2e:
    desc: "Run end to end tests with Robot Framework"
    cmds:
      - docker compose up
      - defer: docker compose down
      - cat ./dump-e2e.sql | docker exec -e PGPASSWORD -t container-psql psql -U $POSTGRES_USER -d $POSTGRES_DB
      - robot --include e2e tests/
    env:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGPASSWORD: postgres
      POSTGRES_DB: postgres
      # ...

Modularization and reusability

Go Task allows you to define reusable tasks that can be used in different contexts:

  • This eliminates the need to repeat lengthy commands across multiple scripts or files.
  • You can create task libraries that encapsulate common functionality, promoting code reuse and reducing redundancy.