Skip to content

Commit

Permalink
Merge branch 'main' into support-new-unity-versioning-scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKahr committed May 6, 2024
2 parents 056d560 + 75d0d76 commit d88d353
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 127 deletions.
74 changes: 46 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ jobs:
# - run: yarn build --quiet && git diff --quiet action || { echo "ERROR - index.js is different from repository version. Forgot to run `yarn build`?" ; exit 62; }

testAllModesLikeInTheReadme:
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
runs-on: ubuntu-latest
name: Test in ${{ matrix.testMode }} of version ${{ matrix.unityVersion }} on ${{ matrix.baseRunner }}
runs-on: ${{ matrix.baseRunner }}
strategy:
fail-fast: false
max-parallel: 2
matrix:
baseRunner:
- ubuntu-latest
- windows-latest
projectPath:
- unity-project-with-correct-tests
unityVersion:
Expand All @@ -57,9 +61,9 @@ jobs:
- uses: actions/cache@v3
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}
key: Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}
restore-keys: |
Library-
Library-${{ matrix.baseRunner }}
- uses: ./
id: tests
with:
Expand All @@ -76,10 +80,13 @@ jobs:

testRunnerInAllModes:
name: Test all modes ✨
runs-on: ubuntu-latest
runs-on: ${{ matrix.baseRunner }}
strategy:
fail-fast: false
matrix:
baseRunner:
- ubuntu-latest
- windows-latest
projectPath:
- unity-project-with-correct-tests
unityVersion:
Expand All @@ -100,10 +107,9 @@ jobs:
- uses: actions/cache@v3
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
key: Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
Library-${{ matrix.baseRunner }}
# Configure test runner
- name: Run tests
Expand Down Expand Up @@ -134,10 +140,13 @@ jobs:

testRunnerInEditMode:
name: Test edit mode 📝
runs-on: ubuntu-latest
runs-on: ${{ matrix.baseRunner }}
strategy:
fail-fast: false
matrix:
baseRunner:
- ubuntu-latest
- windows-latest
unityVersion:
- 2022.3.13f1
- 2023.1.19f1
Expand All @@ -161,10 +170,9 @@ jobs:
- uses: actions/cache@v3
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
key: Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
Library-${{ matrix.baseRunner }}
# Configure test runner
- name: Run tests
Expand Down Expand Up @@ -195,10 +203,13 @@ jobs:

testRunnerInPlayMode:
name: Test play mode 📺
runs-on: ubuntu-latest
runs-on: ${{ matrix.baseRunner }}
strategy:
fail-fast: false
matrix:
baseRunner:
- ubuntu-latest
- windows-latest
projectPath:
- unity-project-with-correct-tests
unityVersion:
Expand All @@ -219,10 +230,9 @@ jobs:
- uses: actions/cache@v3
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
key: Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
Library-${{ matrix.baseRunner }}
# Configure test runner
- name: Run tests
Expand Down Expand Up @@ -252,10 +262,13 @@ jobs:

testRunnerInStandalone:
name: Test standalone 📺
runs-on: ubuntu-latest
runs-on: ${{ matrix.baseRunner }}
strategy:
fail-fast: false
matrix:
baseRunner:
- ubuntu-latest
- windows-latest
projectPath:
- unity-project-with-correct-tests
unityVersion:
Expand All @@ -276,10 +289,10 @@ jobs:
- uses: actions/cache@v3
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
key: Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}-
Library-${{ matrix.baseRunner }}-
# Configure test runner
- name: Run tests
Expand All @@ -301,10 +314,13 @@ jobs:

testRunnerInStandaloneWithIL2CPP:
name: Test standalone with IL2CPP 📺
runs-on: ubuntu-latest
runs-on: ${{ matrix.baseRunner }}
strategy:
fail-fast: false
matrix:
baseRunner:
- ubuntu-latest
- windows-latest
projectPath:
- unity-project-with-correct-tests
unityVersion:
Expand All @@ -325,17 +341,17 @@ jobs:
- uses: actions/cache@v3
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
key: Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
Library-${{ matrix.baseRunner }}-
# Set scripting backend to IL2CPP
- name: Rewrite ProjectSettings
run: |
DefineOriginal=" scriptingBackend: {}"
DefineReplace=" scriptingBackend: \\n Standalone: 1"
sed -i "{s/$DefineOriginal/$DefineReplace/g}" ${{ matrix.projectPath }}/ProjectSettings/ProjectSettings.asset
shell: bash

# Configure test runner
- name: Run tests
Expand All @@ -357,10 +373,13 @@ jobs:

testEachModeSequentially:
name: Test each mode sequentially 👩‍👩‍👧‍👦 # don't try this at home (it's much slower)
runs-on: ubuntu-latest
runs-on: ${{ matrix.baseRunner }}
strategy:
fail-fast: false
matrix:
baseRunner:
- ubuntu-latest
- windows-latest
unityVersion:
- 2022.3.13f1
- 2023.1.19f1
Expand All @@ -381,10 +400,9 @@ jobs:
- uses: actions/cache@v3
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
key: Library-${{ matrix.baseRunner }}-${{ matrix.projectPath }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
Library-${{ matrix.baseRunner }}-
# Configure first test runner
- name: Tests in editmode 📝
Expand Down
74 changes: 16 additions & 58 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/main.js

This file was deleted.

3 changes: 3 additions & 0 deletions dist/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const index = require('./index.js');

index.main();
29 changes: 21 additions & 8 deletions dist/platforms/windows/run_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ foreach ( $platform in ${env:TEST_PLATFORMS}.Split(";") )
Write-Output ""

# Create directories if they do not exist
if(-Not (Test-Path -Path $Env:UNITY_PROJECT_PATH\Assets\Editor))
if(-Not (Test-Path -Path $UNITY_PROJECT_PATH\Assets\Editor))
{
# We use -Force to suppress output, doesn't overwrite anything
New-Item -ItemType Directory -Force -Path $Env:UNITY_PROJECT_PATH\Assets\Editor
New-Item -ItemType Directory -Force -Path $UNITY_PROJECT_PATH\Assets\Editor
}
if(-Not (Test-Path -Path $Env:UNITY_PROJECT_PATH\Assets\Player))
if(-Not (Test-Path -Path $UNITY_PROJECT_PATH\Assets\Player))
{
# We use -Force to suppress output, doesn't overwrite anything
New-Item -ItemType Directory -Force -Path $Env:UNITY_PROJECT_PATH\Assets\Player
}

# Copy the scripts
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Editor" -Destination $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Player" -Destination $Env:UNITY_PROJECT_PATH\Assets\Player -Recurse
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Editor" -Destination $UNITY_PROJECT_PATH\Assets\Editor -Recurse
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Player" -Destination $UNITY_PROJECT_PATH\Assets\Player -Recurse

# Verify recursive paths
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Player -Recurse
Get-ChildItem -Path $UNITY_PROJECT_PATH\Assets\Editor -Recurse
Get-ChildItem -Path $UNITY_PROJECT_PATH\Assets\Player -Recurse

$runTests="-runTests -testPlatform StandaloneWindows64 -builtTestRunnerPath $UNITY_PROJECT_PATH\Build\UnityTestRunner-Standalone.exe"
}
Expand All @@ -106,7 +106,20 @@ foreach ( $platform in ${env:TEST_PLATFORMS}.Split(";") )
}
}

$TEST_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${env:UNITY_VERSION}\editor\Unity.exe" -ArgumentList "-batchmode -logFile $FULL_ARTIFACTS_PATH\$platform.log -projectPath $UNITY_PROJECT_PATH -coverageResultsPath $FULL_COVERAGE_RESULTS_PATH $runTests -enableCodeCoverage -debugCodeOptimization -coverageOptions ${env:COVERAGE_OPTIONS} ${env:CUSTOM_PARAMETERS}"
$TEST_OUTPUT = Start-Process -FilePath "$Env:UNITY_PATH/Editor/Unity.exe" `
-NoNewWindow `
-Wait `
-PassThru `
-ArgumentList "-batchmode `
-nographics `
-logFile $FULL_ARTIFACTS_PATH\$platform.log `
-projectPath $UNITY_PROJECT_PATH `
-coverageResultsPath $FULL_COVERAGE_RESULTS_PATH `
$runTests `
-enableCodeCoverage `
-debugCodeOptimization `
-coverageOptions ${env:COVERAGE_OPTIONS} `
${env:CUSTOM_PARAMETERS}"

# Catch exit code
$TEST_EXIT_CODE = $TEST_OUTPUT.ExitCode
Expand Down
1 change: 0 additions & 1 deletion dist/post.js

This file was deleted.

3 changes: 3 additions & 0 deletions dist/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const index = require('./index.js');

index.post();
32 changes: 2 additions & 30 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@
import { run as main } from './main';
import path from 'path';
import { run as post } from './post';

/*
* GitHub Action can provide multiple executable entrypoints (pre, main, post),
* but it is complicated process to generate multiple `.js` files with `ncc`.
* So we rather generate just one entrypoint, that is symlinked to multiple locations (main.js and post.js).
* Then when GitHub Action Runner executes it as `node path/to/main.js` and `node path/to/post.js`,
* it can read arguments it was executed with and decide which file to execute.
* The argv[0] is going to be a full path to `node` executable and
* the argv[1] is going to be the full path to the script.
* In case index.js would be marked executable and executed directly without the argv[1] it defaults to "main.js".
*/
async function run([, name = 'main.js']: string[]) {
const script = path.basename(name);

switch (script) {
case 'main.js':
await main();
break;
case 'post.js':
await post();
break;
default:
throw new Error(`Unknown script argument: '${script}'`);
}
}

run(process.argv);
export { run as main } from './main';
export { run as post } from './post';

0 comments on commit d88d353

Please sign in to comment.