-
Notifications
You must be signed in to change notification settings - Fork 55
187 lines (161 loc) · 5.64 KB
/
ci.yml
File metadata and controls
187 lines (161 loc) · 5.64 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
180
181
182
183
184
185
186
187
name: CI - Build and Test
on:
push:
branches: [ "main", "develop" ]
paths:
- 'src/**'
- '.github/workflows/ci.yml'
pull_request:
branches: [ "main", "develop" ]
paths:
- 'src/**'
- '.github/workflows/ci.yml'
workflow_call:
# Security: Minimal required permissions
permissions:
contents: read # Read repository contents
actions: write # Upload artifacts
pull-requests: read # Read PR context
checks: write # Write test results
# Prevent concurrent runs of the same workflow only when CI actually runs
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
# Set global defaults
defaults:
run:
working-directory: ./src
jobs:
build-test:
name: Build and Test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
${{ vars.DOTNET_VERSION || '8.0.x' }}
8.0.x
6.0.x
2.1.x
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --no-restore --configuration Debug
- name: Copy DLLs for Unity tests
run: |
cp ./Nino/bin/Debug/netstandard2.1/Nino.Core.dll ./Nino.Unity/Packages/com.jasonxudeveloper.nino/Runtime/Nino.Core.dll
cp ./Nino/bin/Debug/netstandard2.1/Nino.Generator.dll ./Nino.Unity/Packages/com.jasonxudeveloper.nino/Runtime/Nino.Generator.dll
- name: Run unit tests
run: dotnet test --no-build --verbosity normal --configuration Debug --collect:"XPlat Code Coverage" --results-directory ./TestResults
- name: Cache Unity Library
uses: actions/cache@v4
with:
path: src/Nino.Unity/Library
key: Library-Nino-${{ runner.os }}-${{ hashFiles('Nino.Unity/Assets/**', 'Nino.Unity/ProjectSettings/**') }}
restore-keys: |
Library-Nino-${{ runner.os }}-
Library-Nino-
Library-
- name: Run Unity tests
# Skip Unity tests for external PRs (secrets not available in forks)
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: game-ci/unity-test-runner@v4
id: unity-tests
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
projectPath: ./src/Nino.Unity
testMode: editmode
githubToken: ${{ secrets.GITHUB_TOKEN }}
unityVersion: '2022.3.51f1'
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ github.run_number }}
path: |
artifacts
./src/TestResults
retention-days: 30
- name: Upload Unity coverage
uses: actions/upload-artifact@v4
if: always() && steps.unity-tests.outputs.coveragePath
with:
name: unity-coverage-${{ github.run_number }}
path: ${{ steps.unity-tests.outputs.coveragePath }}
retention-days: 30
# Run benchmarks on PRs only
benchmark:
name: Run Benchmarks
runs-on: ubuntu-latest
needs: [ build-test ]
if: github.event_name == 'pull_request'
timeout-minutes: 180
permissions:
contents: read
pull-requests: write
defaults:
run:
working-directory: ./src
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
${{ vars.DOTNET_VERSION || '8.0.x' }}
8.0.x
6.0.x
2.1.x
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-benchmark-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build benchmark project
run: |
cd Nino.Benchmark
dotnet build -c Release
- name: Run benchmarks
run: |
cd Nino.Benchmark
echo "Running benchmarks for PR #${{ github.event.pull_request.number }}..."
dotnet run -c Release --no-build
# Verify benchmark results exist (check for any github markdown file)
MARKDOWN_FILE=$(find BenchmarkDotNet.Artifacts/results -name "*-report-github.md" -type f 2>/dev/null | head -n1)
if [[ -n "$MARKDOWN_FILE" && -f "$MARKDOWN_FILE" ]]; then
echo "✅ Benchmark completed successfully - found report file:"
echo "$MARKDOWN_FILE"
else
echo "❌ Benchmark results not found"
echo "Looking for markdown files in results directory..."
find BenchmarkDotNet.Artifacts -name "*.md" -type f || echo "No markdown files found"
exit 1
fi
- name: Upload benchmark results
uses: actions/upload-artifact@v4
if: always()
with:
name: benchmark-results-pr-${{ github.event.pull_request.number }}
path: src/Nino.Benchmark/**/BenchmarkDotNet.Artifacts/results
retention-days: 30