Skip to content

ci: GUT Test GitHub Action #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/actions/godot-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Inspired by https://github.com/bitbrain/beehave/blob/godot-4.x/.github/actions/godot-install/action.yml

name: install-godot-binary
description: "Installs the Godot Runtime"

inputs:
godot-version:
description: "The Godot engine version"
type: string
required: true
godot-status-version:
description: "The Godot engine status version"
type: string
required: true
godot-bin-name:
type: string
required: true
godot-cache-path:
type: string
required: true


runs:
using: composite
steps:

- name: "Set Cache Name"
shell: bash
run: |
echo "CACHE_NAME=${{ runner.OS }}-Godot_v${{ inputs.godot-version }}-${{ inputs.godot-status-version }}" >> "$GITHUB_ENV"

- name: "Godot Cache Restore"
uses: actions/cache/restore@v3
id: godot-restore-cache
with:
path: ${{ inputs.godot-cache-path }}
key: ${{ env.CACHE_NAME }}

- name: "Download and Install Godot ${{ inputs.godot-version }}"
if: steps.godot-restore-cache.outputs.cache-hit != 'true'
continue-on-error: false
shell: bash
run: |
mkdir -p ${{ inputs.godot-cache-path }}
chmod 770 ${{ inputs.godot-cache-path }}
DIR="$HOME/.config/godot"
if [ ! -d "$DIR" ]; then
mkdir -p "$DIR"
chmod 770 "$DIR"
fi

DOWNLOAD_URL=https://github.com/godotengine/godot/releases/download/${{ inputs.godot-version }}-${{ inputs.godot-status-version }}
GODOT_BIN=Godot_v${{ inputs.godot-version }}-${{ inputs.godot-status-version }}_${{ inputs.godot-bin-name }}

GODOT_PACKAGE=$GODOT_BIN.zip
wget $DOWNLOAD_URL/$GODOT_PACKAGE -P ${{ inputs.godot-cache-path }}
unzip ${{ inputs.godot-cache-path }}/$GODOT_PACKAGE -d ${{ inputs.godot-cache-path }}

mv ${{ inputs.godot-cache-path }}/$GODOT_BIN ${{ inputs.godot-cache-path }}/godot

chmod u+x ${{ inputs.godot-cache-path }}/godot
echo "${{ inputs.godot-cache-path }}/godot"

- name: "Godot Cache Save"
if: steps.godot-restore-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: ${{ inputs.godot-cache-path }}
key: ${{ steps.godot-restore-cache.outputs.cache-primary-key }}
80 changes: 80 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Inspired by https://github.com/utopia-rise/fmod-gdextension/blob/godot-3.x/demo/run_tests.sh

name: test
description: "Runs the tests via GUT CLI"

inputs:
gut-download-path:
required: true
default: ~/gut_download
gut-addons-path:
required: true
default: ${{ github.workspace }}/test/addons/gut
godot-test-project:
required: true
default: ${{ github.workspace }}/test

runs:
using: composite

steps:

- name: "Set Cache Name"
shell: bash
run: |
echo "CACHE_NAME_GUT=GUT_v7.4.1" >> "$GITHUB_ENV"

- name: "GUT Cache Restore"
uses: actions/cache/restore@v3
id: gut-restore-cache
with:
path: ${{ inputs.gut-download-path }}
key: ${{ runner.os }}-${{ env.CACHE_NAME_GUT }}

- name: "Download GUT"
if: steps.gut-restore-cache.outputs.cache-hit != 'true'
continue-on-error: false
shell: bash
run: |
mkdir -p ${{ inputs.gut-download-path }}
chmod 770 ${{ inputs.gut-download-path }}

wget https://github.com/bitwes/Gut/archive/refs/tags/v7.4.1.zip -P ${{ inputs.gut-download-path }}
unzip ${{ inputs.gut-download-path }}/v7.4.1.zip -d ${{ inputs.gut-download-path }}/unzip

- name: "GUT Cache Save"
if: steps.gut-restore-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: ${{ inputs.gut-download-path }}
key: ${{ steps.gut-restore-cache.outputs.cache-primary-key }}

- name: "Create addons Directory"
if: ${{ !cancelled() }}
shell: bash
run: mkdir -p ${{ github.workspace }}/test/addons

- name: "⚔ Link GUT"
if: ${{ !cancelled() }}
shell: bash
run: ln -s ${{ inputs.gut-download-path }}/unzip/Gut-7.4.1/addons/gut ${{ github.workspace }}/test/addons/gut

- name: "⚔ Link Mod Loader"
if: ${{ !cancelled() }}
shell: bash
run: ln -s ${{ github.workspace }}/addons/mod_loader ${{ github.workspace }}/test/addons/mod_loader

- name: "⚔ Link JSON_Schema_Validator"
if: ${{ !cancelled() }}
shell: bash
run: ln -s ${{ github.workspace }}/addons/JSON_Schema_Validator ${{ github.workspace }}/test/addons/JSON_Schema_Validator

- name: "Run Tests"
if: ${{ runner.OS == 'Linux'}} && ${{ !cancelled() }}
env:
TEST_PROJECT: ${{ inputs.godot-test-project }}
shell: bash
run: |
cd "${TEST_PROJECT}"
chmod +x run_tests.sh
./run_tests.sh "$HOME/godot-linux/godot"
30 changes: 29 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
on: [pull_request]
# Inspired by https://github.com/bitbrain/beehave/blob/godot-4.x/.github/workflows/beehave-ci.yml

name: Mod Loader CI

on:
push:
paths-ignore:
- '**.jpg'
- '**.png'
- '**.svg'
- '**.md'
- '**plugin.cfg'
pull_request:
paths-ignore:
- '**.jpg'
- '**.png'
- '**.svg'
- '**.md'
- '**plugin.cfg'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check_dependencies:
runs-on: ubuntu-latest
Expand All @@ -7,3 +30,8 @@ jobs:
- uses: gregsdennis/dependencies-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tests:
name: "Running GUT tests on Godot 3.5.3"
uses: ./.github/workflows/tests.yml
with:
godot-version: '3.5.3'
58 changes: 58 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Inspired by https://github.com/bitbrain/beehave/blob/godot-4.x/.github/workflows/unit-tests.yml

name: tests
run-name: ${{ github.head_ref || github.ref_name }}-tests

on:
workflow_call:
inputs:
os:
required: false
type: string
default: 'ubuntu-22.04'
godot-version:
required: true
type: string
default: '3.5.3'

workflow_dispatch:
inputs:
os:
required: false
type: string
default: 'ubuntu-22.04'
godot-version:
required: true
type: string

concurrency:
group: tests-${{ github.head_ref || github.ref_name }}-${{ inputs.godot-version }}
cancel-in-progress: true

jobs:
test:
name: "Tests"
runs-on: ${{ inputs.os }}
timeout-minutes: 15

steps:
- name: "📦 Checkout Mod Loader Repository"
uses: actions/checkout@v4
with:
lfs: true
submodules: 'recursive'

- name: "🤖 Install Godot ${{ inputs.godot-version }}"
uses: ./.github/actions/godot-install
with:
godot-version: ${{ inputs.godot-version }}
godot-status-version: 'stable'
godot-bin-name: 'linux_headless.64'
godot-cache-path: '~/godot-linux'

- name: "🧪 Run Tests"
if: ${{ !cancelled() }}
timeout-minutes: 4
uses: ./.github/actions/test
with:
godot-test-project: ${{ github.workspace }}/test
10 changes: 10 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.import/
*.import
addons/

# Gut stuff in root dir
asset_lib_icon.png
gut_panel.png
.gut_editor_shortcuts.cfg
BigFont.tres
BigFontTheme.tres
16 changes: 16 additions & 0 deletions test/.gutconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dirs":["res://Unit/"],
"double_strategy":"partial",
"ignore_pause":false,
"include_subdirs":true,
"inner_class":"",
"log_level":3,
"opacity":100,
"prefix":"test_",
"selected":"",
"should_exit":true,
"should_maximize":true,
"suffix":".gd",
"tests":[],
"unit_test_name":""
}
10 changes: 10 additions & 0 deletions test/TestRunner.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://addons/gut/plugin_control.gd" type="Script" id=1]

[node name="TestRunner" type="Control"]
margin_right = 740.0
margin_bottom = 250.0
rect_min_size = Vector2( 740, 250 )
script = ExtResource( 1 )
_directory1 = "res://Unit"
29 changes: 29 additions & 0 deletions test/Unit/test_script_extension_sorting.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extends GutTest


#var order_before_357_correct := [
# "res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_b.gd",
# "res://mods-unpacked/test-mod2/extensions/script_extension_sorting/script_c.gd",
# "res://mods-unpacked/test-mod1/extensions/script_extension_sorting/script_c.gd",
# "res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_d.gd"
#]

var order_after_357_correct := [
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_b.gd",
"res://mods-unpacked/test-mod1/extensions/script_extension_sorting/script_c.gd",
"res://mods-unpacked/test-mod2/extensions/script_extension_sorting/script_c.gd",
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_d.gd"
]


func test_handle_script_extensions():
var extension_paths := [
"res://mods-unpacked/test-mod1/extensions/script_extension_sorting/script_c.gd",
"res://mods-unpacked/test-mod2/extensions/script_extension_sorting/script_c.gd",
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_b.gd",
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_d.gd"
]

extension_paths.sort_custom(_ModLoaderScriptExtension.InheritanceSorting.new(), "_check_inheritances")

assert_true(extension_paths == order_after_357_correct, "Expected %s but was %s instead" % [JSON.print(order_after_357_correct, "\t"), JSON.print(extension_paths, "\t")])
7 changes: 7 additions & 0 deletions test/default_env.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]

[sub_resource type="ProceduralSky" id=1]

[resource]
background_mode = 2
background_sky = SubResource( 1 )
Binary file added test/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends "res://script_extension_sorting/script_c.gd"
40 changes: 40 additions & 0 deletions test/mods-unpacked/test-mod1/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "mod1",
"namespace": "test",
"version_number": "0.0.1",
"description": "Description of your mod...",
"website_url": "https://github.com/exampleauthor/examplemod",
"dependencies": [

],
"extra": {
"godot": {
"authors": [
"AuthorName"
],
"optional_dependencies": [

],
"compatible_game_version": [
"0.0.1"
],
"compatible_mod_loader_version": [
"6.1.0"
],
"incompatibilities": [

],
"load_before": [

],
"tags": [

],
"config_schema": {

},
"description_rich": "",
"image": null
}
}
}
Loading