Skip to content
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

GD-26: Use gdunit4.test.adapter to run C# tests #34

Merged
merged 22 commits into from
Apr 28, 2024
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
39 changes: 39 additions & 0 deletions .gdunit4_action/.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<MaxCpuCount>1</MaxCpuCount>
<ResultsDirectory>./TestResults</ResultsDirectory>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TestSessionTimeout>180000</TestSessionTimeout>
<TreatNoTestsAsError>true</TreatNoTestsAsError>
</RunConfiguration>

<LoggerRunSettings>
<Loggers>
<Logger friendlyName="console" enabled="True">
<Configuration>
<Verbosity>detailed</Verbosity>
</Configuration>
</Logger>
<Logger friendlyName="html" enabled="True">
<Configuration>
<LogFileName>test-result.html</LogFileName>
</Configuration>
</Logger>
<Logger friendlyName="trx" enabled="True">
<Configuration>
<LogFileName>test-result.trx</LogFileName>
</Configuration>
</Logger>
</Loggers>
</LoggerRunSettings>

<GdUnit4>
<!-- Additonal Godot runtime parameters-->
<!-- These parameters are crucial for configuring the Godot runtime to work in headless environments, such as those used in automated testing or CI/CD pipelines.-->
<Parameters>--audio-driver Dummy --display-driver x11 --rendering-driver opengl3 --screen 0 --verbose</Parameters>
<!-- Controlls the Display name attribute of the TestCase. Allowed values are SimpleName and FullyQualifiedName.
This likely determines how the test names are displayed in the test results.-->
<DisplayName>FullyQualifiedName</DisplayName>
</GdUnit4>
</RunSettings>
2 changes: 1 addition & 1 deletion .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: false
max-parallel: 10
matrix:
godot-version: ['4.1.3', '4.2', '4.2.1']
godot-version: ['4.1.3', '4.2', '4.2.1', '4.2.2']
godot-status: ['stable']
godot-net: ['', '.Net']
version: ['master', 'latest', 'v4.2.0']
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/resources/test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</PropertyGroup>
<ItemGroup>
<!--Required for GdUnit4-->
<PackageReference Include="gdUnit4.api" Version="4.2.0-rc*" />
<PackageReference Include="gdUnit4.api" Version="4.2.*" />
</ItemGroup>
</Project>
</Project>
40 changes: 33 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,24 @@ runs:
echo -e "\e[34m -----------------\e[0m"

- name: 'Restore .Net Project'
if: ${{ !cancelled() }}
if: ${{ !cancelled() && inputs.godot-net == 'true' }}
shell: bash
run: |
if ${{ inputs.godot-net == 'true' }}; then
cd "${{ inputs.project_dir }}"
dotnet restore
dotnet build
cd "${{ inputs.project_dir }}"
# install required packages
dotnet add package Microsoft.NET.Test.Sdk
# for gdunit version less than 4.2.2 we need to load api version 4.2.1.1
gdUnitVersion=$(echo "${{ inputs.version }}" | sed 's/^v//; s/\.//g')
if [[ ${gdUnitVersion} < 422 ]]; then
echo "gdUnit4 version ${gdUnitVersion} less 4.2.2, update project to gdUnit4.api v4.2.1"
dotnet add package gdUnit4.api --version 4.2.1
dotnet add package gdUnit4.test.adapter --version 1.0.0
else
dotnet add package gdUnit4.api
dotnet add package gdUnit4.test.adapter
fi
dotnet restore
dotnet build

- name: 'Restore Godot project cache'
if: ${{ !cancelled() }}
Expand All @@ -153,8 +163,8 @@ runs:
$GODOT_BIN --path ./ -e --headless --quit-after 2000
echo -e "\e[94mProject cache successfully restored.\e[0m"

- name: 'Run Tests'
if: ${{ !cancelled() }}
- name: 'Run GDScript Tests'
if: ${{ !cancelled() && inputs.godot-net == 'false' }}
env:
GODOT_BIN: '/home/runner/godot-linux/godot'
uses: actions/github-script@v7
Expand All @@ -170,6 +180,22 @@ runs:
};
await runTests(args, core);

- name: 'Run C# Tests'
if: ${{ !cancelled() && inputs.godot-net == 'true' }}
env:
GODOT_BIN: '/home/runner/godot-linux/godot'
shell: bash
run: |
cd "${{ inputs.project_dir }}"
MikeSchulze marked this conversation as resolved.
Show resolved Hide resolved
# test if a .runsettings file exists, if not use the action provided default .runsettings
if [ -f .runsettings ]; then
echo "Found `.runsettings` file."
else
echo "No project specific '.runsettings' found, using action default '.runsettings'"
cp $GITHUB_ACTION_PATH/.gdunit4_action/.runsettings .
fi
xvfb-run --auto-servernum dotnet test --no-build --settings .runsettings --results-directory ./reports --logger "trx;LogFileName=results.xml"

- name: 'Publish Unit Test Reports'
if: ${{ !cancelled() && inputs.publish-report == 'true' }}
uses: ./.gdunit4_action/publish-test-report
Expand Down