Merge pull request #1111 from Warlander/beta #299
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Unity Tests | |
| on: | |
| workflow_dispatch: {} | |
| workflow_call: | |
| inputs: | |
| ref: | |
| description: "Git ref to test (defaults to the triggering ref)." | |
| type: string | |
| required: false | |
| default: "" | |
| push: | |
| branches: ["**"] | |
| paths: | |
| - TestProjects/UnityMCPTests/** | |
| - MCPForUnity/Editor/** | |
| - MCPForUnity/Runtime/** | |
| - .github/workflows/unity-tests.yml | |
| # Fork PRs: maintainer applies the 'safe-to-test' label after reviewing | |
| # the diff. The workflow runs with UNITY_LICENSE in scope against the | |
| # PR's head SHA. Re-pushed commits do NOT auto-trigger — maintainer must | |
| # remove and re-apply the label to re-run after additional review. | |
| pull_request_target: | |
| types: [labeled] | |
| branches: [main, beta] | |
| paths: | |
| - TestProjects/UnityMCPTests/** | |
| - MCPForUnity/Editor/** | |
| - MCPForUnity/Runtime/** | |
| - .github/workflows/unity-tests.yml | |
| jobs: | |
| testAllModes: | |
| name: Test in ${{ matrix.testMode }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| if: > | |
| github.event_name != 'pull_request_target' || | |
| (github.event.pull_request.head.repo.full_name != github.repository && | |
| github.event.label.name == 'safe-to-test') | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| projectPath: | |
| - TestProjects/UnityMCPTests | |
| testMode: | |
| - editmode | |
| unityVersion: | |
| - 2021.3.45f2 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| ref: ${{ inputs.ref || github.event.pull_request.head.sha || github.ref }} | |
| persist-credentials: false | |
| - name: Detect Unity license secrets | |
| id: detect | |
| env: | |
| UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
| UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
| UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
| UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} | |
| run: | | |
| set -e | |
| if [ -n "$UNITY_LICENSE" ] || { [ -n "$UNITY_EMAIL" ] && [ -n "$UNITY_PASSWORD" ] && [ -n "$UNITY_SERIAL" ]; }; then | |
| echo "unity_ok=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "unity_ok=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Skip Unity tests (missing license secrets) | |
| if: steps.detect.outputs.unity_ok != 'true' | |
| run: | | |
| echo "Unity license secrets missing; skipping Unity tests." | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ${{ matrix.projectPath }}/Library | |
| key: Library-${{ matrix.projectPath }}-${{ matrix.unityVersion }} | |
| restore-keys: | | |
| Library-${{ matrix.projectPath }}- | |
| Library- | |
| # Run domain reload tests first (they're [Explicit] so need explicit category) | |
| - name: Run domain reload tests | |
| if: steps.detect.outputs.unity_ok == 'true' | |
| uses: game-ci/unity-test-runner@v4 | |
| id: domain-tests | |
| env: | |
| UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
| UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
| UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
| UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} | |
| with: | |
| projectPath: ${{ matrix.projectPath }} | |
| unityVersion: ${{ matrix.unityVersion }} | |
| testMode: ${{ matrix.testMode }} | |
| customParameters: -testCategory domain_reload | |
| - name: Run tests | |
| if: steps.detect.outputs.unity_ok == 'true' | |
| uses: game-ci/unity-test-runner@v4 | |
| id: tests | |
| continue-on-error: true | |
| env: | |
| UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
| UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
| UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
| UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} | |
| with: | |
| projectPath: ${{ matrix.projectPath }} | |
| unityVersion: ${{ matrix.unityVersion }} | |
| testMode: ${{ matrix.testMode }} | |
| - name: Check test results | |
| if: steps.detect.outputs.unity_ok == 'true' | |
| run: | | |
| RESULTS_XML=$(find ${{ steps.tests.outputs.artifactsPath }} -name '*.xml' 2>/dev/null | head -1) | |
| if [ -z "$RESULTS_XML" ]; then | |
| echo "::error::No test results XML found — Unity may have crashed" | |
| exit 1 | |
| fi | |
| FAILED=$(grep -oP 'failed="\K[0-9]+' "$RESULTS_XML" | head -1) | |
| PASSED=$(grep -oP 'passed="\K[0-9]+' "$RESULTS_XML" | head -1) | |
| TOTAL=$(grep -oP 'total="\K[0-9]+' "$RESULTS_XML" | head -1) | |
| INCONCLUSIVE=$(grep -oP 'inconclusive="\K[0-9]+' "$RESULTS_XML" | head -1) | |
| SKIPPED=$(grep -oP 'skipped="\K[0-9]+' "$RESULTS_XML" | head -1) | |
| echo "Results: $PASSED passed, $FAILED failed, $INCONCLUSIVE inconclusive, $SKIPPED skipped (total: $TOTAL)" | |
| if [ "$FAILED" != "0" ]; then | |
| echo "::error::$FAILED test(s) failed" | |
| exit 1 | |
| fi | |
| - uses: actions/upload-artifact@v4 | |
| if: always() && steps.detect.outputs.unity_ok == 'true' && steps.tests.outcome != 'skipped' | |
| with: | |
| name: Test results for ${{ matrix.testMode }} | |
| path: ${{ steps.tests.outputs.artifactsPath }} |