-
-
Notifications
You must be signed in to change notification settings - Fork 3
179 lines (159 loc) · 7.08 KB
/
Copy pathtest.yml
File metadata and controls
179 lines (159 loc) · 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Copyright (c) 2023-2026 Koji Hasegawa.
# This software is released under the MIT License.
name: Test
on:
push:
branches:
- master
paths-ignore:
- '**.md'
- '.github/**'
- '!.github/workflows/test.yml'
pull_request:
types: [ opened, synchronize, reopened ] # Same as default
paths-ignore:
- '**.md'
- '.github/**'
- '!.github/workflows/test.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: { }
defaults:
run:
shell: bash
jobs:
test:
if: github.event.pull_request.head.repo.fork == false # Skip on public fork, because can not read secrets.
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
checks: write
pull-requests: write
strategy:
fail-fast: false
matrix:
unityVersion: # Available versions see: https://game.ci/docs/docker/versions
- 2019.4.41f2
- 2022.3.62f3 # Non-Enterprise LTS
- 6000.0.77f1
- 6000.3.18f1
- &latest_unity_version 6000.5.0f1
testMode:
- All # run tests in editor
include:
- unityVersion: *latest_unity_version
octocov: true
flip: true
- unityVersion: 6000.0.63f1 # "Error building Player because scripts are compiling" in 6000.0.64f1 and 6000.3.1f1
testMode: Standalone # run tests on player
steps:
- name: Create project for test
uses: nowsprinting/create-unity-project-action@c086a110a56fd0600a6051e709d99e635e3f208e # v4.1
with:
project-path: .
scripting-backend: 1 # IL2CPP
il2cpp-code-generation: 1 # Optimize for code size and build time
managed-stripping-level: 3 # High
- name: Create link.xml to preserve reflection-only APIs under IL2CPP high stripping
# Has.Length and Throws.TypeOf<ArgumentException>().With.Property("ParamName") resolve
# FileInfo.Length / ArgumentException.ParamName via reflection at runtime; High stripping
# removes the getters and NUnit throws "Property <Name> was not found". Preserve them here
# instead of rewriting the idiomatic assertions in the test code. ArgumentNullException
# inherits ParamName from ArgumentException, so one entry covers both.
run: |
mkdir -p "$CREATED_PROJECT_PATH/Assets"
cat > "$CREATED_PROJECT_PATH/Assets/link.xml" <<'EOF'
<linker>
<assembly fullname="mscorlib">
<type fullname="System.IO.FileInfo">
<method name="get_Length" />
</type>
<type fullname="System.ArgumentException">
<method name="get_ParamName" />
</type>
</assembly>
</linker>
EOF
if: matrix.testMode == 'Standalone'
- name: Get package checkout path
run: |
name=com.$(echo "${GITHUB_REPOSITORY}" | sed 's/\//\./g')
echo "PACKAGE_PATH=$CREATED_PROJECT_PATH/Packages/$name" >> "$GITHUB_ENV"
# In Linux editor, there is a problem that assets in local packages cannot be found with `AssetDatabase.FindAssets`.
# As a workaround, I have made it into an embedded package.
- name: Checkout repository as embedded package
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
submodules: false
lfs: false
path: ${{ env.PACKAGE_PATH }}
- name: Install dependent UPM packages
run: |
npm install -g openupm-cli
openupm add -f com.unity.test-framework@stable
openupm add -f com.cysharp.unitask
working-directory: ${{ env.CREATED_PROJECT_PATH }}
- name: Install FlipBinding.CSharp package
run: |
openupm add -f org.nuget.flipbinding.csharp
working-directory: ${{ env.CREATED_PROJECT_PATH }}
if: ${{ matrix.flip }}
- name: Install codecoverage package
run: |
openupm add -f com.unity.testtools.codecoverage
working-directory: ${{ env.CREATED_PROJECT_PATH }}
if: ${{ matrix.octocov }}
- name: Restore cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ${{ env.CREATED_PROJECT_PATH }}/Library
key: Library-${{ runner.os }}-${{ matrix.unityVersion }}-${{ hashFiles(format('{0}/package.json', env.PACKAGE_PATH)) }}
restore-keys: |
Library-${{ runner.os }}-${{ matrix.unityVersion }}-
Library-${{ runner.os }}-
Library-
- name: Set coverage assembly filters
run: |
assemblies=$(find ${{ env.PACKAGE_PATH }} -name "*.asmdef" | sed -e s/.*\\//\+/ | sed -e s/\\.asmdef// | sed -e s/^.*\\.Tests//)
# shellcheck disable=SC2001,SC2048,SC2086
echo "assembly_filters=$(echo ${assemblies[*]} | sed -e s/\ /,/g),+<assets>,-*.Tests" >> "$GITHUB_ENV"
if: ${{ matrix.octocov }}
- name: Set license secret key
run: echo "secret_key=UNITY_LICENSE_$(echo ${{ matrix.unityVersion }} | cut -c 1-4)" >> "$GITHUB_ENV"
- name: Run tests
uses: game-ci/unity-test-runner@0ff419b913a3630032cbe0de48a0099b5a9f0ed9 # v4
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
unityVersion: ${{ matrix.unityVersion }} # Default is `auto`
checkName: test (${{ matrix.unityVersion }}, ${{ matrix.testMode }})
projectPath: ${{ env.CREATED_PROJECT_PATH }}
customParameters: -retry 5 -testCategory "!IgnoreCI" -testHelperScreenshotDirectory /github/workspace/artifacts/Screenshots
# Note: `/github/workspace/artifacts` is the artifacts path inside the game-ci container
coverageOptions: generateAdditionalMetrics;generateTestReferences;generateHtmlReport;generateAdditionalReports;dontClear;assemblyFilters:${{ env.assembly_filters }}
# see: https://docs.unity3d.com/Packages/com.unity.testtools.codecoverage@1.2/manual/CoverageBatchmode.html
testMode: ${{ matrix.testMode }}
env:
UNITY_LICENSE: ${{ secrets[env.secret_key] }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
id: test
- name: Set coverage path for octocov
run: |
mv ${{ env.PACKAGE_PATH }}/.octocov.yml .
sed -i -r 's/UnityProject~\/Logs/${{ steps.test.outputs.coveragePath }}/' .octocov.yml
if: ${{ matrix.octocov }}
- name: Run octocov
uses: k1LoW/octocov-action@b3b6ee60482a667950f87553abf1df63217235d9 # v1
env:
OCTOCOV_GOOGLE_APPLICATION_CREDENTIALS_JSON: ${{ secrets.OCTOCOV_GOOGLE_APPLICATION_CREDENTIALS_JSON }}
if: ${{ matrix.octocov }}
- name: Upload test results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: TestResults-Unity${{ matrix.unityVersion }}-${{ matrix.testMode }}
path: |
${{ steps.test.outputs.artifactsPath }}
${{ steps.test.outputs.coveragePath }}
if: always()