Skip to content

Commit 04e18c8

Browse files
committed
Change to GitHub actions workflow
1 parent cabc010 commit 04e18c8

5 files changed

Lines changed: 248 additions & 303 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Check formatting
2+
description: Run formatting checks and write a diff artifact when changes are required
3+
4+
outputs:
5+
has_diff:
6+
description: Whether the formatting check produced a diff artifact
7+
value: ${{ steps.result.outputs.has_diff }}
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- uses: actions/setup-dotnet@v5
13+
with:
14+
dotnet-version: 8.0.x
15+
16+
- name: Install dotnet-format
17+
shell: bash
18+
run: |
19+
set -euo pipefail
20+
echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
21+
dotnet tool install --global dotnet-format || dotnet tool update --global dotnet-format
22+
23+
- name: Run dotnet-format
24+
shell: bash
25+
run: |
26+
set -euo pipefail
27+
dotnet-format -f --exclude .git Scripts Markdown
28+
29+
- name: Apply Copyright Year and Namespace Fixes
30+
shell: bash
31+
run: |
32+
set -euo pipefail
33+
export CURRENT_YEAR="$(date +%Y)"
34+
find Packages -type f -name '*.cs' -print0 | xargs -0 perl -0pi -e '
35+
s/^ \* Copyright \(C\) Ultraleap.*$/ * Copyright (C) Ultraleap, Inc. 2011-$ENV{CURRENT_YEAR}. */mg;
36+
if (/using Leap\.Unity|namespace Leap\.Unity/) {
37+
s/ Utils\./ Leap.Unity.Utils./g;
38+
}
39+
'
40+
41+
- name: Generate Formatting Diff
42+
id: result
43+
shell: bash
44+
run: |
45+
set -euo pipefail
46+
diff_path="$ARTIFACTS_PATH/dotnet_format_results.diff"
47+
48+
mapfile -t linter_errors < <(git --no-pager diff --name-only -- '*.cs')
49+
if ((${#linter_errors[@]})); then
50+
printf 'Detected %s formatting issues:\n' "${#linter_errors[@]}"
51+
printf '%s\n' "${linter_errors[@]}"
52+
mkdir -p "$ARTIFACTS_PATH"
53+
git diff > "$diff_path"
54+
echo "has_diff=true" >> "$GITHUB_OUTPUT"
55+
exit 1
56+
else
57+
echo "No formatting issues detected."
58+
echo "has_diff=false" >> "$GITHUB_OUTPUT"
59+
fi
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Export Unity Package
2+
description: Generate Version.txt and export a Unity package artifact
3+
4+
inputs:
5+
package_root_path:
6+
description: Path to the package root
7+
required: true
8+
package_import_path:
9+
description: Import path inside the Unity package
10+
required: true
11+
package_file_name:
12+
description: File name for the generated .unitypackage
13+
required: true
14+
artifact_root_path:
15+
description: Root path that will contain the generated unitypackage artifacts
16+
required: true
17+
package_output_path:
18+
description: Existing output path to reuse for the generated .unitypackage directory
19+
required: false
20+
21+
outputs:
22+
package_version:
23+
description: Exported package version
24+
value: ${{ steps.export.outputs.package_version }}
25+
package_output_path:
26+
description: Output path containing the generated .unitypackage
27+
value: ${{ steps.export.outputs.package_output_path }}
28+
29+
runs:
30+
using: composite
31+
steps:
32+
- name: Export Unity Package
33+
id: export
34+
shell: pwsh
35+
run: |
36+
. "Scripts/ExportUnityPackage.ps1"
37+
38+
Export-VersionTxt "${{ inputs.package_root_path }}"
39+
40+
$packageVersion = Get-Content (Join-Path "${{ inputs.package_root_path }}" "Version.txt")
41+
$packageOutputPath = "${{ inputs.package_output_path }}"
42+
if ([string]::IsNullOrWhiteSpace($packageOutputPath)) {
43+
$packageOutputPath = Join-Path "${{ inputs.artifact_root_path }}" "Ultraleap.UnityPlugin-$packageVersion"
44+
}
45+
New-Item -Path $packageOutputPath -ItemType Directory -Force | Out-Null
46+
47+
$unitypackageOutputPath = Join-Path $packageOutputPath "${{ inputs.package_file_name }}"
48+
49+
$exportErrors = $null
50+
Export-UnityPackage `
51+
-PackageRootPath "${{ inputs.package_root_path }}" `
52+
-PackageImportPath "${{ inputs.package_import_path }}" `
53+
-PackageOutputPath $unitypackageOutputPath `
54+
-ErrorVariable exportErrors
55+
56+
if ($exportErrors) {
57+
throw "Failed to generate $unitypackageOutputPath"
58+
}
59+
60+
"package_version=$packageVersion" >> $env:GITHUB_OUTPUT
61+
"package_output_path=$packageOutputPath" >> $env:GITHUB_OUTPUT

.github/workflows/ci.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
workflow_dispatch:
9+
inputs:
10+
check_formatting:
11+
description: Check formatting
12+
required: false
13+
default: true
14+
type: boolean
15+
generate_api_docs:
16+
description: Generate API documentation
17+
required: false
18+
default: false
19+
type: boolean
20+
export_unitypackages:
21+
description: Export .unitypackage artifacts
22+
required: false
23+
default: false
24+
type: boolean
25+
26+
permissions:
27+
contents: read
28+
29+
concurrency:
30+
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
31+
cancel-in-progress: true
32+
33+
env:
34+
ARTIFACTS_PATH: UnityPlugin_CI_artifacts
35+
PACKAGE_PATH_TRACKING: Packages/Tracking
36+
PACKAGE_PATH_TRACKING_PREVIEW: Packages/Tracking Preview
37+
38+
jobs:
39+
check-formatting:
40+
name: Check Formatting
41+
runs-on: ubuntu-latest
42+
continue-on-error: true
43+
if: github.event_name != 'workflow_dispatch' || inputs.check_formatting
44+
steps:
45+
- name: Checkout Repository
46+
uses: actions/checkout@v6
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Check Formatting
51+
uses: ./.github/actions/check-formatting
52+
id: formatting
53+
54+
- name: Upload Formatting Diff
55+
if: always() && steps.formatting.outputs.has_diff == 'true'
56+
uses: actions/upload-artifact@v7
57+
with:
58+
name: UnityPlugin-${{ github.sha }}-format-diff
59+
path: ${{ env.ARTIFACTS_PATH }}/
60+
if-no-files-found: error
61+
62+
generate-api-docs:
63+
name: Generate API Docs
64+
runs-on: ubuntu-latest
65+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.generate_api_docs)
66+
steps:
67+
- name: Checkout Repository
68+
uses: actions/checkout@v6
69+
70+
- name: Install Doxygen
71+
run: |
72+
sudo apt-get update
73+
sudo apt-get install -y doxygen
74+
75+
- name: Generate API Documentation
76+
run: doxygen ./Doxyfile
77+
78+
- name: Collect API Documentation
79+
run: |
80+
mkdir -p "$ARTIFACTS_PATH"
81+
mv docs/xml "$ARTIFACTS_PATH/unity_xml"
82+
mv docs/html "$ARTIFACTS_PATH/unity_html"
83+
84+
- name: Upload API Documentation
85+
uses: actions/upload-artifact@v7
86+
with:
87+
name: UnityPlugin-${{ github.sha }}-api-docs
88+
path: ${{ env.ARTIFACTS_PATH }}/
89+
if-no-files-found: error
90+
91+
export-unitypackages:
92+
name: Export Unity Packages
93+
runs-on: ubuntu-latest
94+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.export_unitypackages)
95+
env:
96+
UNITYPLUGIN_ASSETS_PATH: Assets/ThirdParty/Ultraleap
97+
steps:
98+
- name: Checkout Repository
99+
uses: actions/checkout@v6
100+
101+
- name: Export Tracking Unity Package
102+
uses: ./.github/actions/export-unitypackage
103+
id: export_tracking
104+
with:
105+
package_root_path: ${{ env.PACKAGE_PATH_TRACKING }}
106+
package_import_path: ${{ env.UNITYPLUGIN_ASSETS_PATH }}/Tracking
107+
package_file_name: Ultraleap Tracking.unitypackage
108+
artifact_root_path: ${{ env.ARTIFACTS_PATH }}
109+
110+
- name: Export Tracking Preview Unity Package
111+
uses: ./.github/actions/export-unitypackage
112+
id: export_tracking_preview
113+
with:
114+
package_root_path: ${{ env.PACKAGE_PATH_TRACKING_PREVIEW }}
115+
package_import_path: ${{ env.UNITYPLUGIN_ASSETS_PATH }}/Tracking Preview
116+
package_file_name: Ultraleap Tracking Preview.unitypackage
117+
artifact_root_path: ${{ env.ARTIFACTS_PATH }}
118+
package_output_path: ${{ steps.export_tracking.outputs.package_output_path }}
119+
120+
- name: Upload Unity Packages
121+
uses: actions/upload-artifact@v7
122+
with:
123+
name: UnityPlugin-${{ github.sha }}-unitypackage
124+
path: ${{ env.ARTIFACTS_PATH }}/
125+
if-no-files-found: error

0 commit comments

Comments
 (0)