-
Notifications
You must be signed in to change notification settings - Fork 329
279 lines (240 loc) · 10 KB
/
main.yml
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: Build and Test
on:
push:
branches: ["master", "feature/*"]
tags: ["v*", "plugin-api-v*"]
pull_request_target:
branches: ["master"]
permissions:
actions: read
checks: write
contents: read
statuses: write
jobs:
determineVersionNumber:
name: Determine Version Number
runs-on: ubuntu-latest
outputs:
version: ${{ steps.generateVersion.outputs.version }}
plugin-api-version: ${{ steps.generateVersion.outputs.plugin-api-version }}
steps:
- name: Checkout action file
uses: actions/checkout@v4
with:
sparse-checkout: .github/actions/checkout/action.yml
sparse-checkout-cone-mode: false
- name: Checkout
uses: ./.github/actions/checkout
- name: Generate Version Number
id: generateVersion
shell: pwsh
run: |
foreach ($tagPrefix in @("", "plugin-api-")) {
$describe = git describe --long --tags --always --match "$($tagPrefix)v*"
if ($describe -match "^$($tagPrefix)v?(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)-(?<offset>\d+)-g(?<hash>[a-f0-9]+)`$") {
if ([int]::Parse($Matches.offset) -eq 0) {
$version = "$($Matches.major).$($Matches.minor).$($Matches.patch)"
} else {
$version = "$($Matches.major).$($Matches.minor).$([int]::Parse($Matches.patch) + 1)-dev.$($Matches.offset)+$($Matches.hash)"
}
} else {
$version = "0.0.0-dev.$(git rev-list HEAD --count)+$describe"
}
Write-Host "Generated version number$(if ($tagPrefix -eq '') { '' } else { " $tagPrefix" } ): $version"
echo "$($tagPrefix)version=$($version)" >> $Env:GITHUB_OUTPUT
}
buildOnLinux:
name: Build on Linux
runs-on: ubuntu-latest
needs: [determineVersionNumber]
steps:
- name: Checkout action file
uses: actions/checkout@v4
with:
sparse-checkout: .github/actions/checkout/action.yml
sparse-checkout-cone-mode: false
- name: Checkout
uses: ./.github/actions/checkout
- name: Create DLL
uses: ./.github/actions/create-dll
with:
version: ${{ needs.determineVersionNumber.outputs.version }}
- name: Upload NuGetForUnity dlls
uses: actions/upload-artifact@v4
with:
name: NuGetForUnity-dlls
path: |
./src/NuGetForUnity.CreateDll/bin/Release/NugetForUnity.dll
./src/NuGetForUnity.CreateDll/bin/Release/NuGetForUnity.PluginAPI.dll
./src/NuGetForUnity.CreateDll/bin/Release/NuGetForUnity.PluginAPI.xml
if-no-files-found: error
- name: Check if files in NuGetForUnity.PluginAPI changed
if: github.event_name == 'pull_request_target'
id: changedPluginApiCode
uses: tj-actions/changed-files@v45
with:
files: |
src/NuGetForUnity.PluginAPI/**.cs
- name: Check if NuGetForUnity.PluginAPI.dll is updated
if: github.event_name == 'pull_request_target'
id: changedPluginApiDll
uses: tj-actions/changed-files@v45
with:
files: |
src/NuGetForUnity/Editor/PluginAPI/NuGetForUnity.PluginAPI.dll
- name: Fail if source code of NuGetForUnity.PluginAPI has changed but NuGetForUnity.PluginAPI.dll is not updated / changed
if: |
github.event_name == 'pull_request_target' &&
steps.changedPluginApiCode.outputs.any_changed == 'true' &&
steps.changedPluginApiDll.outputs.any_changed == 'false'
shell: bash
run: |
echo "One or more *.cs files in the src/NuGetForUnity.PluginAPI folder were changed"
echo "but 'src/NuGetForUnity/Editor/PluginAPI/NuGetForUnity.PluginAPI.dll' was not updated"
exit 1
packageOnLinux:
name: Create .unitypackage on Linux
runs-on: ubuntu-latest
needs: [buildOnLinux, determineVersionNumber]
steps:
- name: Checkout action file
uses: actions/checkout@v4
with:
sparse-checkout: .github/actions/checkout/action.yml
sparse-checkout-cone-mode: false
- name: Checkout
uses: ./.github/actions/checkout
- name: Download NuGetForUnity dlls
uses: actions/download-artifact@v4
with:
name: NuGetForUnity-dlls
path: ./src/NuGetForUnity.Packager/Assets/NuGet/Editor
- name: Unity - Packager (build .unitypackage)
uses: game-ci/[email protected]
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
# Platform that the build should target.
targetPlatform: StandaloneWindows64
# Version of unity to use for building the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt
unityVersion: auto
# Relative path to the project to be built.
projectPath: ./src/NuGetForUnity.Packager
# Path to a Namespace.Class.StaticMethod to run to perform the build.
buildMethod: NugetForUnity.Export.Execute
# custom versioning
versioning: "Custom"
version: ${{ needs.determineVersionNumber.outputs.version }}
- name: Upload UnityPackage
uses: actions/upload-artifact@v4
with:
name: NuGetForUnity.${{ needs.determineVersionNumber.outputs.version }}.unitypackage
path: ./src/NuGetForUnity.Packager/NugetForUnity.unitypackage
if-no-files-found: error
packageNuGetPackages:
name: Pack .NET Core Global Tool (CLI) and PluginAPI
runs-on: ubuntu-latest
needs: [determineVersionNumber]
steps:
- name: Checkout action file
uses: actions/checkout@v4
with:
sparse-checkout: .github/actions/checkout/action.yml
sparse-checkout-cone-mode: false
- name: Checkout
uses: ./.github/actions/checkout
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Build and pack .NET Core Global Tool
run: >-
dotnet pack ./src/NuGetForUnity.Cli/NuGetForUnity.Cli.csproj --nologo -c Release -o .
-p:Version=${{ needs.determineVersionNumber.outputs.version }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
-p:ContinuousIntegrationBuild=true
- name: Build and pack NuGetForUnity.PluginAPI
run: >-
dotnet pack ./src/NuGetForUnity.PluginAPI/NuGetForUnity.PluginAPI.csproj --nologo -c Release -o .
-p:Version=${{ needs.determineVersionNumber.outputs.plugin-api-version }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
-p:ContinuousIntegrationBuild=true
- name: publish the NuGetForUnity.Cli NuGet package
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
run: >-
dotnet nuget push ./NuGetForUnity.Cli.${{ needs.determineVersionNumber.outputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_TOKEN }}
--source https://api.nuget.org/v3/index.json
- name: publish the NuGetForUnity.PluginAPI NuGet package
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'plugin-api-v')
run: >-
dotnet nuget push ./NuGetForUnity.PluginAPI.${{ needs.determineVersionNumber.outputs.plugin-api-version }}.nupkg --api-key ${{ secrets.NUGET_API_TOKEN }}
--source https://api.nuget.org/v3/index.json
- name: Upload NuGet packages
uses: actions/upload-artifact@v4
with:
name: NuGetForUnity-NuGetPackages
path: |
./NuGetForUnity.Cli.*.nupkg
./NuGetForUnity.PluginAPI.*.nupkg
if-no-files-found: error
testUbuntu:
name: Test on Linux
runs-on: ubuntu-latest
steps:
- name: Checkout action file
uses: actions/checkout@v4
with:
sparse-checkout: .github/actions/checkout/action.yml
sparse-checkout-cone-mode: false
- name: Checkout
uses: ./.github/actions/checkout
- name: Unity - Run tests
uses: game-ci/[email protected]
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
projectPath: src/NuGetForUnity.Tests
githubToken: ${{ secrets.GITHUB_TOKEN }}
testMode: EditMode
runTestProjectsOnLinux:
name: Run test projects on Linux
runs-on: ubuntu-latest
needs: [packageNuGetPackages, determineVersionNumber]
strategy:
fail-fast: false
matrix:
projectPath:
- src/TestProjects/ImportAndUseNuGetPackages
- src/TestProjects/ImportAndUseNuGetPackages2021
steps:
- name: Checkout action file
uses: actions/checkout@v4
with:
sparse-checkout: .github/actions/checkout/action.yml
sparse-checkout-cone-mode: false
- name: Checkout
uses: ./.github/actions/checkout
- name: Download NuGetForUnity.Cli NuGet package
uses: actions/download-artifact@v4
with:
name: NuGetForUnity-NuGetPackages
path: .
- name: Install NuGetForUnity.Cli Tool
run: dotnet tool install --add-source . NuGetForUnity.Cli --version ${{ needs.determineVersionNumber.outputs.version }}
- name: Restore NuGet packages using NuGetForUnity.Cli
run: dotnet nugetforunity restore '${{ matrix.projectPath }}'
- name: Unity - Build project ${{ matrix.projectPath }}
uses: game-ci/[email protected]
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
# Platform that the build should target.
targetPlatform: StandaloneWindows64
# Relative path to the project to be built.
projectPath: ${{ matrix.projectPath }}
# disable versioning
versioning: "None"