Task (aka Taskfile) is a task runner written in Go, which is similar to GNU Make, but in my opinion is a lot easier to use as you specify your tasks in yaml.
What to expect
In this post we will go through a quick demonstration using Task, how to install Task, as well as a couple of basic examples to get you up and running with Task.
Install
For mac, installing task::
1
|
|
For linux, installing task:
1
|
|
Or manual installation for arm as an example:
1 2 3 4 5 6 |
|
Verify that task is installed:
1 2 |
|
For more information check the installation page: - https://taskfile.dev/#/installation
Usage
Task uses a default config file: Taskfile.yml
in the current working directory where you can provide context on what your tasks should do.
To generate a Taskfile.yml
with example config, task gives us a --init
flag to generate a sample.
For a basic hello-world example, our task helloworld
will echo out hello, world!
. To generate the sample code, run:
1
|
|
Then update the config, to the following:
1 2 3 4 5 6 7 |
|
To demonstrate what the config means:
tasks
: refers to the list of taskshelloworld
: is the task namedesc
: describes the task, useful for listing taskscmds
: the commands that the task will execute
To list all our tasks for our taskfile:
1 2 3 |
|
Which we call using the application task
with the argument of the task name:
1 2 3 |
|
We can also reduce the output verbosity using silent
:
1 2 3 4 5 6 7 8 |
|
Which will result in:
1 2 |
|
For a example using environment variables, we can use it in two ways:
- per task
- globally, across all tasks
For using environment variables per task:
1 2 3 4 5 6 7 8 |
|
Results in:
1 2 3 |
|
For using environment variables globally across all tasks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Running our first task:
1 2 3 |
|
And running our second task:
1 2 3 |
|
To store your environment variables in a .env
file, you can specify it as the following in your Taskfile.yml
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
And in your .env
:
1
|
|
Then you should see your environment variables referenced from the .env
file:
1 2 3 |
|
We can also reference config using vars
:
1 2 3 4 5 6 7 8 9 10 |
|
In this case our task name is default
, therefore we can only run task
without any arguments, as default with be the default task:
1 2 3 |
|
To run both tasks with one command, you can specify dependencies, so if we define a task with zero commands but just dependencies, it will call those tasks and execute them:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
So when we run the all
task:
1 2 3 4 5 |
|
For more usage examples, have a look at their documentation: - https://taskfile.dev/#/usage
Thanks
Thanks for reading, if you like my content, check out my website or follow me at @ruanbekker on Twitter.