Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automate all the things with Task

Automate all the things with Task

Automate the boring tasks that you use on a daily basis

Avatar for Andrey Nering

Andrey Nering

May 11, 2025
Tweet

More Decks by Andrey Nering

Other Decks in Programming

Transcript

  1. About me @andreynering everywhere Works with dev since 2013 Web

    background (mostly back-end), loves Go, databases and tooling Ruby on Rails PostgreSQL React.js Go Started on Open Source by contributing to the Rails Guides Other projects came as the need appeared: go-testfixtures Task Andrey Nering - Joinville, Santa Catarina
  2. What is Task? Development workflow Setup dev environment (install required

    stuff) Build your apps Run linting / formatting / tests Shipping stuff Handle Docker images (build, run, ship, etc) Run auxiliary servers (PostgreSQL, Redis, OpenSearch/Elasticsearch, etc) Simple deploys etc. It’s a task runner that you can use to automate stuff from the command line:
  3. Why I started Task? I wanted something simple that just

    works I wanted something fast! (Zero delay when running a task) I looked for tools in the area and didn’t like them Make didn’t work well for me No ideal support for Windows .PHONY and other annoyances Caching based on files timestamp instead of content Other tools were difficult to learn Other tools had undesired dependencies (Python, etc) Task is a single binary I had free time in a holiday and was motivated to work on something new and fun 🙂
  4. Installation # macOS brew install go-task # Ubuntu / Snap

    sudo snap install task --classic # npm npm install -g @go-task/cli # Windows winget install Task.Task # ArchLinux pacman -S go-task # Fedora dnf install go-task # Nix nix-env -iA nixpkgs.go-task # Others... # Check out https://taskfile.dev/installation/
  5. Let’s start! Documentation is available at: taskfile.dev A Taskfile can

    be named one of these (in order of priority): Taskfile.yml taskfile.yml Taskfile.yaml taskfile.yaml Taskfile.dist.yml taskfile.dist.yml Taskfile.dist.yaml taskfile.dist.yaml
  6. Hello, World! Output: # Taskfile.yaml version: '3' tasks: say-hi: cmds:

    - echo 'Hello, world!!!' $ task say-hi task: [say-hi] echo 'Hello, world!!!' Hello, world!!!
  7. Silent Output: version: '3' tasks: say-hi: cmds: - echo 'Hello,

    world!!!' silent: true # <-- supress echoing $ task say-hi Hello, world!!!
  8. Silent Global Output: version: '3' silent: true # <-- silent

    can be set globally tasks: say-hi: cmds: - echo 'Hello, world!!!' $ task say-hi Hello, world!!!
  9. Default Output: version: '3' silent: true tasks: default: # <--

    I will be run by default cmds: - echo 'Hello, world!!!' $ task Hello, world!!!
  10. Task aliases version: '3' silent: true tasks: default: aliases: [hello,

    h] cmds: - echo 'Hello, world!' $ task hello Hello, world! $ task h Hello, world! $ task Hello, world!
  11. Basic Go app example version: '3' tasks: build: cmds: -

    go generate ./... - go build -o my_app ./cmd/app/main.go fmt: cmds: - gofumpt -l -w . tidy: cmds: - go mod tidy lint: cmds: - golangci-lint run test: cmds: - go test ./...
  12. Short version version: '3' tasks: build: # <-- array of

    commands - go generate ./... - go build -o my_app ./cmd/app/main.go # command fmt: gofumpt -l -w . tidy: go mod tidy lint: golangci-lint run test: go test ./...
  13. Add documentation Let’s add some descriptions ( desc: ) to

    start documenting our Taskfile: version: '3' tasks: build: aliases: [b] desc: Build the application cmds: - go build -o my_app ./cmd/app/main.go fmt: aliases: [format, f] desc: Format the source code cmds: - gofumpt -l -w . $ task --list task: Available tasks for this project: * build: Build the application (aliases: b) * fmt: Format the source code (aliases: format, f) * lint: Run linting checks (aliases: l) * test: Run tests (aliases: t)
  14. Listing all tasks version: '3' tasks: build: go build -o

    my_app ./cmd/app/main.go fmt: gofumpt -l -w . tidy: go mod tidy lint: golangci-lint run test: go test ./... $ task --list-all task: Available tasks for this project: * build: * fmt: * lint: * test: * tidy:
  15. Add further documentation version: '3' tasks: fmt: desc: Format the

    source code summary: | Format the source code using gofumpt. For more information about gofumpt, visit https://github.com/mvdan/gofumpt cmds: - gofumpt -l -w . $ task --summary fmt task: fmt Format the source code using gofumpt. For more information about gofumpt, visit https://github.com/mvdan/gofumpt commands: - gofumpt -l -w .
  16. Caching sources: can be added to prevent a task from

    running if the sources haven’t changed since the last run. The .task dir stores metadata and should be added to .gitignore . version: '3' tasks: build: cmds: - go build -o my_app ./cmd/app/main.go sources: # <-- input files - ./**/*.go generates: # <-- output files - ./my_app $ task build task: [build] go build -o my_app ./cmd/app/main.go $ task build task: Task "build" is up to date
  17. Caching (alternative, by timestamp) version: '3' tasks: build: cmds: -

    go build -o my_app ./cmd/app/main.go sources: - ./**/*.go generates: - ./my_app method: timestamp # <-- compare file timestamps instead of content
  18. Caching package manager version: '3' tasks: bundle:install: # <-- Ruby

    cmds: - bundle install sources: - Gemfile - Gemfile.lock npm:install: # <-- JavaScript cmds: - npm install sources: - package.json - package-lock.json - yarn.lock $ task npm:install task: [npm:install] bundle install $ task npm:install task: Task "npm:install" is up to date
  19. Caching and dependencies version: '3' tasks: build: deps: [js, css]

    cmds: - go build -v -o my_app ./app.go sources: - '**/*.go' - 'public/bundle.js' - 'public/bundle.css' js: cmds: - esbuild --bundle --minify assets/js/index.js > public/bundle.js sources: - assets/js/**/*.js css: cmds: - esbuild --bundle --minify assets/css/index.css > public/bundle.css sources: - assets/css/**/*.css
  20. Sources and watch version: '3' tasks: run: cmds: - go

    run -v -o my_app ./app.go sources: - '**/*.go' watch: true # <-- set this or run with `--watch`
  21. Variables version: '3' vars: JS_BUNDLE: public/bundle.js BINARY: app{{exeExt}} tasks: build:

    deps: [js] cmds: - go build -v -o {{.BINARY}} ./app.go sources: - '**/*.go' - '{{.JS_BUNDLE}}' generates: - '{{.BINARY}}' js: cmds: - esbuild --bundle --minify assets/js/index.js > {{.JS_BUNDLE}} sources: - assets/js/**/*.js generates: - '{{.JS_BUNDLE}}'
  22. Env Alternatively, you can import .env files as well: version:

    3 dotenv: ['.env', '.env.development'] version: '3' env: CGO_ENABLED: 0 tasks: server: desc: Start the server cmds: - go run ./cmd/server/main.go env: PORT: 8080 HOSTNAME: localhost DATABASE_URL: postgres://user:password@localhost:5432/mydb
  23. CLI_ARGS There are some special variables, documented here CLI_ARGS contains

    all arguments given after -- version: '3' tasks: docker: docker {{.CLI_ARGS}} npm: npm {{.CLI_ARGS}} rails: bundle exec rails {{.CLI_ARGS}} test: bundle exec ruby -Itest {{.CLI_ARGS}} $ task rails -- generate scaffold users task: [rails] bundle exec rails generate scaffold users # ... $ task test -- test/controllers/users_controllers_test.rb task: [rails] bundle exec ruby -Itest test/controllers/users_controllers_test.rb # ...
  24. Includes version: '3' includes: backend: taskfile: ./backend/Taskfile.yml dir: ./backend frontend:

    taskfile: ./frontend/Taskfile.yml dir: ./frontend docs: taskfile: ./docs/Taskfile.yml dir: ./docs $ task --list-all task: Available tasks for this project: * backend:build: * backend:test: * ... * frontend:build: * frontend:test: * ... * docs:build: * docs:server:
  25. Example: Go Web App A runnable example is available at:

    https://github.com/go-task/examples
  26. Tips alias t=task Use ChatGPT and Claude to generate Taskfiles

    for you. Create a global Taskfile on $HOME/Taskfile.yaml and run it from anywhere with task --global ...
  27. What’s next? Remote Taskfiles (#1317): include Taskfiles from remote sources

    Support HTTPS and Git Interactive Terminal UI (TUI) using Bubble Tea and Charm libraries version: '3' includes: my-remote-namespace: https://raw.githubusercontent.com/go-task/task/main/website/static/Taskfile.yml $ task my-remote-namespace:hello task: [hello] echo "Hello Task!" Hello Task!
  28. How to succeed on Open Source development Look for something

    that doesn’t exist or is not so good Do not give up, persist on the long term (Task exists for 8 years) Have great documentation The easiest to get started, the best Examples, examples, examples! Find great co-maintainers (this is hard!) @pd93 🇬🇧 @vmaerten 🇫🇷