Setting up CI/CD for a Godot game

Let’s see how to automate our Godot game projects!

This article was originally posted on Codemagic’s blog.

These past few months, I’ve talked about using Codemagic to build and publish Unity games. Be it to link it to the Firebase App distribution system, get detailed test reports or even share VR games for an Oculus headset, setting up a CI/CD pipeline is a great way of getting a robust and efficient workflow.

But in the world of game design, there’s another well-known game engine that is getting more and more popular among indie creators: Godot.

So, today, let’s shift gears and see how we can use Codemagic to make an automated pipeline for Godot projects, too!

In this tutorial I’ll:

  • Give a short overview of the Godot game engine
  • Quickly introduce the sample project I’ll work with
  • Show how to setup a Codemagic workflow to automate the build of our Godot game

What is Godot?

Godot’s logo (from: https://godotengine.org/press)

Godot is a free game engine that was initially founded by Juan Linietsky and Ariel Manzur, before it became open-source and community-driven in 2014. It allows you to create both 2D and 3D projects and to export for various platforms: Windows, Mac, Linux, Android, iOS, or even WebGL. (It even handles consoles with a bit of extra plugin setup)

The engine is Git-friendly, uses a node-based scene architecture and comes along with its own efficient programming language: GDScript… but it can also use the more common C# or C++ languages. Godot lets you organise your scenes, prefabs and various assets in a very flexible way, and it is meant to be easy-to-use for devs and artists alike. Still, it provides advanced features, too, such as a set of tools to improve your Godot editor itself and customise your workflow!

Note: about Git versioning – what’s cool about Godot is that it relies on basic text files for your project definitions and configurations, from the startup settings to the export modes. That makes it totally compatible with Git pipelines and easy to share your entire project with the rest of your team!

Godot has been used to create various 2D and 3D games, as well as other types of software like the “RPG in a Box” game editing tool. If you want to take a look at all their featured projects, check out their showcase section 😉

Finally, because the open-source philosophy has such an important role in the development of Godot, there are tons of great docs and tutorials contributed either by the original creators or by other members of the community.

A peek at our Godot sample project

For this quick introduction to automating a Godot build, I’m going to use one of the getting started tutorials from the engine’s docs: the tutorial for the 2D game “Dodge the Creeps”. Note that, because we are going to actually export the project as an executable (in our case, a Mac app), you should also take a look at the docs on preparing the export if you’re not yet familiar with Godot 🙂

Note: the Godot “exports” are the equivalent of Unity and Unreal Engine “builds” – thus I’ll use both terms interchangeably in this article.

To check out the entire project architecture, take a look at the GitHub repo! 🚀

The game in itself is quite simple: you control a little player sprite and you click on the screen to set its target point; enemies are spawn periodically somewhere along the edge of the screen, and they simply move on a straight line after popping. You have to avoid these “creeps”: if one touches you, it’s game over! The longer you dodge them, the more points you earn.

Preparing our Godot project for export

For this example, I’ll be building my Godot game for Mac. So, just as explained in the Godot docs, I’ve made sure to setup my project as follows:

  • download the export templates: These won’t be available directly on the remote Codemagic machine, obviously, but they’re required to prepare everything for the auto-build
    To download and install those templates, just open the Editor > Manage Export Templates… menu, and then click the “Download and Install” button:
  • configure the export presets: now that we have templates, we can add various export presets to our project – this are essential because they’re the one(s) we’ll call from the command-line to build the project into an executable.
    To add a preset, just open the Project > Export… menu and click the “Add…” button at the top; then, choose the preset template you want to import (in my case, the “Mac OSX“):

You can also set up some info about the export, such as a custom name for the export preset (here, I’ve changed it to “mac“), or some additional data and identifiers for your app:

Keep in mind the name you gave your preset: we will use this reference in our export shell command!

Note: also – because we’ll be using a unique reference, you can define additional “ready-to-go” export presets even if you don’t use them, like my Windows “win” preset here: They’ll just be ignored if we use another preset 😉

If you scroll down a bit in the export options of the “mac” preset, you’ll also notice that, by default the macOS export makes a “signed” app – this is usually required if you want end users to actually be able to run your executable (otherwise, the Mac Gatekeeper will most likely prevent it from starting up). This is also where you can “notarise” your app by use your Apple Developer ID Certificate, if you have one. Else, you can ignore this step and Godot will use an ad-hoc signature for the app. As explained in the Godot docs, the signing and notarisation data determine if and how the app will eventually run.

Note however that, in order to get a properly signed (and optionally notarised) macOS export, you’ll need to run the export step on a macOS system with the XCode command-line tools installed! (fortunately for us, Codemagic’s Mac build machines have Xcode CLI preinstalled).

Versioning our Godot project

Now, we need to make sure our Godot project is Git versioned so that we can push it to an online Git provider and give access to the sources to Codemagic.

To prepare our new Git repo, we can simply use the git init command. And then, we’re going to discover a really great perk of Godot in terms of Git versioning… Since everything is text-based, we don’t have any complex file tree, or bonus metafiles to watch out for: we can simply commit everything, and we are not even required to add a .gitignore!

You can however add one if you want, in particular to avoid versioning auto-generated data:

  • the .import directory: it stores all the imported file configs but will be re-created if need be
  • *.translation: those files are generated from CSVs
  • the .mono directory (it only exists if you’re using the Mono version of the Godot editor): it stores auto-generated Mono-related files

Then, there is the special case of the export_presets.cfg.

If you take a look at your FileSystem dock inside the Godot editor, you won’t actually see this file, because this view filters project-wide files and other high-level settings (because it is better to use the Godot setting modals to update those properly). However, if you take a look at your Godot project folder with your usual file browser, you’ll see that this export_presets.cfg is there, at the root, and if you open it, you’ll get something like this:

This file is important because it’s what tells Godot how to build a given export preset. For example, here, I find the two “mac” and “win” presets I prepared earlier, with their additional config data.

However, it can be risky to add this file to your Git repo because it can contain app signatures, and other sensitive credentials.

However, it’s up to you to decide. If it’s safe to commit your export_presets.cfg file because it just contains basic public info, feel free to simply add it to the repo and skip the next paragraph 🙂

Else, if your export_presets.cfg can’t be committed because of security issues, a trick is to use environment variables: while the Godot export presets don’t handle environment variables themselves for now, there’s nothing stopping you from encoding the entire file to base64 and adding it to your Codemagic app as an environment variable!

So simply run the following command on your local machine, at the root of your Godot project folder:

cat export_presets.cfg | base64 | pbcopy

Then, go to your Codemagic app dashboard and, in the “Environment variables” tab, add a new variable called GODOT_EXPORT_PRESETS, paste the file’s encoded contents as the value and create a new environment variable group, “godot“.

We’ll see in just a second how to use this variable in our Codemagic workflow configuration 😉

Automating our Godot game build with Codemagic

We are now ready to set up our Codemagic workflow to automate the export of our Godot game!

Since Codemagic isn’t yet as knee-deep in Godot automation as in Unity automation, there is no Godot editor installed on the remote machines by default. But it’s not a problem, as we can download the editor and the export templates, and set everything up properly.

Then, we’ll simply decode our GODOT_EXPORT_PRESETS environment variable to “re-inject” our export_presets.cfg file into the sources fetched from the Git provider.

Finally, we’ll use the Godot command-line tools to export our project using the “mac” preset.

Here is the complete codemagic.yaml workflow configuration file:

Now, all that’s left to do is to run this pipeline, and after just a few minutes, we’ll get our Mac app all zipped in a little archive:

Also, you’ll notice that downloading the engine and the templates is really fast – it can of course depend a bit on your current Internet connection, but Godot is a very lightweight piece of software that is just a breeze to get and install! 😉

Note: after you download and unzip the exported project, when you try and run the app, you might get some security warnings depending on how you signed and notarized your project; usually, you can just force-open the project, or put it on your computer’s whitelist, but for more info, make sure to check out Godot’s docs.

Conclusion

Even if Unity and Unreal Engine are still the big players in the world of video games, the Godot 2D and 3D engine is getting more and more fans as its community-based open-source development adds ever more features!

And in this article, we’ve seen that is actually very easy to use Godot with Git versioning, and that using it along with Codemagic allows us to quickly automate the building our game 🙂

I hope you enjoyed this tutorial — feel free to share your ideas for other DevOps topics you’d like me to make Unity tutorials on! You can find me on Codemagic’s Slack, on Medium, or on Twitter.

Don’t forget: you can get the sample project with the code of “Dodge the Creeps” and the codemagic.yaml file on GitHub over here 🚀

Leave a Reply

Your email address will not be published.