-
Notifications
You must be signed in to change notification settings - Fork 167
/
.gitlab-ci.yml
298 lines (248 loc) · 12.2 KB
/
.gitlab-ci.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# If there's an open MR then we do not run branch pipelines. Otherwise, we always run the pipeline.
# This allows us to run all pipelines (web, branch, MR) without duplicating branch and MR pipelines
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_PIPELINE_SOURCE == "external_pull_request_event"'
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- when: never
variables:
UNITY_HUB: "C:/Program Files/Unity Hub/Unity Hub.exe"
# Path to folder on runner where artifacts are stored
# Changing this will affect other repositories that consume artifacts from this repository
ARTIFACTS_PATH: "UnityPlugin_CI_artifacts"
ARTIFACTS_NAME: "UnityPlugin-$CI_COMMIT_SHORT_SHA"
# Path to CI folder in this repository
CI_PATH: "CI"
CI_UNITY_PROJECTS_PATH: "$CI_PATH/Projects"
CI_SCRIPTS_PATH: "$CI_PATH/Scripts"
# Paths to the UPM packages in this repository
PACKAGES_PATH: "$CI_PROJECT_DIR/Packages"
PACKAGE_PATH_Tracking: "$PACKAGES_PATH/Tracking"
PACKAGE_PATH_Tracking_Preview: "$PACKAGES_PATH/Tracking Preview"
# Keys used to share caches between jobs
CACHE_LIBRARY_KEY: library-key
CACHE_FALLBACK_KEY: fallback-key
# Name of output artifacts including the .unitypackage
OUTPUT_NAME: "$CI_PROJECT_TITLE"
stages:
- gather
- test
- build
.base:
tags:
- unity
- win10
interruptible: true
before_script:
- New-Item -Path "$ARTIFACTS_PATH" -ItemType Directory -Force
# -----------------------------------------------------------------------------
# Formatting
# -----------------------------------------------------------------------------
#
# This job checks formatting of source code against the rules defined in .editorconfig.
# The job will not make changes on it's own - failure will produce a diff artifact which can be applied in a later commit.
#
check-formatting:
extends: .base
stage: test
allow_failure: true
needs: []
variables:
DOTNET_FORMAT_RESULTS: "$ARTIFACTS_PATH/dotnet_format_results.diff"
script:
# Run dotnet format from location where .editorconfig is defined
- dotnet-format -f --exclude ".git $CI_PATH Markdown"
# Make sure our copyrights have the correct date
- $CurrentYear = Get-Date -Format yyyy;
- |
Get-ChildItem -Path "$PACKAGES_PATH/" -Filter *.cs -Recurse -File -Name | ForEach-Object {
$ScriptContent = Get-Content -Path "$PACKAGES_PATH/$_";
if ($ScriptContent[1] -Like "*Copyright (C) Ultraleap*") {
$ScriptContent[1] = " * Copyright (C) Ultraleap, Inc. 2011-$CurrentYear. *";
$ScriptContent -Join "`n" | Set-Content -NoNewline "$PACKAGES_PATH/$_";
}
}
# Make sure uses of Utils specify the Leap.Unity namespace
- |
Get-ChildItem -Path "$PACKAGES_PATH/" -Filter *.cs -Recurse -File -Name | ForEach-Object {
$ScriptContent = Get-Content -Path "$PACKAGES_PATH/$_";
if ($ScriptContent -match 'using Leap.Unity' -or $ScriptContent -match 'namespace Leap.Unity') {
$ScriptContent = $ScriptContent -replace ' Utils\.', ' Leap.Unity.Utils.';
$ScriptContent -Join "`n" | Set-Content -NoNewline "$PACKAGES_PATH/$_";
}
}
# git diff so we can see the changes needed to be made
- $linter_errors = git --no-pager diff --name-only "*.cs";
# Pipe diffs into output artefact and fail job if any are detected
- $err_count = $linter_errors.length
- if ($linter_errors.length -gt 0) { echo "Detected $err_count formatting issues:" $linter_errors; cmd /c "git diff > $DOTNET_FORMAT_RESULTS"; exit 1; } else { exit 0; }
artifacts:
name: "$ARTIFACTS_NAME-format-diff"
paths:
- "$ARTIFACTS_PATH/"
when: on_failure
# -----------------------------------------------------------------------------
# Unity Builds
# -----------------------------------------------------------------------------
#
# This job will trigger Unity 2021/2022 test apps to build using the plugin commit that started this pipeline.
# A failure in a build likely represents a breaking plugin change and should be addressed, but will not fail the whole pipeline.
# The resulting builds will contain every sample scene, and should be used for manual testing.
#
unity-builds:
stage: test
allow_failure: true
needs: []
rules:
- when: manual
trigger:
project: xr/integrations/unity/unityplugin-tests
branch: main
variables:
PLUGIN_COMMIT_BRANCH: $CI_COMMIT_BRANCH
PLUGIN_COMMIT_HASH: $CI_COMMIT_SHA
# -----------------------------------------------------------------------------
# Generate API Documentation
# -----------------------------------------------------------------------------
#
# This job runs doxygen to generate xml artifacts required by the [documentation repository](https://gitlab.ultrahaptics.com/marcom/ultraleap-api-docs).
# Html artifacts are also generated for quick visualization purposes.
#
generate-api-docs:
extends: .base
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- when: manual
stage: gather
needs: []
variables:
XML_ARTIFACTS_PATH: "$ARTIFACTS_PATH/unity_xml"
HTML_ARTIFACTS_PATH: "$ARTIFACTS_PATH/unity_html"
script:
- doxygen
- Move-Item -Path docs/xml -Destination $XML_ARTIFACTS_PATH
- Move-Item -Path docs/html -Destination $HTML_ARTIFACTS_PATH
artifacts:
name: "$ARTIFACTS_NAME-api-docs"
paths:
- "$ARTIFACTS_PATH/"
when: always
# -----------------------------------------------------------------------------
# Libtrack Dependency
# -----------------------------------------------------------------------------
#
# This job retrieves artifacts from the libtrack repository and selects files required for the UnityPlugin.
# Output is artifacts which can be consumed by later jobs in specific unity projects.
#
dependencies-libtrack:
extends: .base
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- when: manual
stage: gather
needs: []
variables:
# XR group variables:
# - LIBTRACK_ACCESS_TOKEN
# - LIBTRACK_BRANCH
LIBTRACK_URL: "https://gitlab.ultrahaptics.com/api/v4/projects/leap-v5-platform%2Flibtrack/jobs/artifacts/$LIBTRACK_BRANCH/raw"
LIBTRACK_ANDROID_JOB: "AndroidRelWithDebInfoProdLTS"
LIBTRACK_WINDOWS_JOB: "WinRelDebProdLTS"
ANDROID_ARTIFACTS_PATH: "$ARTIFACTS_PATH/Android"
WINDOWS_ARTIFACTS_PATH: "$ARTIFACTS_PATH/Windows"
VERSION_SUFFIX_PATH: "$ARTIFACTS_PATH/libtrack_version_suffix.txt"
script:
# Ensure artifact paths exist
- New-Item -Path "$ANDROID_ARTIFACTS_PATH" -ItemType Directory -Force
- New-Item -Path "$WINDOWS_ARTIFACTS_PATH" -ItemType Directory -Force
## Download version info
- echo "$LIBTRACK_URL/VERSION_SUFFIX.txt?job=$LIBTRACK_ANDROID_JOB"
- Invoke-RestMethod -Headers @{"PRIVATE-TOKEN"="$LIBTRACK_ACCESS_TOKEN"} -Uri "$LIBTRACK_URL/VERSION_SUFFIX.txt?job=$LIBTRACK_ANDROID_JOB" -OutFile "$VERSION_SUFFIX_PATH"
- if ( -not (Test-Path "$VERSION_SUFFIX_PATH")) { echo "Error downloading version info"; exit 1; }
- $VERSION_SUFFIX = Get-Content -Path "$VERSION_SUFFIX_PATH"
- echo $VERSION_SUFFIX
## Download libLeapC ZIP
- if (-not (Test-Path -Path "LeapC/")) { echo "creating... LeapC"; New-Item "LeapC/" -Type Directory }
- echo "$LIBTRACK_URL/LeapC-SDK-XR2-$VERSION_SUFFIX.zip?job=$LIBTRACK_ANDROID_JOB"
- Invoke-RestMethod -Headers @{"PRIVATE-TOKEN"="$LIBTRACK_ACCESS_TOKEN"} -Uri "$LIBTRACK_URL/LeapC-SDK-XR2-$VERSION_SUFFIX.zip?job=$LIBTRACK_ANDROID_JOB" -OutFile "LeapC.zip"
- if (-not (Test-Path "LeapC.zip")) { echo "Error downloading LeapC"; exit 1; }
- Expand-Archive -Path "LeapC.zip" -DestinationPath "LeapC/"
- Copy-Item "LeapC/lib/libLeapC.so" -Destination "$ANDROID_ARTIFACTS_PATH/libLeapC.so" -Force
## Download service binder AAR
- echo "$LIBTRACK_URL/UltraleapTrackingServiceBinder-$VERSION_SUFFIX.aar?job=$LIBTRACK_ANDROID_JOB"
- Invoke-RestMethod -Headers @{"PRIVATE-TOKEN"="$LIBTRACK_ACCESS_TOKEN"} -Uri "$LIBTRACK_URL/UltraleapTrackingServiceBinder-$VERSION_SUFFIX.aar?job=$LIBTRACK_ANDROID_JOB" -OutFile "$ANDROID_ARTIFACTS_PATH/UltraleapTrackingServiceBinder.aar"
- if (-not (Test-Path "$ANDROID_ARTIFACTS_PATH/UltraleapTrackingServiceBinder.aar")) { echo "Error downloading service binder"; exit 1; }
## Download LeapC DLL
- echo "$LIBTRACK_URL/VisualizerDependencies.zip?job=$LIBTRACK_WINDOWS_JOB"
- if (-not (Test-Path -Path "temp/")) { echo "creating... temp"; New-Item "temp/" -Type Directory }
- Invoke-RestMethod -Headers @{"PRIVATE-TOKEN"="$LIBTRACK_ACCESS_TOKEN"} -Uri "$LIBTRACK_URL/VisualizerDependencies.zip?job=$LIBTRACK_WINDOWS_JOB" -OutFile "temp.zip"
- if (-not (Test-Path "temp.zip")) { echo "Error downloading full artifact archive"; exit 1; }
- Expand-Archive -Path "temp.zip" -DestinationPath "temp/"
- Copy-Item "temp/VisualizerDependencies/LeapC.dll" -Destination "$WINDOWS_ARTIFACTS_PATH/LeapC.dll" -Force
artifacts:
name: "$ARTIFACTS_NAME-libtrack-dependencies"
paths:
- "$ARTIFACTS_PATH/"
when: on_success
# -----------------------------------------------------------------------------
# Exports all .unitypackages
# -----------------------------------------------------------------------------
#
# This job moves/modifies content to be more suitable for .unitypackage and exports multiple .unitypackage artifacts.
#
export-unitypackages:
extends: .base
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- when: manual
stage: build
needs: []
variables:
# Path to UnityPlugin within a unity project
# Changing this will change the root where all generated .unitypackages import to in a project
UNITYPLUGIN_ASSETS_PATH: "Assets/ThirdParty/Ultraleap"
EXPORT_UNITYPACKAGE_SCRIPT: "$CI_SCRIPTS_PATH/ExportUnityPackage.ps1"
PLUGIN_LIBS_PATH: "$PACKAGE_PATH_Tracking/Core/Runtime/Plugins"
UNITYPACKAGES_OUTPUT_PATH: "$CI_PROJECT_DIR/$ARTIFACTS_PATH/Ultraleap.UnityPlugin"
# These are the paths that the corresponding .unitypackage will export from
PACKAGE_IMPORT_PATH_Tracking: "$UNITYPLUGIN_ASSETS_PATH/Tracking"
UNITYPACKAGE_OUTPUT_PATH_Tracking: "$UNITYPACKAGES_OUTPUT_PATH/Ultraleap Tracking.unitypackage"
PACKAGE_IMPORT_PATH_Tracking_Preview: "$UNITYPLUGIN_ASSETS_PATH/Tracking Preview"
UNITYPACKAGE_OUTPUT_PATH_Tracking_Preview: "$UNITYPACKAGES_OUTPUT_PATH/Ultraleap Tracking Preview.unitypackage"
script:
- New-Item -Path "$UNITYPACKAGES_OUTPUT_PATH" -ItemType Directory -Force
# Import functions required below by calling script to define global functions
- . $EXPORT_UNITYPACKAGE_SCRIPT
######################################################
# Creates version.txt and deletes package.json files #
######################################################
- Export-VersionTxt $PACKAGE_PATH_Tracking
- Export-VersionTxt $PACKAGE_PATH_Tracking_Preview
#########################
# Export .unitypackages #
#########################
- Export-UnityPackage -PackageRootPath "$PACKAGE_PATH_Tracking" -PackageImportPath "$PACKAGE_IMPORT_PATH_Tracking" -PackageOutputPath "$UNITYPACKAGE_OUTPUT_PATH_Tracking" -ErrorVariable ExportErrors
- if ($ExportErrors) { echo "Failed to generate Tracking.unitypackage"; exit 1; }
- Export-UnityPackage -PackageRootPath "$PACKAGE_PATH_Tracking_Preview" -PackageImportPath "$PACKAGE_IMPORT_PATH_Tracking_Preview" -PackageOutputPath "$UNITYPACKAGE_OUTPUT_PATH_Tracking_Preview" -ErrorVariable ExportErrors
- if ($ExportErrors) { echo "Failed to generate Tracking Preview.unitypackage"; exit 1; }
############################
# Tidy up artifacts folder #
############################
- $package_version = Get-Content "$PACKAGE_PATH_Tracking/Version.txt"
- echo "Version - $package_version"
- ls $UNITYPACKAGES_OUTPUT_PATH
- Move-Item "$UNITYPACKAGES_OUTPUT_PATH" "$UNITYPACKAGES_OUTPUT_PATH-$package_version"
artifacts:
name: "$ARTIFACTS_NAME-unitypackage"
paths:
- "$ARTIFACTS_PATH/"
when: on_success