CI

Roblox CI Test

This is an example of a Roblox project that uses TestEZ for unit testing and Selene for linting. A GitHub action is run to automatically run linting and unit tests. See the .github/workflows/ci.yaml file for the GitHub action declaration.

Project Structure

  • src/ - Contains all the source code for the game
  • test/ - Contains all unit tests
  • Packages/ - Dependencies installed from Wally (only generated after running wally install)
  • ci.lua - Used by the CI process to run the tests (will be run in the context of a Roblox plugin)
  • default.project.json - Rojo configuration
  • foreman.toml - Foreman configuration
  • selene.toml - Selene configuration
  • roblox.toml - Generated by Selene
  • testez.toml - Add Selene rules for TestEZ
  • wally.toml - Project dependencies

CI Process

Install Roblox Studio

Roblox Studio is needed in order to run the TestEZ unit tests. The roblox-win-installer-action is used to run this installation process. The GitHub repo must have a ROBLOSECURITY secret assigned in order for this to work properly. Due to the high security risk of such a token, it is recommended that a burner account is created for this token.

Install Foreman

Foreman is a toolchain manager for Roblox development. With Foreman, other build dependencies can be installed, which can also be seen in the foreman.toml file:

Install Dependencies via Wally

The wally install command is run to install all dependencies listed in the wally.toml file. These are placed into the Packages directory at the project root level.

Build Place File

In order for unit testing to take place via TestEZ, a Roblox place file needs to be generated with our main code and tests. The rojo build command is utilized to create this file, which will then be used by the run-in-roblox tool.

Run Unit Tests

Once the place file is generated, unit tests are run using run-in-roblox. The ci.lua script is passed to the tool. This works by opening up Roblox Studio and running the ci.lua script in the context of a plugin. Any output generated by the process (e.g. calls to print) are returned by the tool and can be written to a file. In this example, results are written to test-out.txt.

The test-out.txt file is searched to look for "0 failed, 0 skipped", which would indicate that TestEZ succeeded. If so, the process exits successfully. Otherwise, the process will fail and the GitHub action will be shown in a failure state. In the case of a test failure, the test-out.txt file will be outputted within the logs of the GitHub action at this stage.

Linting

Linting is done with Selene against the src directory.

Linting should only be done against code written for the project, hence why Selene is not run against the whole project directory. Running the linter against vendor code (e.g. dependencies installed from Wally) could result in linting errors that don't pertain to the project.