Skip to content

Commit 007ee8e

Browse files
committed
v2.4.1 release
1 parent 789df19 commit 007ee8e

File tree

20 files changed

+182
-343
lines changed

20 files changed

+182
-343
lines changed

.github/actions/test-execute-test/action.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ runs:
4747
$run_settings_args = 'NUnit.DefaultTestNamePattern="{C}:{m}{a}" RunConfiguration.TargetPlatform=${{inputs.architecture}}';
4848
"run_settings_args=$run_settings_args" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
4949
50-
$vstest = "--logger:trx --logger:'console;verbosity=normal' --blame";
51-
"vstest=$vstest" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
52-
53-
$dotnet = "-l trx -l 'console;verbosity=normal' --blame";
54-
"dotnet=$dotnet" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
55-
5650
$target_framework = "${{inputs.target_framework}}";
5751
$target_frameworks = "${{inputs.target_framework_array}}";
5852
if ($target_frameworks -eq '') {
@@ -61,36 +55,53 @@ runs:
6155
"target_frameworks=$target_frameworks" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
6256
shell: pwsh
6357

58+
- name: Clean TestResults (Windows)
59+
if: runner.os == 'Windows'
60+
run: |
61+
if (Test-Path "TestResults") {
62+
Remove-Item -Path "TestResults" -Recurse -Force
63+
}
64+
New-Item -Path "TestResults" -ItemType Directory
65+
shell: pwsh
66+
67+
- name: Clean TestResults (Unix)
68+
if: runner.os != 'Windows'
69+
run: |
70+
rm -rf TestResults
71+
mkdir -p TestResults
72+
shell: bash
73+
6474
- name: Build if required
6575
if: ${{inputs.manual_build == 'true'}}
6676
run: |
6777
foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
68-
dotnet build HarmonyTests/HarmonyTests.csproj -c ${{inputs.build_configuration}} -f $target_framework;
78+
dotnet build HarmonyTests/HarmonyTests.csproj -c ${{inputs.build_configuration}} -f $target_framework
6979
}
7080
shell: pwsh
7181

7282
- name: Perform Tests Windows FX/Mono
7383
if: ${{inputs.os == 'windows' && (inputs.runtime-type == 'fx' || inputs.runtime-type == 'mono')}}
7484
run: |
75-
$mono = "${{steps.get-program-files.outputs.path}}/Mono/bin/mono.exe";
85+
$mono = "${{steps.get-program-files.outputs.path}}/Mono/bin/mono.exe"
7686
77-
$vspath = vswhere -latest -property installationPath;
78-
$vstest = join-path $vspath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe";
87+
$vspath = vswhere -latest -property installationPath
88+
$vstest = join-path $vspath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
7989
8090
foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
81-
& ${{(inputs.runtime-type == 'mono' && '"$mono"') || ''}} "$vstest" "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" --framework:$target_framework ${{steps.test-args.outputs.vstest}} -- ${{steps.test-args.outputs.run_settings_args}};
91+
$trxFileName = "${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
92+
& ${{(inputs.runtime-type == 'mono' && '"$mono"') || ''}} "$vstest" "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" --framework:$target_framework --logger:"trx;LogFileName=../TestResults/$trxFileName" --logger:"console;verbosity=normal" --blame -- ${{steps.test-args.outputs.run_settings_args}}
8293
}
8394
shell: pwsh
8495

8596
- name: Perform Tests Windows .NET | Ubuntu .NET/Mono
8697
if: ${{(inputs.os == 'windows' && inputs.runtime-type == 'dotnet') || inputs.os == 'ubuntu'}}
8798
run: |
8899
foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
89-
dotnet test "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" -f $target_framework ${{steps.test-args.outputs.dotnet}} -- ${{steps.test-args.outputs.run_settings_args}};
100+
$trxFileName = "${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
101+
dotnet test "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" -f $target_framework --logger:"trx;LogFileName=../TestResults/$trxFileName" --logger:"console;verbosity=normal" -- ${{steps.test-args.outputs.run_settings_args}}
90102
}
91103
shell: pwsh
92104

93-
# Not sure if continue_on_error: true is needed
94105
- name: Perform Tests MacOS/MacOS-arm64 .NET/Mono
95106
uses: nick-fields/retry@v3
96107
if: ${{inputs.os == 'macos' || inputs.os == 'macos-arm64'}}
@@ -100,12 +111,13 @@ runs:
100111
retry_on: timeout
101112
command: |
102113
if ('${{inputs.os == 'macos-arm64' && inputs.architecture == 'x64' && inputs.runtime-type == 'dotnet'}}' -eq 'true') {
103-
$dotnet = '/Users/runner/.dotnet/x64/dotnet';
114+
$dotnet = '/Users/runner/.dotnet/x64/dotnet'
104115
} else {
105-
$dotnet = '/Users/runner/.dotnet/dotnet';
116+
$dotnet = '/Users/runner/.dotnet/dotnet'
106117
}
107118
foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
108-
& $dotnet test "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" -f $target_framework ${{steps.test-args.outputs.dotnet}} -- ${{steps.test-args.outputs.run_settings_args}};
119+
$trxFileName = "${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
120+
& $dotnet test "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" -f $target_framework --logger:"trx;LogFileName=../TestResults/$trxFileName" --logger:"console;verbosity=normal" -- ${{steps.test-args.outputs.run_settings_args}}
109121
}
110122
shell: pwsh
111123

.github/actions/test-upload-result/action.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@ inputs:
2020
experimental:
2121
description: 'Whether the tests are mandatory for the build to pass'
2222
required: true
23-
#type: boolean # We don't have boolean types in composites https://github.com/actions/runner/issues/2238
2423

2524
runs:
2625
using: "composite"
2726
steps:
28-
- name: Clean TRX files
29-
run: python3 scripts/clean-trx-files.py
30-
shell: bash
31-
if: ${{success() || failure()}}
3227
- name: Upload Test Results
3328
uses: actions/upload-artifact@v4
34-
if: ${{success() || failure()}}
29+
if: success() || failure()
3530
with:
36-
name: ${{(inputs.experimental == 'true' && 'experimental-') || ''}}test-results-${{inputs.runtime-type}}-${{inputs.os}}-${{inputs.architecture}}-${{inputs.target_framework}}-${{inputs.build_configuration}}
37-
path: '**/*.trx'
38-
if-no-files-found: ${{(inputs.experimental == 'true' && 'ignore') || 'warn'}}
39-
compression-level: 0
31+
name: ${{(inputs.experimental == 'true' && 'experimental-') || ''}}test-results-${{inputs.runtime-type}}-${{inputs.os}}-${{inputs.architecture}}${{inputs.target_framework && format('-{0}', inputs.target_framework) || ''}}-${{inputs.build_configuration}}
32+
path: |
33+
TestResults/*.trx
34+
if-no-files-found: warn
35+
retention-days: 1
36+
compression-level: 0

.github/copilot-instructions.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
Prefer `var` in variable declarations.
2-
Use the latest C# version features.
3-
Do not add obvious comments.
4-
When adding new methods, provide docfx documentation.
5-
Respect .editorconfig (for example, tab instead of spaces).
1+
For editing C# code changes:
2+
- prefer `var` in variable declarations.
3+
- use the latest C# version features.
4+
- do not add obvious comments.
5+
- when adding new methods, provide docfx documentation.
6+
- respect .editorconfig (for example, tab instead of spaces).
7+
8+
For editing .github/actions or .github/workflows:
9+
- make sure to understand the multi-platform nature of the Harmony tests
10+
- avoid running bash or powershell scripts
11+
- use the latest and valid GitHub Actions syntax and features
12+
- make sure no unnecessary warnings or errors are introduced
13+
- prefer smaller surgical changes over large refactors unless instructed to do so

.github/workflows/test-result-upload.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
if: always()
3232
with:
3333
check_name: Test Results ${{(inputs.experimental && '(Experimental)') || ''}}
34-
files: test-results/**/*.trx
34+
files: "test-results/**/*.trx"
3535
fail_on: ${{(inputs.experimental && 'nothing') || 'test failures'}}
3636
check_run: ${{!inputs.experimental}}
3737
comment_mode: ${{(inputs.experimental && 'off') || 'always'}}

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,24 @@ jobs:
200200

201201
test-results:
202202
name: Test Results
203-
needs: [windows-dotnet, windows-framework, windows-mono, ubuntu-macos-x64-dotnet, ubuntu-macos-x64-mono, ubuntu-macos-arm64-mono]
203+
needs: [variables, windows-dotnet, windows-framework, windows-mono, ubuntu-macos-x64-dotnet, ubuntu-macos-x64-mono, ubuntu-macos-arm64-mono]
204204
if: always()
205205
uses: ./.github/workflows/test-result-upload.yml
206+
with:
207+
experimental: ${{needs.variables.outputs.EXPERIMENTAL == 'true'}}
206208

207209
cleanup-build-output:
208210
name: Cleanup Build Output
209211
needs: [test-results]
210212
runs-on: ubuntu-latest
211213
if: always()
212214
steps:
215+
# Delete build output artifacts
213216
- uses: joutvhu/delete-artifact@v2
214217
with:
215218
pattern: build-output-*
219+
220+
# Delete test result artifacts
216221
- uses: joutvhu/delete-artifact@v2
217222
with:
218223
pattern: test-results-*

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup Label="Harmony Defines">
3-
<HarmonyVersion>2.4.0.0</HarmonyVersion>
3+
<HarmonyVersion>2.4.1.0</HarmonyVersion>
44
<HarmonyPrerelease></HarmonyPrerelease>
55

66
<!-- set empty to build from local LocalMonoMod submodule -->

Harmony/Internal/MethodPatcherTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ [.. parameterTypes]
7575
{
7676
var baseArgs = method.GetArgumentAttributes();
7777
if (method.DeclaringType is not null)
78-
baseArgs = baseArgs.Union(method.DeclaringType.GetArgumentAttributes());
78+
baseArgs = baseArgs.Union(method.DeclaringType.GetArgumentAttributes()).OfType<HarmonyArgument>();
7979
return method.GetParameters().Select(p =>
8080
{
8181
var arg = p.GetArgumentAttribute();

Harmony/Internal/PatchArgumentExtensions.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,41 @@ static IEnumerable<HarmonyArgument> AllHarmonyArguments(object[] attributes)
2020

2121
internal static HarmonyArgument GetArgumentAttribute(this ParameterInfo parameter)
2222
{
23-
var attributes = parameter.GetCustomAttributes(true);
24-
return AllHarmonyArguments(attributes).FirstOrDefault();
23+
try
24+
{
25+
var attributes = parameter.GetCustomAttributes(true);
26+
return AllHarmonyArguments(attributes).FirstOrDefault();
27+
}
28+
catch (NotSupportedException)
29+
{
30+
return null;
31+
}
2532
}
2633

2734
internal static IEnumerable<HarmonyArgument> GetArgumentAttributes(this MethodInfo method)
2835
{
29-
var attributes = method.GetCustomAttributes(true);
30-
return AllHarmonyArguments(attributes);
36+
try
37+
{
38+
var attributes = method.GetCustomAttributes(true);
39+
return AllHarmonyArguments(attributes);
40+
}
41+
catch (NotSupportedException)
42+
{
43+
return [];
44+
}
3145
}
3246

3347
internal static IEnumerable<HarmonyArgument> GetArgumentAttributes(this Type type)
3448
{
35-
var attributes = type.GetCustomAttributes(true);
36-
return AllHarmonyArguments(attributes);
49+
try
50+
{
51+
var attributes = type.GetCustomAttributes(true);
52+
return AllHarmonyArguments(attributes);
53+
}
54+
catch (NotSupportedException)
55+
{
56+
return [];
57+
}
3758
}
3859

3960
internal static string GetRealName(this IEnumerable<HarmonyArgument> attributes, string name, string[] originalParameterNames)

Harmony/Internal/VariableState.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public LocalBuilder this[InjectionType type]
2121
{
2222
if (injected.TryGetValue(type, out var local))
2323
return local;
24-
Console.WriteLine($"VariableState: variable of type {type} not found");
25-
return null;
24+
throw new ArgumentException($"VariableState: variable of type {type} not found");
2625
}
2726
set => injected[type] = value;
2827
}
@@ -33,8 +32,7 @@ public LocalBuilder this[string name]
3332
{
3433
if (other.TryGetValue(name, out var local))
3534
return local;
36-
Console.WriteLine($"VariableState: variable named '{name}' not found");
37-
return null;
35+
throw new ArgumentException($"VariableState: variable named '{name}' not found");
3836
}
3937
set => other[name] = value;
4038
}

HarmonyTests/Patching/Assets/ArgumentCases.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,40 @@ public struct Value { public int n; }
1616
public class ArgumentOriginalMethods
1717
{
1818
[MethodImpl(MethodImplOptions.NoInlining)]
19-
public void Object_2_Object(ArgumentTypes.Object p) => TestTools.WriteLine("ok");
19+
public void Object_2_Object(ArgumentTypes.Object p) => TestTools.WriteLine("ok", false);
2020

2121
[MethodImpl(MethodImplOptions.NoInlining)]
22-
public void Object_2_ObjectRef(ArgumentTypes.Object p) => TestTools.WriteLine("ok");
22+
public void Object_2_ObjectRef(ArgumentTypes.Object p) => TestTools.WriteLine("ok", false);
2323

2424
[MethodImpl(MethodImplOptions.NoInlining)]
25-
public void ObjectRef_2_Object(ref ArgumentTypes.Object p) => TestTools.WriteLine("ok");
25+
public void ObjectRef_2_Object(ref ArgumentTypes.Object p) => TestTools.WriteLine("ok", false);
2626

2727
[MethodImpl(MethodImplOptions.NoInlining)]
28-
public void ObjectRef_2_ObjectRef(ref ArgumentTypes.Object p) => TestTools.WriteLine("ok");
28+
public void ObjectRef_2_ObjectRef(ref ArgumentTypes.Object p) => TestTools.WriteLine("ok", false);
2929

3030
[MethodImpl(MethodImplOptions.NoInlining)]
31-
public void Value_2_Value(ArgumentTypes.Value p) => TestTools.WriteLine("ok");
31+
public void Value_2_Value(ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
3232

3333
[MethodImpl(MethodImplOptions.NoInlining)]
34-
public void Value_2_Boxing(ArgumentTypes.Value p) => TestTools.WriteLine("ok");
34+
public void Value_2_Boxing(ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
3535

3636
[MethodImpl(MethodImplOptions.NoInlining)]
37-
public void Value_2_ValueRef(ArgumentTypes.Value p) => TestTools.WriteLine("ok");
37+
public void Value_2_ValueRef(ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
3838

3939
[MethodImpl(MethodImplOptions.NoInlining)]
40-
public void Value_2_BoxingRef(ArgumentTypes.Value p) => TestTools.WriteLine("ok");
40+
public void Value_2_BoxingRef(ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
4141

4242
[MethodImpl(MethodImplOptions.NoInlining)]
43-
public void ValueRef_2_Value(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok");
43+
public void ValueRef_2_Value(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
4444

4545
[MethodImpl(MethodImplOptions.NoInlining)]
46-
public void ValueRef_2_Boxing(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok");
46+
public void ValueRef_2_Boxing(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
4747

4848
[MethodImpl(MethodImplOptions.NoInlining)]
49-
public void ValueRef_2_ValueRef(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok");
49+
public void ValueRef_2_ValueRef(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
5050

5151
[MethodImpl(MethodImplOptions.NoInlining)]
52-
public void ValueRef_2_BoxingRef(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok");
52+
public void ValueRef_2_BoxingRef(ref ArgumentTypes.Value p) => TestTools.WriteLine("ok", false);
5353
}
5454

5555
public static class ArgumentPatchMethods

0 commit comments

Comments
 (0)