-
Notifications
You must be signed in to change notification settings - Fork 52
149 lines (135 loc) · 5.81 KB
/
Copy pathunity-tests.yml
File metadata and controls
149 lines (135 loc) · 5.81 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
name: Unity Tests
# Path-filtered on purpose. This matrix is five game-ci jobs; before the monorepo
# it lived in a repo that only held C#, so firing on every push was harmless. Now
# a renderer or docs commit would light up all five for nothing.
on:
push:
branches: ['**']
paths:
- 'unity/**'
- 'tests/**'
- '.github/workflows/unity-tests.yml'
pull_request:
branches: [main]
paths:
- 'unity/**'
- 'tests/**'
- '.github/workflows/unity-tests.yml'
workflow_dispatch:
inputs:
overwrite-snapshots:
type: boolean
description: Overwrite snapshots
# The old workflow also had `repository_dispatch: [run-tests]`, fired by a
# trigger-tests.yml living on the orphan `tests` branch of another repo. Both
# sides are in this repo now, so the whole round trip is deleted.
concurrency:
group: unity-tests-${{ github.ref }}
cancel-in-progress: true
jobs:
tests:
name: ${{ matrix.suite.name }} - Unity ${{ matrix.unity.version }}
permissions:
contents: write
checks: write
pull-requests: write
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]
unity:
- { version: '6000.0.51f1' }
- { version: '2023.2.20f1' }
- { version: '2022.3.62f1' }
- { version: '2021.3.45f1' }
suite:
- { name: 'Unit Tests', assemblies: 'ReactUnity.Tests;ReactUnity.Tests.Editor' }
include:
# `main` marks the one job that owns the side effects: committing
# snapshots and pushing the badge gist.
- main: true
unity: { version: '6000.1.9f1' }
suite: { name: 'Unit Tests', assemblies: 'ReactUnity.Tests;ReactUnity.Tests.Editor' }
runs-on: ${{ matrix.platform || 'ubuntu-latest' }}
steps:
# One checkout. This replaced five (core, tests@tests branch, jint, quickjs,
# clearscript) plus the jq manifest rewriting that wired them together --
# tests/Packages/manifest.json now commits the correct file:../../unity/*
# paths, so there is nothing to patch at runtime.
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache Unity Library
uses: actions/cache@v4
with:
path: tests/Library
key: Library-${{ matrix.unity.version }}-${{ matrix.platform || 'ubuntu-latest' }}
- name: Run Unity Tests
uses: game-ci/unity-test-runner@v4
id: testRunner
continue-on-error: true
env:
UNITY_LICENSE: ${{ secrets[matrix.unity.license || 'UNITY_LICENSE'] }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
projectPath: tests
githubToken: ${{ secrets.GITHUB_TOKEN }}
checkName: ${{ matrix.suite.name }} ${{ matrix.unity.version }}
unityVersion: ${{ matrix.unity.version }}
testMode: ${{ contains(matrix.suite.assemblies, 'Editor') && 'All' || 'PlayMode' }}
# Code coverage instrumentation is gone along with Codecov. It cost
# -debugCodeOptimization on the slowest job and nothing consumed the
# result any more.
customParameters: >-
-assemblyNames ${{ matrix.suite.assemblies }}
${{ (contains(github.event.head_commit.message, '[snapshots]') || github.event.inputs.overwrite-snapshots == 'true') && '-reactOverwriteSnapshots' || '' }}
- name: Commit Snapshots
if: hashFiles('unity/core/Tests/.snapshots/snapshots.lock') != '' && matrix.main
uses: EndBug/add-and-commit@v9
with:
add: 'unity/core/Tests/.snapshots'
default_author: github_actions
message: 'Update snapshots'
- name: Set artifacts folder ownership to current user
run: sudo chown -R $(id -u):$(id -g) "${{ github.workspace }}/${{ steps.testRunner.outputs.artifactsPath }}"
- uses: EnricoMi/publish-unit-test-result-action@v2
id: test-results
with:
check_name: '${{ matrix.suite.name }} ${{ matrix.unity.version }}'
nunit_files: '${{ github.workspace }}/${{ steps.testRunner.outputs.artifactsPath }}/*.xml'
- name: Set badge color
shell: bash
run: |
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
success) echo "BADGE_COLOR=31c653" >> $GITHUB_ENV ;;
failure) echo "BADGE_COLOR=800000" >> $GITHUB_ENV ;;
neutral) echo "BADGE_COLOR=696969" >> $GITHUB_ENV ;;
esac
- name: Create badge
uses: emibcn/badge-action@v2
with:
label: Tests
status: '${{ fromJSON( steps.test-results.outputs.json ).stats.tests_succ }}/${{ fromJSON( steps.test-results.outputs.json ).stats.tests }}'
color: ${{ env.BADGE_COLOR }}
path: ReactUnityTestBadge.svg
style: flat
scale: 1.4
- name: Upload badge to Gist
if: github.ref == 'refs/heads/main' && always() && matrix.main
uses: andymckay/append-gist-action@1fbfbbce708a39bd45846f0955ed5521f2099c6d
with:
token: ${{ secrets.GIST_TOKEN }}
gistURL: https://gist.githubusercontent.com/KurtGokhan/f744e86dd53cd0159d4f1d56ae9aae19
file: ReactUnityTestBadge.svg
- name: Upload Test Result Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: '${{ matrix.suite.name }} ${{ matrix.unity.version }}'
path: ${{ steps.testRunner.outputs.artifactsPath }}
- name: Fail workflow if tests failed
if: steps.testRunner.outcome == 'failure' && (fromJSON(steps.test-results.outputs.json).conclusion == 'failure' || fromJSON(steps.test-results.outputs.json).stats.tests == 0)
uses: actions/github-script@v7
with:
script: core.setFailed('Tests failed!')