Skip to content

Commit 9c9f75c

Browse files
committed
test 9
1 parent a59695e commit 9c9f75c

File tree

2 files changed

+96
-58
lines changed

2 files changed

+96
-58
lines changed

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

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,22 @@ runs:
5555
"target_frameworks=$target_frameworks" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
5656
shell: pwsh
5757

58-
# Create TestResults directory with absolute path to prevent nesting
59-
- name: Set up TestResults directory
60-
uses: actions/github-script@v7
61-
id: test-results-dir
62-
with:
63-
script: |
64-
const fs = require('fs');
65-
const path = require('path');
66-
67-
// Get the absolute path to the current directory
68-
const workspaceDir = process.cwd();
69-
const testResultsDir = path.join(workspaceDir, 'TestResults');
70-
71-
// Clean up and recreate the directory
72-
if (fs.existsSync(testResultsDir)) {
73-
fs.rmSync(testResultsDir, { recursive: true, force: true });
74-
}
75-
fs.mkdirSync(testResultsDir);
76-
77-
// Output the absolute path for use in later steps
78-
core.setOutput('path', testResultsDir);
79-
return testResultsDir;
58+
# Create clean TestResults directory using simple platform-specific commands
59+
- name: Clean TestResults (Windows)
60+
if: runner.os == 'Windows'
61+
run: |
62+
if (Test-Path "TestResults") {
63+
Remove-Item -Path "TestResults" -Recurse -Force
64+
}
65+
New-Item -Path "TestResults" -ItemType Directory
66+
shell: pwsh
67+
68+
- name: Clean TestResults (Unix)
69+
if: runner.os != 'Windows'
70+
run: |
71+
rm -rf TestResults
72+
mkdir -p TestResults
73+
shell: bash
8074

8175
- name: Build if required
8276
if: ${{inputs.manual_build == 'true'}}
@@ -95,17 +89,17 @@ runs:
9589
$vstest = join-path $vspath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
9690
9791
foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
98-
$resultsFile = "${{steps.test-results-dir.outputs.path}}\${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
99-
& ${{(inputs.runtime-type == 'mono' && '"$mono"') || ''}} "$vstest" "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" --framework:$target_framework --logger:"trx;LogFileName=$resultsFile" --logger:"console;verbosity=normal" --blame -- ${{steps.test-args.outputs.run_settings_args}}
92+
$trxFileName = "${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
93+
& ${{(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}}
10094
}
10195
shell: pwsh
10296

10397
- name: Perform Tests Windows .NET | Ubuntu .NET/Mono
10498
if: ${{(inputs.os == 'windows' && inputs.runtime-type == 'dotnet') || inputs.os == 'ubuntu'}}
10599
run: |
106100
foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
107-
$resultsFile = "${{steps.test-results-dir.outputs.path}}\${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
108-
dotnet test "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" -f $target_framework --logger:"trx;LogFileName=$resultsFile" --logger:"console;verbosity=normal" -- ${{steps.test-args.outputs.run_settings_args}}
101+
$trxFileName = "${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
102+
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}}
109103
}
110104
shell: pwsh
111105

@@ -123,19 +117,40 @@ runs:
123117
$dotnet = '/Users/runner/.dotnet/dotnet'
124118
}
125119
foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
126-
$resultsFile = "${{steps.test-results-dir.outputs.path}}/${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
127-
& $dotnet test "HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll" -f $target_framework --logger:"trx;LogFileName=$resultsFile" --logger:"console;verbosity=normal" -- ${{steps.test-args.outputs.run_settings_args}}
120+
$trxFileName = "${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
121+
& $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}}
128122
}
129123
shell: pwsh
130124

125+
# Copy any TRX files that might have ended up in a nested directory
126+
- name: Fix any nested TRX files (Windows)
127+
if: runner.os == 'Windows'
128+
run: |
129+
$nestedDirs = Get-ChildItem -Path "TestResults" -Directory
130+
foreach ($dir in $nestedDirs) {
131+
$trxFiles = Get-ChildItem -Path $dir.FullName -Filter "*.trx" -File
132+
foreach ($file in $trxFiles) {
133+
Copy-Item -Path $file.FullName -Destination "TestResults\" -Force
134+
}
135+
}
136+
shell: pwsh
137+
continue-on-error: true
138+
139+
- name: Fix any nested TRX files (Unix)
140+
if: runner.os != 'Windows'
141+
run: |
142+
find TestResults -mindepth 2 -name "*.trx" -type f -exec cp {} TestResults/ \;
143+
shell: bash
144+
continue-on-error: true
145+
131146
# Debug step for Windows
132147
- name: List TRX files (Windows)
133148
if: runner.os == 'Windows'
134149
run: |
135150
Write-Host "Searching for TRX files on Windows..."
136151
Write-Host "TRX files in TestResults directory:"
137152
if (Test-Path -Path "TestResults") {
138-
Get-ChildItem -Path "TestResults" -Filter "*.trx" | ForEach-Object { Write-Host $_.FullName }
153+
Get-ChildItem -Path "TestResults" -Filter "*.trx" -Recurse | ForEach-Object { Write-Host $_.FullName }
139154
} else {
140155
Write-Host "TestResults directory not found"
141156
}
@@ -148,12 +163,20 @@ runs:
148163
echo "Searching for TRX files on Unix..."
149164
echo "TRX files in TestResults directory:"
150165
if [ -d "TestResults" ]; then
151-
find TestResults -maxdepth 1 -name "*.trx" -type f | sort
166+
find TestResults -name "*.trx" -type f | sort
152167
else
153168
echo "TestResults directory not found"
154169
fi
155170
shell: bash
156171

172+
# Ensure permissions are correct on Unix systems
173+
- name: Set permissions (Unix)
174+
if: runner.os != 'Windows'
175+
run: |
176+
chmod -R 755 TestResults
177+
shell: bash
178+
continue-on-error: true
179+
157180
- name: Upload Test Result
158181
uses: ./.github/actions/test-upload-result
159182
if: ${{(inputs.upload_tests == 'true') && (always() || failure())}}

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

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,56 @@ inputs:
2424
runs:
2525
using: "composite"
2626
steps:
27-
# Debug step to find TRX files before upload
28-
- name: Find TRX files (Windows)
29-
if: runner.os == 'Windows'
30-
run: |
31-
Write-Host "Finding TRX files before upload (Windows)..."
32-
if (Test-Path -Path "TestResults") {
33-
$files = Get-ChildItem -Path "TestResults" -Filter "*.trx" -File
34-
Write-Host "Found $($files.Count) TRX files in TestResults directory:"
35-
$files | ForEach-Object { Write-Host $_.Name }
36-
} else {
37-
Write-Host "TestResults directory not found"
38-
}
39-
shell: pwsh
40-
41-
- name: Find TRX files (Unix)
42-
if: runner.os != 'Windows'
43-
run: |
44-
echo "Finding TRX files before upload (Unix)..."
45-
if [ -d "TestResults" ]; then
46-
FILES=$(find TestResults -maxdepth 1 -name "*.trx" -type f)
47-
COUNT=$(find TestResults -maxdepth 1 -name "*.trx" -type f | wc -l)
48-
echo "Found $COUNT TRX files in TestResults directory:"
49-
echo "$FILES"
50-
else
51-
echo "TestResults directory not found"
52-
fi
53-
shell: bash
27+
# Use github-script to check files before upload (platform-independent)
28+
- name: Check TRX Files
29+
id: check-files
30+
uses: actions/github-script@v7
31+
with:
32+
script: |
33+
const fs = require('fs');
34+
const path = require('path');
35+
36+
try {
37+
if (!fs.existsSync('TestResults')) {
38+
console.log('TestResults directory not found');
39+
return { count: 0, files: [] };
40+
}
41+
42+
// Helper function to find all TRX files recursively
43+
function findTrxFiles(dir) {
44+
let results = [];
45+
const entries = fs.readdirSync(dir, { withFileTypes: true });
46+
47+
for (const entry of entries) {
48+
const fullPath = path.join(dir, entry.name);
49+
50+
if (entry.isDirectory()) {
51+
results = results.concat(findTrxFiles(fullPath));
52+
} else if (entry.isFile() && entry.name.endsWith('.trx')) {
53+
results.push(fullPath);
54+
}
55+
}
56+
57+
return results;
58+
}
59+
60+
const trxFiles = findTrxFiles('TestResults');
61+
console.log(`Found ${trxFiles.length} TRX files:`);
62+
trxFiles.slice(0, 10).forEach(f => console.log(f));
63+
64+
return { count: trxFiles.length, files: trxFiles.slice(0, 10) };
65+
} catch (error) {
66+
console.log(`Error checking TRX files: ${error.message}`);
67+
return { count: 0, files: [] };
68+
}
5469
5570
- name: Upload Test Results
5671
uses: actions/upload-artifact@v4
5772
if: success() || failure()
5873
with:
5974
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}}
6075
path: |
61-
TestResults/*.trx
76+
TestResults/**/*.trx
6277
if-no-files-found: warn
6378
retention-days: 1
6479
compression-level: 0

0 commit comments

Comments
 (0)