Skip to content

Commit 56922f9

Browse files
authored
Handle Unity Package Setting in different OS (#93)
1 parent cfebc90 commit 56922f9

File tree

6 files changed

+146
-53
lines changed

6 files changed

+146
-53
lines changed

.github/workflows/android.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
inputs:
77
unity_version:
88
description: 'Unity version'
9-
default: '2019.4.32f1'
9+
default: '2019'
1010
required: true
1111
firebase_cpp_sdk_version:
1212
description: 'Firebase CPP SDK version to build against (The branch, tag or SHA to checkout)'
@@ -81,7 +81,7 @@ jobs:
8181
- name: Setup Unity path
8282
shell: bash
8383
run: |
84-
echo "UNITY_ROOT_DIR=/Applications/Unity_${{ github.event.inputs.unity_version }}" >> $GITHUB_ENV
84+
echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{ github.event.inputs.unity_version }} -k unity_path )" >> $GITHUB_ENV
8585
8686
- name: Build SDK (Android)
8787
shell: bash

.github/workflows/integration_tests.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
inputs:
99
unity_versions:
1010
description: 'Unity version'
11-
default: '2019.4.32f1'
11+
default: '2020,2019,2018,2017'
1212
required: true
1313
platforms:
1414
description: 'CSV of Android,iOS,Windows,macOS,Linux'
@@ -117,12 +117,13 @@ jobs:
117117
echo "::set-output name=ios_device::$( python scripts/gha/print_matrix_configuration.py -w integration_tests ${TEST_MATRIX_PARAM} -k ios_device -t ${mobile_test_on} )"
118118
119119
build:
120-
name: build-${{ matrix.unity_version }}-${{ needs.check_and_prepare.outputs.platform }}
121-
runs-on: macos-latest
120+
name: build-${{matrix.os}}-${{ matrix.unity_version }}-${{ needs.check_and_prepare.outputs.platform }}
121+
runs-on: ${{matrix.os}}
122122
needs: check_and_prepare
123123
strategy:
124124
fail-fast: false
125125
matrix:
126+
os: [macos-latest]
126127
unity_version: ${{ fromJson(needs.check_and_prepare.outputs.matrix_unity_versions) }}
127128
env:
128129
# LC_ALL, LANG and U3D_PASSWORD are needed for U3D.
@@ -134,7 +135,10 @@ jobs:
134135
- name: Install Unity installer (U3D)
135136
timeout-minutes: 10
136137
shell: bash
137-
run: gem install u3d
138+
run: |
139+
gem install u3d
140+
u3d available
141+
u3d available -u ${{ matrix.unity_version }} -p
138142
- name: Setup python
139143
uses: actions/setup-python@v2
140144
with:
@@ -181,7 +185,7 @@ jobs:
181185
unzip -q ~/Downloads/firebase_unity_sdk.zip -d ~/Downloads/
182186
python scripts/gha/build_testapps.py \
183187
--t ${{ needs.check_and_prepare.outputs.apis }} \
184-
--u ${{ matrix.unity_version }} \
188+
--u $( python scripts/gha/print_matrix_configuration.py -u ${{matrix.unity_version}} -k version ) \
185189
--p ${{ needs.check_and_prepare.outputs.platform }} \
186190
--ios_sdk ${{ needs.check_and_prepare.outputs.mobile_test_on }} \
187191
--plugin_dir ~/Downloads/firebase_unity_sdk \

.github/workflows/ios.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
# Which version of Unity to use
88
unity_version:
99
description: 'Unity version'
10-
default: '2019.4.32f1'
10+
default: '2019'
1111
required: true
1212
firebase_cpp_sdk_version:
1313
description: 'Firebase CPP SDK version to build against (The branch, tag or SHA to checkout)'
@@ -70,7 +70,7 @@ jobs:
7070
- name: Setup Unity path
7171
shell: bash
7272
run: |
73-
echo "UNITY_ROOT_DIR=/Applications/Unity_${{ github.event.inputs.unity_version }}" >> $GITHUB_ENV
73+
echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{ github.event.inputs.unity_version }} -k unity_path )" >> $GITHUB_ENV
7474
7575
- name: Build SDK (iOS)
7676
shell: bash

.github/workflows/sdk_build.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@ on:
66
inputs:
77
# Which version of Unity to use
88
unity_version:
9-
description: 'Unity version [2017.4.40f1, 2018.4.36f1, 2019.4.32f1, 2020.3.22f1]'
10-
default: '2019.4.32f1'
11-
required: true
12-
# Linux uses a different number for its versions
13-
linux_unity_version:
14-
description: 'Linux Unity version [2017.4.10f1, 2018.4.36f1, 2019.4.32f1, 2020.3.22f1]'
15-
default: '2019.4.32f1'
9+
description: 'Unity version [2017, 2018, 2019, 2020]'
10+
default: '2019'
1611
required: true
1712
# Additional CMake flags to use
1813
additional_cmake_flags:
@@ -31,17 +26,14 @@ jobs:
3126
include:
3227
- os: macos-latest
3328
unity_version: ${{ github.event.inputs.unity_version }}
34-
unity_install_dir: /Applications/Unity_${{ github.event.inputs.unity_version }}
3529
build_dir: macos_unity
3630
unity_platform_name: macOS,iOS
3731
- os: windows-latest
3832
unity_version: ${{ github.event.inputs.unity_version }}
39-
unity_install_dir: /c/Program Files/Unity_${{ github.event.inputs.unity_version }}
4033
build_dir: windows_unity
4134
unity_platform_name: Windows
4235
- os: ubuntu-latest
43-
unity_version: ${{ github.event.inputs.linux_unity_version }}
44-
unity_install_dir: /opt/unity-editor-${{ github.event.inputs.linux_unity_version }}
36+
unity_version: ${{ github.event.inputs.unity_version }}
4537
build_dir: linux_unity
4638
unity_platform_name: Linux
4739
env:
@@ -116,13 +108,12 @@ jobs:
116108
- name: Install Unity
117109
shell: bash
118110
run: |
119-
u3d available -u ${{ matrix.unity_version }} -p
120111
python scripts/gha/unity_installer.py --install --platforms ${{ matrix.unity_platform_name }} --version ${{ matrix.unity_version }}
121112
122113
- name: Setup Unity path
123114
shell: bash
124115
run: |
125-
echo "UNITY_ROOT_DIR=${{ matrix.unity_install_dir }}" >> $GITHUB_ENV
116+
echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{matrix.unity_version}} -k unity_path )" >> $GITHUB_ENV
126117
echo "$(swig -swiglib)" >> $GITHUB_PATH
127118
swig -swiglib
128119
echo "SWIG_DIR=$(swig -swiglib)" >> $GITHUB_ENV
@@ -146,7 +137,7 @@ jobs:
146137
# ./build_windows_x64.bat ${{ github.event.inputs.additional_cmake_flags }} TODO convert to python script
147138
mkdir ${{ matrix.build_dir }}
148139
pushd ${{ matrix.build_dir }}
149-
cmake .. -G "Visual Studio 16 2019" -A x64 -DFIREBASE_CPP_SDK_DIR="${FIREBASE_CPP_SDK_DIR}" -DUNITY_ROOT_DIR="${{ matrix.unity_install_dir }}" -DSWIG_DIR="$(swig -swiglib)" ${{ github.event.inputs.additional_cmake_flags }}
140+
cmake .. -G "Visual Studio 16 2019" -A x64 -DFIREBASE_CPP_SDK_DIR="${FIREBASE_CPP_SDK_DIR}" -DUNITY_ROOT_DIR="${UNITY_ROOT_DIR}" -DSWIG_DIR="${SWIG_DIR}" ${{ github.event.inputs.additional_cmake_flags }}
150141
echo "=-=-=-=-=-=-=-=-="
151142
echo "Start Build"
152143
echo "=-=-=-=-=-=-=-=-="

scripts/gha/print_matrix_configuration.py

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,21 @@
3737

3838
import argparse
3939
import json
40-
import os
41-
import re
42-
import subprocess
43-
import sys
44-
45-
from integration_testing import config_reader
40+
import platform
4641

4742

4843
DEFAULT_WORKFLOW = "desktop"
4944
EXPANDED_KEY = "expanded"
5045
MINIMAL_KEY = "minimal"
5146

47+
_WINDOWS = "Windows"
48+
_MACOS = "macOS"
49+
_LINUX = "Linux"
50+
5251
PARAMETERS = {
5352
"integration_tests": {
5453
"matrix": {
55-
"unity_version": ["2019.4.32f1"],
54+
"unity_version": ["2019"],
5655
"android_device": ["android_target", "emulator_target"],
5756
"ios_device": ["ios_target", "simulator_target"],
5857

@@ -62,7 +61,7 @@
6261
},
6362

6463
EXPANDED_KEY: {
65-
"unity_version": ["2020.3.22f1", "2019.4.32f1", "2018.4.36f1", "2017.4.40f1", "2017.4.10f1"],
64+
"unity_version": ["2020", "2019", "2018", "2017"],
6665
"android_device": ["android_target", "android_latest", "emulator_target", "emulator_latest", "emulator_32bit"],
6766
"ios_device": ["ios_min", "ios_target", "ios_latest", "simulator_min", "simulator_target", "simulator_latest"],
6867
}
@@ -78,12 +77,64 @@
7877
# Plese use Unity LTS versions: https://unity3d.com/unity/qa/lts-releases
7978
# To list avaliable packages, install u3d, and use cmd "u3d available -u $unity_version -p"
8079
# The packages below is valid only if Unity Hub is not installed.
81-
UNITY_PACKAGES = {
82-
"2020.3.22f1": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-il2cpp"], "macOS": None, "Linux": ["linux-il2cpp"]},
83-
"2019.4.32f1": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["windows-il2cpp"], "macOS": None, "Linux": ["linux-il2cpp"]},
84-
"2018.4.36f1": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-il2cpp"], "macOS": None, "Linux": None},
85-
"2017.4.40f1": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": None, "macOS": None, "Linux": None},
86-
"2017.4.10f1": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows"], "macOS": None, "Linux": None} # For Linux Special
80+
# TODO(@sunmou): Add Android Setting. e.g. NDK_VERSION
81+
UNITY_SETTINGS = {
82+
"2020": {
83+
_WINDOWS: {
84+
"version": "2020.3.22f1",
85+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": None, "macOS": ["Mac-mono"], "Linux": ["Linux-mono"]}
86+
},
87+
_MACOS: {
88+
"version": "2020.3.22f1",
89+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-mono"], "macOS": None, "Linux": ["Linux-mono"]}
90+
},
91+
_LINUX: {
92+
"version": "2020.3.22f1",
93+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-mono"], "macOS": ["Mac-mono"], "Linux": None}
94+
}
95+
},
96+
"2019": {
97+
_WINDOWS: {
98+
"version": "2019.4.32f1",
99+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": None, "macOS": ["Mac-mono"], "Linux": ["Linux-mono"]}
100+
},
101+
_MACOS: {
102+
"version": "2019.4.32f1",
103+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-mono"], "macOS": None, "Linux": ["Linux-mono"]}
104+
},
105+
_LINUX: {
106+
"version": "2019.4.32f1",
107+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-mono"], "macOS": ["Mac-mono"], "Linux": None}
108+
}
109+
},
110+
"2018": {
111+
_WINDOWS: {
112+
"version": "2018.4.36f1",
113+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-il2cpp"], "macOS": ["Mac-mono"], "Linux": ["Linux"]}
114+
},
115+
_MACOS: {
116+
"version": "2018.4.36f1",
117+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-mono"], "macOS": ["Mac-il2cpp"], "Linux": ["Linux"]}
118+
},
119+
_LINUX: {
120+
"version": "2018.4.36f1",
121+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows-mono"], "macOS": ["Mac-mono"], "Linux": None}
122+
}
123+
},
124+
"2017": {
125+
_WINDOWS: {
126+
"version": "2017.4.40f1",
127+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": None, "macOS": ["Mac"], "Linux": ["Linux"]}
128+
},
129+
_MACOS: {
130+
"version": "2017.4.40f1",
131+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows"], "macOS": None, "Linux": ["Linux"]}
132+
},
133+
_LINUX: {
134+
"version": "2017.4.10f1",
135+
"packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "Windows": ["Windows"], "macOS": ["Mac"], "Linux": None}
136+
}
137+
}
87138
}
88139

89140
TEST_DEVICES = {
@@ -103,6 +154,29 @@
103154
}
104155

105156

157+
def get_os():
158+
"""Current Operation System"""
159+
if platform.system() == 'Windows':
160+
return _WINDOWS
161+
elif platform.system() == 'Darwin':
162+
return _MACOS
163+
elif platform.system() == 'Linux':
164+
return _LINUX
165+
166+
167+
def get_unity_path(version):
168+
"""Returns the path to this version of Unity, as generated by U3D."""
169+
# These are the path formats assumed by U3D, as documented here:
170+
# https://github.com/DragonBox/u3d
171+
unity_full_version = UNITY_SETTINGS[version][get_os()]["version"]
172+
if platform.system() == "Windows":
173+
return "/c/Program Files/Unity_%s" % unity_full_version
174+
elif platform.system() == "Darwin":
175+
return "/Applications/Unity_%s" % unity_full_version
176+
elif platform.system() == 'Linux':
177+
return "/opt/unity-editor-%s" % unity_full_version
178+
179+
106180
def get_value(workflow, test_matrix, parm_key, config_parms_only=False):
107181
""" Fetch value from configuration
108182
@@ -168,6 +242,17 @@ def filter_values_on_diff(parm_key, value, auto_diff):
168242

169243
def main():
170244
args = parse_cmdline_args()
245+
if args.unity_version:
246+
if args.parm_key == "unity_path":
247+
print(get_unity_path(args.unity_version))
248+
else:
249+
print(UNITY_SETTINGS[args.unity_version][get_os()].get(args.parm_key))
250+
return
251+
252+
if args.device:
253+
print(TEST_DEVICES.get(args.parm_key).get("type"))
254+
return
255+
171256
if args.override:
172257
# If it is matrix parm, convert CSV string into a list
173258
if not args.config:
@@ -176,10 +261,6 @@ def main():
176261
print_value(args.override)
177262
return
178263

179-
if args.device:
180-
print(TEST_DEVICES.get(args.parm_key).get("type"))
181-
return
182-
183264
if args.expanded:
184265
test_matrix = EXPANDED_KEY
185266
elif args.minimal:
@@ -203,8 +284,9 @@ def parse_cmdline_args():
203284
parser.add_argument('-k', '--parm_key', required=True, help='Print the value of specified key from matrix or config maps.')
204285
parser.add_argument('-a', '--auto_diff', metavar='BRANCH', help='Compare with specified base branch to automatically set matrix options')
205286
parser.add_argument('-o', '--override', help='Override existing value with provided value')
206-
parser.add_argument('-d', '--device', action='store_true', help='Get the device type, used with -k $device')
287+
parser.add_argument('-d', '--device', type=bool, default=False, help='Get the device type, used with -k $device')
207288
parser.add_argument('-t', '--device_type', default=['real', 'virtual'], help='Test on which type of mobile devices')
289+
parser.add_argument('-u', '--unity_version', help='Get unity setting based on unity major version')
208290
args = parser.parse_args()
209291
return args
210292

0 commit comments

Comments
 (0)