Friday, September 29, 2023

Automatically publishing Godot 4.1 projects to GitHub.io

Some time ago, I wrote a blog post and made a video about how to automate the publishing of web-based Godot games on GitHub.io. It worked fine in 3.x, but with the release of 4.x, things got complicated because of SharedArrayBuffer. I have come across some tips online that claim to solve the problem, but I was unable to get any of them working entirely as advertised. After some effort last night, I've been able to pull all the pieces together into this GitHub workflow configuration:

Briefly, this makes use of barichello's godot-ci Docker container to build the web export for the game, then it brings in gzuidhof's service worker to provide the secure context necessary for SharedArrayBuffers. Deployment to GitHub pages is conveniently managed via peaceiris' actions-gh-pages.

Here is what you need to make this work:

  • The script assumes you have a "project" folder at the root of your repository, and that your Godot project and its corresponding project.godot file are there.
  • You need to have configured HTML5 export and called it "Web," which is the default. Set the export to go to the path "build/web/index.html" off of the repository root. That is, within the export settings, the export path will be "../build/web/index.html".
  • Make sure your export configuration (export_presets.cfg) is in the repository. That is the default for Godot 4, but you'll find some sample .gitignore configurations that want to hide that file.
  • Your repository must be public.
  • You have to enable GitHub Pages in your repository. In the corresponding section of the GitHub repository settings, make sure your source for the pages is to "Deploy from a branch" and that the branch you select is "gh-pages."
I was blindsided by the HTML5 export complications when trying to build a web version of my last Ludum Dare game. I'm hopeful that this new configuration will make my deployment easier for Ludum Dare 54, which starts tonight.

UPDATE: Although I did not complete an LD54 project, I did get far enough to set up GitHub automation. I ran into a problem Saturday that I did not see on Thursday, which was the need for the build system to be able to write to the repository. It comes up in peaceiris' gh-pages documentation, and the fix is a one-liner: the addition of a permissions statement. I have updated the gist above to include this.

No comments:

Post a Comment