Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 67 additions & 0 deletions .github/actions/godot-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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 }}
87 changes: 87 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# 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_v9.3.0" >> "$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/v9.3.0.zip -P ${{ inputs.gut-download-path }}
unzip ${{ inputs.gut-download-path }}/v9.3.0.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-9.3.0/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 Import"
if: ${{ runner.OS == 'Linux'}} && ${{ !cancelled() }}
env:
TEST_PROJECT: ${{ inputs.godot-test-project }}
shell: bash
run: |
cd "${TEST_PROJECT}"
chmod +x run_import.sh
./run_import.sh "$HOME/godot-linux/godot"
- 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 4.3"
uses: ./.github/workflows/tests.yml
with:
godot-version: "4.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: "4.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.x86_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
11 changes: 11 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.godot/
*.import
addons/
icon.png

# 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":""
}
8 changes: 8 additions & 0 deletions test/TestRunner.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_scene format=3 uid="uid://dkea2wjvdowwf"]

[node name="TestRunner" type="Control"]
custom_minimum_size = Vector2(740, 250)
layout_mode = 3
anchors_preset = 0
offset_right = 740.0
offset_bottom = 250.0
20 changes: 6 additions & 14 deletions test/Unit/test_mod_hook_preprocessor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func test_get_closing_paren_index(params: Array = use_parameters(test_get_closin


var test_match_func_with_whitespace_params = [
["abc", FUNCTIONS_SAMPLE1, 0, ["func abc(", 0, 9]],
["test", FUNCTIONS_SAMPLE1, 0, ["func test(", 19, 29]],
["_ready", FUNCTIONS_SAMPLE2, 0, ["func _ready(", 70, 82]],
["_on_hit_detector_body_entered", FUNCTIONS_SAMPLE2, 0, ["func _on_hit_detector_body_entered(", 155, 190]],
["abc", FUNCTIONS_SAMPLE1, 0, ["func abc("]],
["test", FUNCTIONS_SAMPLE1, 0, ["func test("]],
["_ready", FUNCTIONS_SAMPLE2, 0, ["func _ready("]],
["_on_hit_detector_body_entered", FUNCTIONS_SAMPLE2, 0, ["func _on_hit_detector_body_entered("]],
]

const FUNCTIONS_SAMPLE1 := """\
Expand Down Expand Up @@ -69,15 +69,15 @@ func _on_hit_detector_body_entered(body: Node3D) -> void:
Global.reset_game()
"""


# We can't (easily) test for start and end indices due to different line endings between Windows and Linux.
func test_match_func_with_whitespace(params: Array = use_parameters(test_match_func_with_whitespace_params)) -> void:
# prepare
var method_name: String = params[0]
var text: String = params[1]
var offset: int = params[2]

var expected_string: String = params.back()[0]
var expected_start: int = params.back()[1]
var expected_end: int = params.back()[2]

# test
var result := _ModLoaderModHookPreProcessor.match_func_with_whitespace(method_name, text, offset)
Expand All @@ -89,11 +89,3 @@ func test_match_func_with_whitespace(params: Array = use_parameters(test_match_f
result.get_string(), expected_string,
"expected %s, got %s" % [expected_string, result.get_string()]
)
assert_eq(
result.get_start(), expected_start,
"expected %s, got %s" % [expected_start, result.get_start()]
)
assert_eq(
result.get_end(), expected_end,
"expected %s, got %s" % [expected_end, result.get_end()]
)
30 changes: 30 additions & 0 deletions test/Unit/test_script_extension_sorting.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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"
#]

# https://github.com/GodotModding/godot-mod-loader/pull/357
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"
]

_ModLoaderScriptExtension.InheritanceSorting.new(extension_paths)

assert_true(extension_paths == order_after_357_correct, "Expected %s but was %s instead" % [JSON.stringify(order_after_357_correct, "\t"), JSON.stringify(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=3 uid="uid://dhpbuhssb7uh"]

[sub_resource type="Sky" id="1"]

[resource]
background_mode = 2
sky = SubResource("1")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends "res://script_extension_sorting/script_c.gd"
Loading