|
| 1 | +name: Unity Performance Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + types: |
| 7 | + - opened |
| 8 | + - reopened |
| 9 | + - synchronize |
| 10 | + - labeled |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + actions: read |
| 16 | + |
| 17 | +env: |
| 18 | + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} |
| 19 | + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} |
| 20 | + UNITY_LICENSE: ${{ secrets.UNITY_PERSONAL_LICENSE }} |
| 21 | + UNITY_IMAGE_FLAVOR: linux-il2cpp |
| 22 | + UNITY_IMAGE_VERSION: 3.2.0 |
| 23 | + GHCR_IMAGE_NAME: unityci-editor |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + performance-test: |
| 31 | + name: Performance Test (PlayMode) |
| 32 | + runs-on: ubuntu-latest |
| 33 | + # Run on manual dispatch OR when PR has 'perf_test' label (already present or just added) |
| 34 | + if: | |
| 35 | + github.event_name == 'workflow_dispatch' || |
| 36 | + contains(github.event.pull_request.labels.*.name, 'perf_test') |
| 37 | + steps: |
| 38 | + |
| 39 | + - name: Move Docker data-root to /mnt/docker |
| 40 | + run: | |
| 41 | + sudo systemctl stop docker |
| 42 | + sudo mkdir -p /mnt/docker |
| 43 | + echo '{"data-root":"/mnt/docker"}' | sudo tee /etc/docker/daemon.json |
| 44 | + sudo systemctl start docker |
| 45 | + docker info | sed -n '1,40p' |
| 46 | + df -h /mnt /mnt/docker |
| 47 | +
|
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + fetch-depth: 0 |
| 52 | + lfs: true |
| 53 | + submodules: recursive |
| 54 | + |
| 55 | + - name: Create LFS file list |
| 56 | + run: git lfs ls-files -l | awk '{print $1}' | sort > .lfs-assets-id |
| 57 | + |
| 58 | + - name: Restore LFS cache |
| 59 | + uses: actions/cache@v4 |
| 60 | + id: lfs-cache |
| 61 | + with: |
| 62 | + path: .git/lfs |
| 63 | + key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} |
| 64 | + |
| 65 | + - name: Git LFS Pull |
| 66 | + run: | |
| 67 | + git lfs pull |
| 68 | + git add . |
| 69 | + git reset --hard |
| 70 | +
|
| 71 | + - uses: webfactory/ssh-agent@v0.8.0 |
| 72 | + with: |
| 73 | + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 74 | + |
| 75 | + - name: 'Add GitHub to the SSH known hosts file' |
| 76 | + run: | |
| 77 | + mkdir -p -m 0700 /home/runner/.ssh |
| 78 | + curl --silent https://api.github.com/meta | jq --raw-output '"github.com "+.ssh_keys[]' >> /home/runner/.ssh/known_hosts |
| 79 | + chmod 600 /home/runner/.ssh/known_hosts |
| 80 | +
|
| 81 | + - name: Restore Library cache |
| 82 | + uses: actions/cache@v4 |
| 83 | + with: |
| 84 | + path: Explorer/Library |
| 85 | + key: Library-Explorer-Ubuntu |
| 86 | + |
| 87 | + # --- Detect Unity version from the project --- |
| 88 | + - name: Read Unity version from ProjectVersion.txt |
| 89 | + id: unity-version |
| 90 | + run: | |
| 91 | + verFile="Explorer/ProjectSettings/ProjectVersion.txt" |
| 92 | + if [ ! -f "$verFile" ]; then |
| 93 | + echo "File not found: $verFile" |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | + ver=$(grep -o 'm_EditorVersion: [0-9a-f.]*' "$verFile" | cut -d' ' -f2) |
| 97 | + if [ -z "$ver" ]; then |
| 98 | + echo "Could not parse Unity version from $verFile" |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | + echo "version=$ver" >> $GITHUB_OUTPUT |
| 102 | + echo "Detected Unity version: $ver" |
| 103 | +
|
| 104 | + # --- Build image references (GHCR + upstream) --- |
| 105 | + - name: Set image names |
| 106 | + id: img |
| 107 | + run: | |
| 108 | + version="${{ steps.unity-version.outputs.version }}" |
| 109 | + flavor="${{ env.UNITY_IMAGE_FLAVOR }}" |
| 110 | + imgVer="${{ env.UNITY_IMAGE_VERSION }}" |
| 111 | +
|
| 112 | + # ubuntu-<unityVersion>-<flavor>-<gameciVersion> |
| 113 | + tag="ubuntu-$version-$flavor-$imgVer" |
| 114 | + owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') |
| 115 | + upstream="unityci/editor:$tag" |
| 116 | + ghcr="ghcr.io/$owner/${{ env.GHCR_IMAGE_NAME }}:$tag" |
| 117 | + echo "tag=$tag" >> $GITHUB_OUTPUT |
| 118 | + echo "upstream=$upstream" >> $GITHUB_OUTPUT |
| 119 | + echo "ghcr=$ghcr" >> $GITHUB_OUTPUT |
| 120 | + echo "Upstream image: $upstream" |
| 121 | + echo "GHCR image: $ghcr" |
| 122 | +
|
| 123 | + # --- Log into GHCR --- |
| 124 | + - name: Log in to GitHub Container Registry |
| 125 | + uses: docker/login-action@v3 |
| 126 | + with: |
| 127 | + registry: ghcr.io |
| 128 | + username: ${{ github.actor }} |
| 129 | + password: ${{ github.token }} |
| 130 | + |
| 131 | + # --- Restore Unity image from GHCR (fast path) --- |
| 132 | + - name: Restore Unity image from GHCR |
| 133 | + id: restore-image |
| 134 | + continue-on-error: true |
| 135 | + run: | |
| 136 | + docker pull "${{ steps.img.outputs.ghcr }}" |
| 137 | +
|
| 138 | + # --- Seed GHCR from Docker Hub if missing (one-time per tag) --- |
| 139 | + - name: Download from Docker Hub and upload to GHCR (if missing) |
| 140 | + if: steps.restore-image.outcome == 'failure' |
| 141 | + run: | |
| 142 | + upstream="${{ steps.img.outputs.upstream }}" |
| 143 | + ghcr="${{ steps.img.outputs.ghcr }}" |
| 144 | + echo "GHCR miss. Pulling upstream: $upstream" |
| 145 | + docker pull $upstream |
| 146 | + docker tag $upstream $ghcr |
| 147 | + docker push $ghcr |
| 148 | + echo "Seeded GHCR: $ghcr" |
| 149 | +
|
| 150 | + # Configure test runner for Performance tests only |
| 151 | + - uses: game-ci/unity-test-runner@v4.3.1 |
| 152 | + id: testRunner |
| 153 | + timeout-minutes: 180 |
| 154 | + continue-on-error: true |
| 155 | + env: |
| 156 | + SHELL: /bin/bash |
| 157 | + with: |
| 158 | + projectPath: Explorer |
| 159 | + testMode: playmode |
| 160 | + sshAgent: ${{ env.SSH_AUTH_SOCK }} |
| 161 | + customImage: ${{ steps.img.outputs.ghcr }} |
| 162 | + customParameters: -buildTarget StandaloneLinux64 -testCategory "Performance" -perfTestResults ./PerformanceTestResults.json -DCLBenchmarkCIPKey ${{ secrets.DCL_BENCHMARK_CIP_KEY }} |
| 163 | + githubToken: ${{ env.GITHUB_TOKEN }} |
| 164 | + |
| 165 | + # Generate PDF report |
| 166 | + - name: Set up Python |
| 167 | + if: always() |
| 168 | + uses: actions/setup-python@v5 |
| 169 | + with: |
| 170 | + python-version: '3.11' |
| 171 | + |
| 172 | + - name: Install report dependencies |
| 173 | + if: always() |
| 174 | + run: pip install -r scripts/requirements-perf-report.txt |
| 175 | + |
| 176 | + - name: Generate performance report PDF |
| 177 | + if: always() |
| 178 | + run: | |
| 179 | + python scripts/generate_perf_report.py Explorer/PerformanceTestResults.json Explorer/PerformanceBenchmarkReport.pdf --github-summary Explorer/github_summary.md |
| 180 | + cat Explorer/github_summary.md >> $GITHUB_STEP_SUMMARY |
| 181 | +
|
| 182 | + # Upload performance test results JSON |
| 183 | + - name: Upload performance test results (JSON) |
| 184 | + uses: actions/upload-artifact@v4 |
| 185 | + if: always() |
| 186 | + with: |
| 187 | + name: Performance test results (JSON) |
| 188 | + path: Explorer/PerformanceTestResults.json |
| 189 | + if-no-files-found: warn |
| 190 | + |
| 191 | + # Upload performance report PDF |
| 192 | + - name: Upload performance report (PDF) |
| 193 | + uses: actions/upload-artifact@v4 |
| 194 | + if: always() |
| 195 | + with: |
| 196 | + name: Performance benchmark report (PDF) |
| 197 | + path: Explorer/PerformanceBenchmarkReport.pdf |
| 198 | + if-no-files-found: warn |
0 commit comments