diff --git a/.github/workflows/build_android.yml b/.github/workflows/build_android.yml index d20804a54..1d670a65c 100644 --- a/.github/workflows/build_android.yml +++ b/.github/workflows/build_android.yml @@ -42,12 +42,6 @@ jobs: strategy: fail-fast: false env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 CCACHE_DIR: ${{ github.workspace }}/ccache_dir steps: @@ -103,32 +97,16 @@ jobs: echo "NDK_ROOT=/tmp/android-ndk-r21e" >> $GITHUB_ENV echo "ANDROID_NDK_HOME=/tmp/android-ndk-r21e" >> $GITHUB_ENV - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - - name: Install python deps shell: bash run: | pip install -r scripts/gha/requirements.txt - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 15 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install --platforms ${{ inputs.unity_platform_name }} --version ${{ inputs.unity_version }} - - - name: Setup Unity path - shell: bash - run: | - echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{ inputs.unity_version }} -k unity_path )" >> $GITHUB_ENV + version: ${{ inputs.unity_version }} + platforms: ${{ inputs.unity_platform_name }} - name: Display Swig Version shell: bash diff --git a/.github/workflows/build_ios.yml b/.github/workflows/build_ios.yml index b32194880..92d4485b1 100644 --- a/.github/workflows/build_ios.yml +++ b/.github/workflows/build_ios.yml @@ -43,12 +43,6 @@ jobs: fail-fast: false env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 xcodeVersion: "13.3.1" steps: @@ -82,32 +76,16 @@ jobs: python scripts/gha/install_prereqs_desktop.py cd .. - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - - name: Install python deps shell: bash run: | pip install -r scripts/gha/requirements.txt - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 15 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install --platforms ${{ inputs.unity_platform_name }} --version ${{ inputs.unity_version }} - - - name: Setup Unity path - shell: bash - run: | - echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{ inputs.unity_version }} -k unity_path )" >> $GITHUB_ENV + version: ${{ inputs.unity_version }} + platforms: ${{ inputs.unity_platform_name }} - name: Build SDK (iOS) timeout-minutes: 90 diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index 70b3c8baa..7646f7a0e 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -42,13 +42,6 @@ jobs: strategy: fail-fast: false - env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 steps: - uses: actions/checkout@v3 with: @@ -68,14 +61,6 @@ jobs: with: ruby-version: 3.0.2 - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - - name: Setup python uses: actions/setup-python@v4 with: @@ -98,19 +83,15 @@ jobs: run: | sudo apt install openssl - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 15 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install --platforms ${{ inputs.unity_platform_name }} --version ${{ inputs.unity_version }} + version: ${{ inputs.unity_version }} + platforms: ${{ inputs.unity_platform_name }} - - name: Setup Unity path + - name: Setup Swig Env shell: bash run: | - echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{inputs.unity_version}} -k unity_path )" >> $GITHUB_ENV echo "$(swig -swiglib)" >> $GITHUB_PATH swig -swiglib echo "SWIG_DIR=$(swig -swiglib)" >> $GITHUB_ENV diff --git a/.github/workflows/build_macos.yml b/.github/workflows/build_macos.yml index 4393d24d8..1c20c5188 100644 --- a/.github/workflows/build_macos.yml +++ b/.github/workflows/build_macos.yml @@ -41,14 +41,7 @@ jobs: runs-on: macos-latest strategy: fail-fast: false - - env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 + steps: - uses: actions/checkout@v3 with: @@ -68,14 +61,6 @@ jobs: with: ruby-version: 3.0.2 - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - - name: Setup python uses: actions/setup-python@v4 with: @@ -104,19 +89,15 @@ jobs: # brew won't overwrite MacOS system default OpenSSL, so force it here. echo "OPENSSL_ROOT_DIR=$(brew --prefix openssl --installed)" >> $GITHUB_ENV - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 15 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install --platforms ${{ inputs.unity_platform_name }} --version ${{ inputs.unity_version }} + version: ${{ inputs.unity_version }} + platforms: ${{ inputs.unity_platform_name }} - - name: Setup Unity path + - name: Setup Swig Env shell: bash run: | - echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{ inputs.unity_version }} -k unity_path )" >> $GITHUB_ENV echo "$(swig -swiglib)" >> $GITHUB_PATH swig -swiglib echo "SWIG_DIR=$(swig -swiglib)" >> $GITHUB_ENV diff --git a/.github/workflows/build_tvos.yml b/.github/workflows/build_tvos.yml index babd32fa4..13f9e82ff 100644 --- a/.github/workflows/build_tvos.yml +++ b/.github/workflows/build_tvos.yml @@ -64,12 +64,6 @@ jobs: fail-fast: false env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 xcodeVersion: "13.3.1" steps: @@ -103,14 +97,6 @@ jobs: python scripts/gha/install_prereqs_desktop.py cd .. - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - - name: Install python deps shell: bash run: | @@ -122,19 +108,11 @@ jobs: run: | pod repo add cocoapods https://github.com/CocoaPods/Specs.git - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 15 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install --platforms ${{ inputs.unity_platform_name }} --version ${{ inputs.unity_version }} - - - name: Setup Unity path - shell: bash - run: | - echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{ inputs.unity_version }} -k unity_path )" >> $GITHUB_ENV + version: ${{ inputs.unity_version }} + platforms: ${{ inputs.unity_platform_name }} - name: Build SDK (tvOS) timeout-minutes: 90 diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index e1508bb12..34224b102 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -41,14 +41,7 @@ jobs: runs-on: windows-2019 strategy: fail-fast: false - - env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 + steps: - uses: actions/checkout@v3 with: @@ -71,14 +64,6 @@ jobs: with: ruby-version: 3.0.2 - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - - name: Setup python uses: actions/setup-python@v4 with: @@ -104,19 +89,15 @@ jobs: run: | choco install openssl -r - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 15 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install --platforms ${{ inputs.unity_platform_name }} --version ${{ inputs.unity_version }} + version: ${{ inputs.unity_version }} + platforms: ${{ inputs.unity_platform_name }} - - name: Setup Unity path + - name: Setup Swig Env shell: bash run: | - echo "UNITY_ROOT_DIR=$( python scripts/gha/print_matrix_configuration.py -u ${{inputs.unity_version}} -k unity_path )" >> $GITHUB_ENV echo "$(swig -swiglib)" >> $GITHUB_PATH swig -swiglib echo "SWIG_DIR=$(swig -swiglib)" >> $GITHUB_ENV diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 4823ac48b..a3db1bd28 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -164,13 +164,6 @@ jobs: fail-fast: false matrix: ${{ fromJson(needs.check_and_prepare.outputs.build_matrix) }} env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 - # Which xcode version to use xcodeVersion: "13.3.1" steps: - id: matrix_info @@ -178,16 +171,6 @@ jobs: echo "::set-output name=info::${{ matrix.unity_version }}-${{matrix.os}}-${{ matrix.platform }}-${{ matrix.ios_sdk }}" echo "::set-output name=artifact_suffix::${{ matrix.unity_version }}-${{matrix.os}}-${{ matrix.ios_sdk }}" - uses: actions/checkout@v3 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.0.2 - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - name: Setup python uses: actions/setup-python@v4 with: @@ -200,26 +183,14 @@ jobs: - name: setup Xcode version if: runner.os == 'macOS' run: sudo xcode-select -s /Applications/Xcode_${{ env.xcodeVersion }}.app/Contents/Developer - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 30 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install \ - --platforms ${{ matrix.platform }} \ - --version ${{ matrix.unity_version }} - - name: Activate Unity license - timeout-minutes: 10 - shell: bash - run: | - python scripts/gha/unity_installer.py --activate_license \ - --version ${{ matrix.unity_version }} \ - --username "${{ secrets.UNITY_USERNAME }}" \ - --password "${{ secrets.UNITY_PASSWORD }}" \ - --serial_ids "${{ secrets.SERIAL_ID }}" \ - --logfile "testapps/activate_license.log" + version: ${{ matrix.unity_version }} + platforms: ${{ matrix.platform }} + username: ${{ secrets.UNITY_USERNAME }} + password: ${{ secrets.UNITY_PASSWORD }} + serial_ids: ${{ secrets.SERIAL_ID }} - name: Prepare for integration tests timeout-minutes: 10 shell: bash @@ -245,9 +216,9 @@ jobs: fi python scripts/gha/build_testapps.py \ --t ${{ needs.check_and_prepare.outputs.apis }} \ - --u $( python scripts/gha/print_matrix_configuration.py -k version -u ${{matrix.unity_version}}) \ - --p ${{ matrix.platform }} \ - --ios_sdk ${{ matrix.ios_sdk }} \ + --u "${{ steps.unity_setup.outputs.unity_version }}" \ + --p "${{ matrix.platform }}" \ + --ios_sdk "${{ matrix.ios_sdk }}" \ --plugin_dir ~/Downloads/firebase_unity_sdk \ --output_directory "${{ github.workspace }}" \ --artifact_name "${{ steps.matrix_info.outputs.info }}" \ @@ -256,17 +227,10 @@ jobs: - name: Return Unity license # Always returns true, even when job failed or canceled. But will not run when a critical failure prevents the task from running. if: always() - # Retry at most 3 times when Return Unity license fails. - uses: nick-invision/retry@v2 + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --release_license \ - --version ${{ matrix.unity_version }} \ - --logfile "testapps/release_license.log" - cat testapps/release_license.log + version: ${{ matrix.unity_version }} + release_license: "true" - name: Prepare results summary artifact if: ${{ !cancelled() }} shell: bash @@ -370,28 +334,11 @@ jobs: strategy: fail-fast: false matrix: ${{ fromJson(needs.check_and_prepare.outputs.playmode_matrix) }} - env: - # LC_ALL, LANG and U3D_PASSWORD are needed for U3D. - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - U3D_PASSWORD: "" - # Disable checking for U3D updates, since it is buggy - U3D_SKIP_UPDATE_CHECK: 1 steps: - id: matrix_info run: | echo "::set-output name=info::${{ matrix.unity_version }}-${{matrix.os}}-Playmode-github_runner-${{ matrix.os }}" - uses: actions/checkout@v3 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.0.2 - - name: Install Unity installer (U3D) - uses: nick-invision/retry@v2 - with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: gem install u3d -v 1.2.3 - name: Setup python uses: actions/setup-python@v4 with: @@ -401,25 +348,13 @@ jobs: shell: bash run: | pip install -r scripts/gha/requirements.txt - - name: Install Unity - uses: nick-invision/retry@v2 + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 20 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --install \ - --version ${{ matrix.unity_version }} - - name: Activate Unity license - timeout-minutes: 10 - shell: bash - run: | - python scripts/gha/unity_installer.py --activate_license \ - --version ${{ matrix.unity_version }} \ - --username "${{ secrets.UNITY_USERNAME }}" \ - --password "${{ secrets.UNITY_PASSWORD }}" \ - --serial_ids "${{ secrets.SERIAL_ID }}" \ - --logfile "testapps/activate_license.log" + version: ${{ matrix.unity_version }} + username: ${{ secrets.UNITY_USERNAME }} + password: ${{ secrets.UNITY_PASSWORD }} + serial_ids: ${{ secrets.SERIAL_ID }} - name: Prepare for integration tests timeout-minutes: 10 shell: bash @@ -443,7 +378,7 @@ jobs: fi python scripts/gha/build_testapps.py \ --t ${{ needs.check_and_prepare.outputs.apis }} \ - --u $( python scripts/gha/print_matrix_configuration.py -k version -u ${{matrix.unity_version}}) \ + --u ${{ steps.unity_setup.outputs.unity_version }} \ --p Playmode \ --plugin_dir ~/Downloads/firebase_unity_sdk \ --output_directory "${{ github.workspace }}" \ @@ -453,17 +388,10 @@ jobs: - name: Return Unity license # Always returns true, even when job failed or canceled. But will not run when a critical failure prevents the task from running. if: always() - # Retry at most 3 times when Return Unity license fails. - uses: nick-invision/retry@v2 + uses: firebase/firebase-unity-sdk/gha/unity@main with: - timeout_minutes: 10 - max_attempts: 3 - shell: bash - command: | - python scripts/gha/unity_installer.py --release_license \ - --version ${{ matrix.unity_version }} \ - --logfile "testapps/release_license.log" - cat testapps/release_license.log + version: ${{ matrix.unity_version }} + release_license: "true" - name: Prepare results summary artifact if: ${{ !cancelled() }} shell: bash diff --git a/gha/unity/README.md b/gha/unity/README.md new file mode 100644 index 000000000..90aa1b9f9 --- /dev/null +++ b/gha/unity/README.md @@ -0,0 +1,109 @@ +# `unity-setup` GitHub Action + +## Inputs +- `version`: **[Required]** Unity Major Version Number. Currently supported values: [2019, 2020]. + +- `platforms`: Platforms that you'd like to support, if not provided, some platforms may encounter errors. Values: [Android,iOS,tvOS,Windows,macOS,Linux]. + +- `username`: Required when Activate Unity license. Refer to the Usage section below. + +- `password`: Required when Activate Unity license. Refer to the Usage section below. + +- `serial_ids`: Required when Activate Unity license. Refer to the Usage section below. + +- `release_license`: If a license has been activated in the pervious step, then **must** add anothe step and set **"ture"** to `release_license` input. + +## Output + +This GitHub Action will provide `unity_version` (full unity version) output and `UNITY_ROOT_DIR` (Unity project directory) environment variable + +- Output usage: + ```yml + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main + with: + version: ${{ unity_version }} + platforms: ${{ platforms }} + - run: | + echo '${{ steps.unity_setup.outputs.unity_version }}' + echo '$UNITY_ROOT_DIR' + ``` + +## Usage +- Install Unity without Activation + ```yml + jobs: + build_sdk: + # ... + + steps: + # ... + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main + with: + version: ${{ unity_version }} + platforms: ${{ platforms }} + ``` + +- Install Unity, Activate and Release Unity License + ```yml + jobs: + build_testapp: + # ... + + steps: + # ... + - id: unity_setup + uses: firebase/firebase-unity-sdk/gha/unity@main + with: + version: ${{ unity_version }} + platforms: ${{ platforms }} + username: ${{ secrets.UNITY_USERNAME }} + password: ${{ secrets.UNITY_PASSWORD }} + serial_ids: ${{ secrets.SERIAL_ID }} + # ... + - id: release_license + uses: firebase/firebase-unity-sdk/gha/unity@main + with: + version: ${{ unity_version }} + release_license: "true" + ``` + +## How to upgrade supported unity versions +**Background** + +This GitHub Action leverages [U3D](github.com/DragonBox/u3d), which is a command line tool for working with Unity from the command line on all three operating systems. + +In this GitHub Action, supported Unity Versions are maintained by `UNITY_SETTINGS` in `gha/unity/unity_installer.py`. + +**Add a new Unity version support** + +1. Install [U3D](github.com/DragonBox/u3d). + +2. Generate new JSON string and added it to `UNITY_SETTINGS`: + - `Major_version_number`: unity major version number: 2020, 2021, etc. + - `Full_version_number`: unity full version number. e.g. 2020.3.34f1 for major version 2020. Run `u3d available` and select [Unity LTS versions](https://unity3d.com/unity/qa/lts-releases). + - `Platform`: Values of [Android,iOS,tvOS,Windows,macOS,Linux] + - `Package`:[Unity Hub must **not** been installed] Unity Packages that required for certain platform. e.g. ["Windows-mono"] pakcages for "Windows" platform. To list avaliable packages, run `u3d available -u $unity_version -p`. + + ``` + UNITY_SETTINGS = { + Major_version_number: { + OS: { + "version": Full_version_number, + "packages": {Platform: [Package], ...}, + }, + ... + }, + } + ``` + +**Common failures & solutions** + +1. If you met problem with `u3d` cmd (e.g. `u3d available -u $unity_version -p`), please install older version of `u3d` and disable the `u3d` version check. Then try it again. + ``` + gem install u3d -v 1.2.3 + export U3D_SKIP_UPDATE_CHECK=1 + ``` + +2. If you have problem with Android build. Make sure you are using the right version of NDK and JDK. Testapp building process is using a patch function `patch_android_env` in `build_testapp.py`. (Please refer [Unity Documentation](https://docs.unity3d.com/Manual/android-sdksetup.html) for Android environment setup). diff --git a/gha/unity/action.yml b/gha/unity/action.yml new file mode 100644 index 000000000..05e1b325b --- /dev/null +++ b/gha/unity/action.yml @@ -0,0 +1,90 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: 'Unity Setup' +inputs: + version: + required: true + platforms: + required: false + username: + required: false + password: + required: false + serial_ids: + required: false + release_license: + required: false + +outputs: + unity_version: + value: ${{ steps.unity_installation.outputs.unity_version }} + +runs: + using: 'composite' + steps: + - name: Return Unity license + if: inputs.release_license + uses: nick-invision/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 2 + shell: bash + command: | + python $GITHUB_ACTION_PATH/unity_installer.py --release_license \ + --version ${{ inputs.version }} \ + --logfile "testapps/release_license.log" + cat testapps/release_license.log + - name: Install Unity installer (U3D) + if: inputs.release_license == '' + uses: nick-invision/retry@v2 + with: + timeout_minutes: 10 + max_attempts: 2 + shell: bash + command: gem install u3d -v 1.2.3 + - name: Set the Unity Env + if: inputs.release_license == '' + shell: bash + run: | + echo "LC_ALL=en_US.UTF-8" >> $GITHUB_ENV + echo "LANG=en_US.UTF-8" >> $GITHUB_ENV + echo "U3D_PASSWORD=" >> $GITHUB_ENV + echo "U3D_SKIP_UPDATE_CHECK=1" >> $GITHUB_ENV + - id: unity_installation + name: Install Unity + if: inputs.release_license == '' + uses: nick-invision/retry@v2 + with: + timeout_minutes: 12 + max_attempts: 2 + shell: bash + command: | + if [[ -n "${{ inputs.platforms }}" ]]; then + additional_flags+=(--platforms ${{ inputs.platforms }}) + fi + unity_info=$( python $GITHUB_ACTION_PATH/unity_installer.py --install --version ${{ inputs.version }} ${additional_flags[*]} ) + echo "UNITY_ROOT_DIR=$(cut -d',' -f2 <<< ${unity_info})" >> $GITHUB_ENV + echo "unity_version=$(cut -d',' -f1 <<< ${unity_info})" >> $GITHUB_OUTPUT + - name: Activate Unity license + if: inputs.release_license == '' && inputs.username != '' && inputs.password != '' && inputs.serial_ids != '' + shell: bash + run: | + python $GITHUB_ACTION_PATH/unity_installer.py --activate_license \ + --version ${{ inputs.version }} \ + --username "${{ inputs.username }}" \ + --password "${{ inputs.password }}" \ + --serial_ids "${{ inputs.serial_ids }}" \ + --logfile "testapps/activate_license.log" + cat testapps/activate_license.log diff --git a/scripts/gha/unity_installer.py b/gha/unity/unity_installer.py similarity index 78% rename from scripts/gha/unity_installer.py rename to gha/unity/unity_installer.py index 4a752cfce..30b32a2c2 100644 --- a/scripts/gha/unity_installer.py +++ b/gha/unity/unity_installer.py @@ -80,20 +80,52 @@ from absl import flags from absl import logging -from print_matrix_configuration import UNITY_SETTINGS - _CMD_TIMEOUT = 900 _DEFALUT = "Default" _ANDROID = "Android" _IOS = "iOS" -_TVOS ="tvOS" +_TVOS = "tvOS" _WINDOWS = "Windows" _MACOS = "macOS" _LINUX = "Linux" _SUPPORTED_PLATFORMS = (_ANDROID, _IOS, _TVOS, _WINDOWS, _MACOS, _LINUX) +# Plese use Unity LTS versions: https://unity3d.com/unity/qa/lts-releases +# To list avaliable packages, install u3d, and use cmd "u3d available -u $unity_version -p" +# The packages below is valid only if Unity Hub is not installed. +UNITY_SETTINGS = { + "2020": { + _WINDOWS: { + "version": "2020.3.34f1", + "packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "tvOS": ["appletv"], "Windows": None, "macOS": ["Mac-mono"], "Linux": ["Linux-mono"]}, + }, + _MACOS: { + "version": "2020.3.34f1", + "packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "tvOS": ["appletv"], "Windows": ["Windows-mono"], "macOS": None, "Linux": ["Linux-mono"]}, + }, + _LINUX: { + "version": "2020.3.40f1", + "packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "tvOS": None, "Windows": ["Windows-mono"], "macOS": ["Mac-mono"], "Linux": None} + } + }, + "2019": { + _WINDOWS: { + "version": "2019.4.39f1", + "packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "tvOS": ["appletv"], "Windows": None, "macOS": ["Mac-mono"], "Linux": ["Linux-mono"]}, + }, + _MACOS: { + "version": "2019.4.39f1", + "packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "tvOS": ["appletv"], "Windows": ["Windows-mono"], "macOS": None, "Linux": ["Linux-mono"]}, + }, + _LINUX: { + "version": "2019.4.40f1", + "packages": {"Default": ["Unity"], "Android": ["Android"], "iOS": ["Ios"], "tvOS": ["appletv"], "Windows": ["Windows-mono"], "macOS": ["Mac-mono"], "Linux": None} + } + }, +} + FLAGS = flags.FLAGS # These are the three actions supported by the tool. @@ -182,6 +214,10 @@ def install_unity(unity_version, platforms): "-p", package_csv]) logging.info("Finished installing Unity.") + unity_path = get_unity_path(unity_version) + logging.info("unity_path: %s", unity_path) + print("%s,%s" % (unity_full_version, unity_path)) + def uninstall_unity(unity_version): """Uninstalls Unity and build supports (packages).""" @@ -200,7 +236,7 @@ def activate_license(username, password, serial_ids, logfile, unity_version): # succeeds. This has occurred e.g. in Unity 2019.3.15 on Mac. # To handle this case, we check the Unity logs for the message indicating # successful activation and ignore the error in that case. - unity = get_unity_path(unity_version) + unity = get_unity_executable(unity_version) logging.info("Found %d licenses. Attempting each.", len(serial_ids)) for i, serial_id in enumerate(serial_ids): logging.info("Attempting license %d", i) @@ -231,7 +267,7 @@ def activate_license(username, password, serial_ids, logfile, unity_version): def release_license(logfile, unity_version): """Releases the Unity license. Requires finding an installation of Unity.""" - unity = get_unity_path(unity_version) + unity = get_unity_executable(unity_version) run([unity, "-quit", "-batchmode", "-returnlicense", "-logfile", logfile]) logging.info("Unity license released.") @@ -256,7 +292,7 @@ def get_os(): return _LINUX -def get_unity_path(version): +def get_unity_executable(version): """Returns the path to this version of Unity, as generated by U3D.""" # These are the path formats assumed by U3D, as documented here: # https://github.com/DragonBox/u3d @@ -271,10 +307,25 @@ def get_unity_path(version): raise RuntimeError("Only Windows and MacOS are supported.") +def get_unity_path(version): + """Returns the path to this version of Unity, as generated by U3D.""" + # These are the path formats assumed by U3D, as documented here: + # https://github.com/DragonBox/u3d + full_version = UNITY_SETTINGS[version][get_os()]["version"] + if platform.system() == "Windows": + return "/c/Program Files/Unity_%s" % full_version + elif platform.system() == "Darwin": + return "/Applications/Unity_%s" % full_version + elif platform.system() == 'Linux': + return "/opt/unity-editor-%s" % full_version + + def run(args, check=True, timeout=_CMD_TIMEOUT): """Runs args in a subprocess, throwing an error on non-zero return code.""" logging.info("run cmd: %s", " ".join(args)) - subprocess.run(args=args, check=check, timeout=timeout) + result = subprocess.run(args=args, check=check, timeout=timeout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + logging.info(result.stdout) + logging.info(result.stderr) if __name__ == "__main__": diff --git a/scripts/gha/build_testapps.py b/scripts/gha/build_testapps.py index 60f4c91a6..2414614f6 100644 --- a/scripts/gha/build_testapps.py +++ b/scripts/gha/build_testapps.py @@ -105,7 +105,6 @@ from integration_testing import unity_finder from integration_testing import unity_version from integration_testing import xcodebuild -from print_matrix_configuration import UNITY_SETTINGS # Used in specifying whether xcodebuild should build for device or simulator _DEVICE_REAL = "real" @@ -488,8 +487,18 @@ def build_testapp(dir_helper, api_config, ios_config, target): def patch_android_env(unity_version): major_version = int(unity_version.split(".")[0]) # Set ndk env - if UNITY_SETTINGS[str(major_version)][get_desktop_platform()]["ndk"]: - url = UNITY_SETTINGS[str(major_version)][get_desktop_platform()]["ndk"] + UNITY_SETTINGS = { + "2020": { + _WINDOWS: "https://dl.google.com/android/repository/android-ndk-r19-windows-x86_64.zip", + _MACOS: "https://dl.google.com/android/repository/android-ndk-r19-darwin-x86_64.zip", + }, + "2019": { + _WINDOWS: "https://dl.google.com/android/repository/android-ndk-r19-windows-x86_64.zip", + _MACOS: "https://dl.google.com/android/repository/android-ndk-r19-darwin-x86_64.zip", + }, + } + url = UNITY_SETTINGS[str(major_version)][get_desktop_platform()] + if url: logging.info("install ndk: %s", url) ndk_zip_path = "ndk_zip" ndk_path = "ndk" diff --git a/scripts/gha/print_matrix_configuration.py b/scripts/gha/print_matrix_configuration.py index 58067c111..34121ab1c 100644 --- a/scripts/gha/print_matrix_configuration.py +++ b/scripts/gha/print_matrix_configuration.py @@ -37,7 +37,6 @@ import argparse import json -import logging import platform import itertools @@ -87,45 +86,6 @@ }, } -# Plese use Unity LTS versions: https://unity3d.com/unity/qa/lts-releases -# To list avaliable packages, install u3d, and use cmd "u3d available -u $unity_version -p" -# The packages below is valid only if Unity Hub is not installed. -# TODO(@sunmou): Add Android Setting. e.g. NDK_VERSION -UNITY_SETTINGS = { - "2020": { - WINDOWS: { - "version": "2020.3.34f1", - "packages": {"Default": ["Unity"], ANDROID: ["Android"], IOS: ["Ios"], TVOS: ["appletv"], WINDOWS: None, MACOS: ["Mac-mono"], LINUX: ["Linux-mono"]}, - "ndk": "https://dl.google.com/android/repository/android-ndk-r19-windows-x86_64.zip" - }, - MACOS: { - "version": "2020.3.34f1", - "packages": {"Default": ["Unity"], ANDROID: ["Android"], IOS: ["Ios"], TVOS: ["appletv"], WINDOWS: ["Windows-mono"], MACOS: None, LINUX: ["Linux-mono"]}, - "ndk": "https://dl.google.com/android/repository/android-ndk-r19-darwin-x86_64.zip" - }, - LINUX: { - "version": "2020.3.40f1", - "packages": {"Default": ["Unity"], ANDROID: ["Android"], IOS: ["Ios"], TVOS: None, WINDOWS: ["Windows-mono"], MACOS: ["Mac-mono"], LINUX: None} - } - }, - "2019": { - WINDOWS: { - "version": "2019.4.39f1", - "packages": {"Default": ["Unity"], ANDROID: ["Android"], IOS: ["Ios"], TVOS: ["appletv"], WINDOWS: None, MACOS: ["Mac-mono"], LINUX: ["Linux-mono"]}, - "ndk": "https://dl.google.com/android/repository/android-ndk-r19-windows-x86_64.zip" - }, - MACOS: { - "version": "2019.4.39f1", - "packages": {"Default": ["Unity"], ANDROID: ["Android"], IOS: ["Ios"], TVOS: ["appletv"], WINDOWS: ["Windows-mono"], MACOS: None, LINUX: ["Linux-mono"]}, - "ndk": "https://dl.google.com/android/repository/android-ndk-r19-darwin-x86_64.zip" - }, - LINUX: { - "version": "2019.4.40f1", - "packages": {"Default": ["Unity"], ANDROID: ["Android"], IOS: ["Ios"], TVOS: ["appletv"], WINDOWS: ["Windows-mono"], MACOS: ["Mac-mono"], LINUX: None} - } - }, -} - BUILD_CONFIGS = ["Unity Version(s)", "Build OS(s)", "Platform(s)", "Test Device(s)"] TEST_DEVICES = { @@ -156,19 +116,6 @@ def get_os(): return LINUX -def get_unity_path(version): - """Returns the path to this version of Unity, as generated by U3D.""" - # These are the path formats assumed by U3D, as documented here: - # https://github.com/DragonBox/u3d - unity_full_version = UNITY_SETTINGS[version][get_os()]["version"] - if platform.system() == "Windows": - return "/c/Program Files/Unity_%s" % unity_full_version - elif platform.system() == "Darwin": - return "/Applications/Unity_%s" % unity_full_version - elif platform.system() == 'Linux': - return "/opt/unity-editor-%s" % unity_full_version - - def get_value(workflow, matrix_type, parm_key, config_parms_only=False): """ Fetch value from configuration @@ -367,12 +314,6 @@ def _get_test_os(platform, mobile_device_type=""): def main(): args = parse_cmdline_args() - if args.unity_version: - if args.parm_key == "unity_path": - print(get_unity_path(args.unity_version)) - else: - print(UNITY_SETTINGS[args.unity_version][get_os()].get(args.parm_key)) - return if args.override: # If it is matrix parm, convert CSV string into a list @@ -406,7 +347,6 @@ def parse_cmdline_args(): parser.add_argument('-k', '--parm_key', help='Print the value of specified key from matrix or config maps.') parser.add_argument('-a', '--auto_diff', metavar='BRANCH', help='Compare with specified base branch to automatically set matrix options') parser.add_argument('-o', '--override', help='Override existing value with provided value') - parser.add_argument('-u', '--unity_version', help='Get unity setting based on unity major version. Used with "-k $unity_setting -u $unity_major_version"') parser.add_argument('-playmode_matrix', action='store_true', help='Generate the playmode matrix for integration_test workflow') parser.add_argument('-build_matrix', action='store_true', help='Generate the build matrix for integration_test workflow') parser.add_argument('-test_matrix', action='store_true', help='Generate the test matrix for integration_test workflow')