croconut / godot-tester

A Github Action to handle testing Godot applications with GUT
MIT License
36 stars 14 forks source link

Support Godot 4 w/ 3.x compatibility #27

Closed RGonzalezTech closed 1 year ago

RGonzalezTech commented 1 year ago

Summary

I added another tester godot project that uses Godot 4.0.3 and GUT 9.0.1 & I renamed the existing tester to tester_GUT_v7.4.1 so that we can open the right project depending on the Godot version.

I refactored the code to make heavy use of functions so that we can easily locate & isolate the behavior that needs version-handling logic.

The download URL and headless behavior changed in Godot v4. We no longer need to download a binary compiled to run headlessly, we simply append --headless to the executable args.

Also, the architecture suffix changed from _64 to _x86_64 or .64 to .x86_64

Luckily, the GUT command line interface and results XML did not change.

Details

I used the following function to determine whether this version is greater than v3:

check_godot_version() {
    local version=$GODOT_VERSION
    local version_three=3

    # Remove the leading 'v' character if present
    version=${version#v}

    # Extract the major version number from the version string
    local current_version=$(echo "$version" | cut -d. -f1)

    if [ "$current_version" -gt "$version_three" ]; then
        # v4+ behavior
        IS_VERSION_FOUR=1
    fi
}

It updates a global "boolean" called IS_VERSION_FOUR.

Downloading Godot

The download filename changed slightly. That URL is generated in the generate_dl_url function. You can see the change below:

generate_dl_url_three() {
    echo "generating download url ...v3"

    if [ "$IS_MONO" = "true" ]; then
        FULL_GODOT_NAME="${FULL_GODOT_NAME}_mono_linux_headless"
        FULL_GODOT_NAME_EXT="${FULL_GODOT_NAME}_64"
    else
        FULL_GODOT_NAME="${FULL_GODOT_NAME}_linux_headless"
        FULL_GODOT_NAME_EXT="${FULL_GODOT_NAME}.64"
    fi
}

generate_dl_url_four() {
    echo "generating download url ...v4"

    if [ "$IS_MONO" = "true" ]; then
        FULL_GODOT_NAME="${FULL_GODOT_NAME}_mono_linux"
        FULL_GODOT_NAME_EXT="${FULL_GODOT_NAME}_x86_64"
    else
        FULL_GODOT_NAME="${FULL_GODOT_NAME}_linux"
        FULL_GODOT_NAME_EXT="${FULL_GODOT_NAME}.x86_64"
    fi
}

generate_dl_url() {
    if [ "$RELEASE_TYPE" = "stable" ]; then
        GODOT_URL_PATH_SUBDIR=""
    else
        # if not stable, then it's a release candidate or beta
        # Those are located in a subdirectory of the release type
        # example: /beta1, /rc1, etc.
        GODOT_URL_PATH_SUBDIR="/${RELEASE_TYPE}"
    fi
    # This is the path to the godot version hosted on tuxfamily
    # example: 3.2.3/, 3.2.3/beta1/, etc.
    GODOT_URL_PATH="${GODOT_VERSION}${GODOT_URL_PATH_SUBDIR}/"

    if [ "$IS_MONO" = "true" ]; then
        # mono builds are in a subdirectory of the godot version
        # example: 3.2.3/mono/, 3.2.3/beta1/mono/, etc.
        GODOT_URL_PATH="${GODOT_URL_PATH}mono/"
    fi

    FULL_GODOT_NAME="Godot_v${GODOT_VERSION}-${RELEASE_TYPE}"
    # Different behavior for v4+ and v3
    if [[ "$IS_VERSION_FOUR" -eq "1" ]]; then
        generate_dl_url_four
    else
        generate_dl_url_three
    fi

    # Apply the generated path & name to the download url
    DL_URL="https://downloads.tuxfamily.org/godotengine/${GODOT_URL_PATH}${FULL_GODOT_NAME_EXT}.zip"

    if [ "$CUSTOM_GODOT_DL_URL" != "" ]; then
        DL_URL="$CUSTOM_GODOT_DL_URL"
    fi
}

Generate Run Options

Godot v4 no longer has a headless build, you can simply add the --headless argument to the regular linux executable and it will run headlessly. This is accounted for in the generate_run_options function, where we append --headless to the run options if we're on v4+

    if [ "$IS_VERSION_FOUR" -eq "1" ]; then
        # v4+ behavior
        # you must use the --headless argument 
        # rather than use a headless binary
        RUN_OPTIONS="${RUN_OPTIONS} --headless"
    fi

Test Running & Analysis

While the code has been refactored to make heavier use of functions, the actual behavior hasn't changed.

Version Bump

I changed the README a bit with more relevant information and bumped the action to v4

Relevant issues

26 #25

RGonzalezTech commented 1 year ago

I'm going to sleep for the night 😴 I'll review tomorrow morning

croconut commented 1 year ago

@RGonzalezTech let's update the actions to run the test workflow on PR / commit to PR

RGonzalezTech commented 1 year ago

Summary

Refactored the code a bit. Due to the complexity of the download step & assert-check logic, I extracted those into functions and then I moved some of the less complex behaviors into functions as well to follow the SLAP principle.

I understand the point, though. I noticed that I wasn't following the principle in the generate_dl_url function, so I flattened that one out in 5e70a57e3c06a85f015184e249da1ea89c670a21. I also cleaned up the download_godot and run_tests to better implement the SLAP principle. 47591bcfdcca5a93a3be7b8ad39bb13cb3053228

I also removed some older behavior in 068fd8ed059477e2163f86fbca26225815f6a538.

Now, we're running into an issue with the imports.

Importing Process Troubleshooting

Since I've removed the .godot/ folder from tester_GUT_v9.0.1, the runs now fail. I've been trying to debug this in:

Not sure how to get it to rebuild the .godot/ folder.

EDIT: looks like the import timeout of 1s might be too short now.

RGonzalezTech commented 1 year ago

Fixed the .godot/ import issue. Had to increase the import timeout.

croconut commented 1 year ago

@RGonzalezTech please merge + release when you're ready, LGTM :)

I'd recommend mentioning in release notes the deprecated argument and the default import time change