Automating Godot game releases to itch.io
Tags: gamedev, godot, github, automation
Published: 2022-01-18 00:21:13

If you're a game developer, you most likely want to spend your time actually designing and developing your game. Unfortunately, a lot of time goes into not-so-interesting manual administrative tasks. One of those tasks is publishing new builds. What if this work could be completely automated away and happen as you work on your game, in the background? With workflow automation tools like [GitHub Actions](https://github.com/features/actions), this is not only possible, but free to use and easy to achieve!

## The goal

Me and my friend [Luke](https://github.com/lstebner) are building [Farmhand Go!](https://rainbowcow-studio.itch.io/farmhand-go), a Godot game that's based around making in-game money by growing and harvesting crops with timed actions. What we wanted was for every merge to the `main` Git branch to initiate a release to https://rainbowcow-studio.itch.io/farmhand-go, where the game lives and can be played. We also wanted our Discord channel to be automatically notified of the new release as soon as it's available.

With a little elbow grease, we came up with this GitHub Action that does all of this for us:

{% gist https://gist.github.com/jeremyckahn/bcfe074d774b2e75ad990fcb30c7a410 %}

The rest of this article will discuss how we got this set up, and how you can have something similar for your Godot games!

## Prerequisites

In order to set up this automation, you will need your GitHub repo and itch.io page already published. If you want the optional Discord notification functionality, you will need to have your server and relevant channel set up as well.

## Setting it up

In the Git repo, your Godot project needs to have an `export_presets.cfg` file at its root. In Farmhand Go!, the actual Godot project is at `./project` rather than the repo root, but your setup may vary. Be sure that `export_presets.cfg` is not in your `.gitignore` ([it is by default](https://github.com/godotengine/godot-demo-projects/issues/329)), or that it is [at least present for when the actual Godot export occurs](https://github.com/godotengine/godot-demo-projects/issues/329#issuecomment-763625011). This is what our committed `export_presets.cfg` looks like:

{% gist https://gist.github.com/jeremyckahn/4f9278a30514577598e6e64f86d33fbe %}

Once that's set up, you'll need your modified version of the YAML file from above. Here's a more generic version you can use: https://gist.github.com/jeremyckahn/ff4f0e409f089ec36bdecb5a5adb6819. You'll just need to replace the following stubbed values:

  - `NAME-OF-YOUR-GAME`
  - `NAME-OF-YOUR-USER`

These occur in a few places in this file, so I recommend using your editor's Find and Replace feature and carefully reviewing the changes. Move this file to your repo's `.github/workflows/` directory, and name it whatever you'd like. For Farmhand Go!, it's `.github/workflows/deploy.yml`.

As written, this automation will run whenever a commit is pushed, either directly or via Pull Request merge, to the `main` branch. If you want to use a different branch for this automation, change the `branches` value towards the top of the file.

Once that's in place, you will need an API key for itch.io and optionally a webhook URL for Discord. 

### The itch.io API key

To create your itch.io API key, go to your settings in itch.io:

![Itch.io API key creation step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sh92k0lqgxc9l2nk8mih.png)

Then, in the left-hand nav, go to "API keys"

![Itch.io API key creation step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txcgrcu3jdvqlelc28x5.png)

Input your password, and then click "Generate new API key." You should now have a screen that looks something like this:

![Itch.io API key creation step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x68qg21274s814t5mam8.png)

And you're done here! Copy the new key and head over to the Settings page for your game's GitHub repo and click on "Secrets" in the left-hand nav:

![GitHub secret creation step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a65fd6ia1l9ruipt2zqz.png)

From here, click "New Repository Secret." For "Name," put `BUTLER_API_KEY`. For the value, paste in the key that you copied from itch.io. Click "Add secret," and you should now have a screen that looks something like this:

![GitHub secret creation step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8kvxaoswm8i6c5b0fra.png)

### The Discord webhook URL (optional)

In your Discord server, go to "Server Settings":

![Discord webhook creation step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyd47uh1rwa5or451lb1.png)

In the left-hand nav, click "Integrations":

![Discord webhook creation step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpsytypaho9m7ygy5dfb.png)

Click "Webhooks:"

![Discord webhook creation step 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3ciue0a0pkuq7a5j4oh.png)

Click "New Webhook" and fill out the form appropriately. Here's how ours looks:

![Discord webhook creation step 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hix1lhvd4y3gdlwxefm.png)

Click "Copy Webhook" to copy the URL to your clipboard, and then "Save Changes" at the bottom. We're done here!

Flip back to your GitHub repo's Secrets page, and create a new secret named `DISCORD_WEBHOOK` with the webhook URL from Discord as the value. Your Secrets page should now look like this:

![GitHub secret creation step 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfqx36cf7udxizjods9t.png)

Now that all the necessary GitHub secrets are in place, all that's left to do is commit `.github/workflows/deploy.yml` to your `main` branch via PR. Starting with this commit and going forward on the `main` branch, all commits will trigger a GitHub Action that deploys your web game to itch.io and notifies your community of the new release:

![Successful release deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhbo959wcuu69h80tls0.png)

![Successful release notification](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9qltc4qi56x2awq48iy.png)

And that's it! You can customize this workflow to your liking, perhaps by changing the Discord messaging or adding additional build targets. For the latter, I recommend looking at the Action that I learned from in order to see how to support Linux, Mac, and Windows builds: https://github.com/RudyMis/Bubbles/blob/master/.github/workflows/godot-ci.yml

What do you think? How do you think this automation could be improved? Please share your thoughts in the comments. Thanks for reading, and have fun with developing your Godot games!