Automating unity builds Ⅰ, an introduction to Taskfile
2020-12-18
{: .scale_media} I swear, I don't know where those shaders come from. {: .scale_media}
I love doing gamejams. I've probably done more than a dozen. And if you have ever done one, you know every second counts.
A gamejam is an event where participants make games following a theme on a short time frame (Usually ~48 hrs).
And so, everyone has a bag of tricks and shortcuts to gain those precious moments. This series of blogs will teach you how to automate building your unity projects, so you can focus more on doing, and less on waiting.
I tried to assume not a lot of familiarity with the technical stuff here, and if you don't know some specific commands it's fine. It is more about understanding the idea of automating commands.
These techniques are also useful for longer projects and bigger teams. Although usually those have dedicated machines and workflows, or even ops teams that will take care of everything. We will go for a much simpler approach.
CLI
A fundamental part of the automating process is using the Command Line Interface.
The command line interface allows users to interact with the computer through text commands instead of the graphical user interface.
Access to the cli will depend on your platform, but do not worry, to avoid OS specific problems, we will use taskfile{:target="_blank"}.
Taskfile
Taskfile is a modern alternative to make{:target="_blank"}, which is a build automation tool.
It allows us to specify commands we want to run again and again.
It also provides support for running commands before other commands, fingerprinting results so commands are only run when needed, and more.
Install
Follow the instructions here{:target="_blank"}.
Why not make? If you have used make before you might wonder, why bother with taskfile?
And it's totally fine to use it. I used to, all the time. But I find taskfiles much cleaner, plus the fact you won't have to fight any incompatibilities between installed versions.
Usage
If you want the full usage guide, I can't recommend enough the official{:target="_blank"} page enough.
For our case we just needed three things:
- Commands
- Variables
- Dependencies
We start by creating a Taskfile.yml
in the project root directory.
Commands
version: 3
tasks:
list-files:
cmds:
- ls
This task will list all files in the root directory. We can run it with task list-file
in our favorite shell.
A shell is a program allows running commands interactively.
This ain't terribly useful by itself, to make more interesting things we need...
Variables
version: 3
vars:
DIR: Builds
tasks:
list-files:
cmds:
- ls {{.DIR}}
This will list files inside the builds
folder, or whichever folder we choose to set the DIR
variable to.
But what if we want to run something before that command?
Dependencies
version: 3
vars:
DIR: Build
tasks:
build-project:
cmds:
- echo Imagine this is our build command
list-files:
cmds:
- ls {{.DIR}}
deps:
- task: build
This time we have defined an additional build-project
command that will be run before
list-files
.
But wait, build-project
simply prints a message to the console now, how do we
build the actual project? That we will see next.
What's next?
So this post has been a bit slow, but we needed to get familiar with taskfile before getting to interact with unity through the CLI.
Next post we will learn about calling Unity from the command line and passing commands.
As always, thanks for reading this tutorial. And if you want to know when the next blog will come up, follow me at @alvarber.