From 8b46049c64145bae13eae4797a46bae854670c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sierpi=C5=84ski?= <33436839+sierpinskid@users.noreply.github.com> Date: Mon, 4 Dec 2023 20:22:00 +0100 Subject: [PATCH 1/4] Setup CI to run tests on every PR to develop or main --- .github/workflows/ci.yml | 286 ++++++++++++++++++ .../StreamVideoLowLevelClient.cs | 9 +- .../Tests/Editor/StreamVideo.Tests.asmdef | 2 +- 3 files changed, 293 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c020b476 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,286 @@ +name: CI - Run Tests + Build Sample App + +on: + pull_request: + branches: [ main, develop ] + push: + branches: [ main, develop ] + + workflow_dispatch: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + +jobs: + testRunner: + strategy: + fail-fast: false + matrix: + os: [macos-latest] + unity_version: [2021.3.0] + dotnet_version: [NET_4_x, STANDARD_2_x] + compiler: [mono, il2cpp] + target_platform: [standalone, mobile] + name: Run tests + Build Sample APp + runs-on: ${{ matrix.os }} + timeout-minutes: 600 + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Print chipset + shell: bash + run: uname -m + continue-on-error: true + + - name: Set up Node.js 16 + uses: actions/setup-node@v1 + with: + node-version: 16 + + - uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Print python version + shell: bash + run: python --version + continue-on-error: true + + - name: Install node package, `unity-license-activate` + run: npm install --global https://github.com/sierpinskid/unity-license-activate + + - name: Install node package, `unity-verify-code` + run: npm install --global https://github.com/sierpinskid/unity-verify-code + + - name: Download Unity & Modules + if: ${{ matrix.os }} == 'macos-latest' + shell: bash + run: | + if [[ ${{ matrix.unity_version }} == '2021.3.0' ]] + then + curl -L -o ~/Unity.pkg https://download.unity3d.com/download_unity/6eacc8284459/MacEditorInstaller/Unity.pkg + + if [[ ${{ matrix.compiler }} == 'il2cpp' ]] + then + curl -L -o ~/UnityIL2CPPModule.pkg https://download.unity3d.com/download_unity/6eacc8284459/MacEditorTargetInstaller/UnitySetup-Mac-IL2CPP-Support-for-Editor-2021.3.0f1.pkg + fi + + if [[ ${{ matrix.target_platform }} == 'mobile' ]] + then + curl -L -o ~/UnityIosModule.pkg https://download.unity3d.com/download_unity/6eacc8284459/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-2021.3.0f1.pkg + fi + fi + + - name: Install Unity + uses: nick-fields/retry@v2 + with: + timeout_minutes: 15 + max_attempts: 3 + shell: bash + command: sudo installer -package ~/Unity.pkg -target / + + - name: Instal IL2CPP Module + if: matrix.compiler == 'il2cpp' + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 3 + shell: bash + command: sudo installer -package ~/UnityIL2CPPModule.pkg -target / + + - name: Instal Mobile Module + if: matrix.target_platform == 'mobile' + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 3 + shell: bash + command: sudo installer -package ~/UnityIosModule.pkg -target / + + - name: Create Test Results dir + shell: bash + run: mkdir test_results + + - name: Generate .ALF license file + shell: bash + run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -createManualActivationFile -quit + continue-on-error: true #Unity return exit code 1 even if successfully creating license file + + - name: List dir + shell: bash + run: | + ls + grep ".alf$" + ULF_FILE_PATH=$(ls | grep ".alf$") + echo $ULF_FILE_PATH + continue-on-error: true + + - name: Ensure code file exists + shell: bash + run: touch ./code.txt + continue-on-error: true + + - name: Activate .ALF License - Get .ULF file + id: generate_ulf_license_attempt_1 + shell: bash + run: sudo unity-license-activate "${{ secrets.UNITY_ACCOUNT_USER }}" "${{ secrets.UNITY_ACCOUNT_PASS }}" "$(ls | grep ".alf$")" --password "${{ secrets.EMAIL_PASS }}" --host "imap.gmail.com" + timeout-minutes: 25 + continue-on-error: true + + - name: Activate .ALF License - Get .ULF file - Attempt 2 + if: steps.generate_ulf_license_attempt_1.outcome == 'failure' + id: generate_ulf_license_attempt_2 + shell: bash + run: sudo unity-license-activate "${{ secrets.UNITY_ACCOUNT_USER }}" "${{ secrets.UNITY_ACCOUNT_PASS }}" "$(ls | grep ".alf$")" --password "${{ secrets.EMAIL_PASS }}" --host "imap.gmail.com" + timeout-minutes: 25 + continue-on-error: true + + - name: Activate .ALF License - Get .ULF file - Attempt 3 + if: steps.generate_ulf_license_attempt_2.outcome == 'failure' + id: generate_ulf_license_attempt_3 + shell: bash + run: sudo unity-license-activate "${{ secrets.UNITY_ACCOUNT_USER }}" "${{ secrets.UNITY_ACCOUNT_PASS }}" "$(ls | grep ".alf$")" --password "${{ secrets.EMAIL_PASS }}" --host "imap.gmail.com" + timeout-minutes: 25 + continue-on-error: true + + - name: 🩺 Upload error screenshot + if: steps.generate_ulf_license_attempt_1.outcome == 'failure' + uses: actions/upload-artifact@v1 + continue-on-error: true + with: + name: screenshot_error_1 + path: error.png + + - name: 🩺 Upload error screenshot 2 + if: steps.generate_ulf_license_attempt_2.outcome == 'failure' + uses: actions/upload-artifact@v1 + continue-on-error: true + with: + name: screenshot_error_2 + path: error.png + + - name: 🩺 Upload error screenshot 3 + if: steps.generate_ulf_license_attempt_3.outcome == 'failure' + uses: actions/upload-artifact@v1 + continue-on-error: true + with: + name: screenshot_error_3 + path: error.png + + - name: Activate Unity with .ULF license file + shell: bash + run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -manualLicenseFile "$(ls | grep ".ulf$")" -quit + continue-on-error: true #Unity return exit code 1 even if successfully activating with license file + + - name: LS Unity Logs dir + shell: bash + run: ls ~/Library/Logs/Unity/ + continue-on-error: true + + - name: Print Audit Unity Logs + shell: bash + run: cat ~/Library/Logs/Unity/Unity.Entitlements.Audit.log + continue-on-error: true + + - name: Print Client Unity Logs + shell: bash + run: cat ~/Library/Logs/Unity/Unity.Licensing.Client.log + continue-on-error: true + + - name: Print Unity Editor Logs + shell: bash + run: cat ~/Library/Logs/Unity/Editor.log + continue-on-error: true + + - name: Enable Stream Tests in Unity + shell: bash + run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -projectPath "$GITHUB_WORKSPACE" -executeMethod StreamChat.EditorTools.StreamEditorTools.EnableStreamTestsEnabledCompilerFlag -quit + +#skip -quit due to not working with async tests + - name: Run Unity Tests + id: run_unity_tests + shell: bash + run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -projectPath "$GITHUB_WORKSPACE" -runTests -testResults ~/test_results/results.xml -streamBase64TestDataSet ${{ secrets.STREAM_AUTH_TEST_DATA_BASE64 }} + continue-on-error: true + +#due to skipped -quit + - name: Force Close Unity + shell: bash + run: sudo pkill -x Unity + continue-on-error: true + + - name: Print Test Results + if: always() + shell: bash + run: cat ~/test_results/results.xml + + - name: Print Unity Logs + shell: bash + run: cat ~/Library/Logs/Unity/Editor.log + continue-on-error: true + + - name: Generate HTML test report + uses: rempelj/nunit-html-action@v1.0.1 + if: always() + with: + inputXmlPath: ~/test_results/results.xml + outputHtmlPath: ~/test_results/results.html + + - name: Upload tests results XML Artifact + uses: actions/upload-artifact@v3 + if: always() + with: + name: ${{ matrix.os }}_${{ matrix.unity_version }}_${{ matrix.compiler }}_${{ matrix.dotnet_version }}_${{ matrix.target_platform }}_test_results.xml + path: ~/test_results/results.xml + + - name: Upload tests results Html Artifact + uses: actions/upload-artifact@v3 + if: always() + with: + name: ${{ matrix.os }}_${{ matrix.unity_version }}_${{ matrix.compiler }}_${{ matrix.dotnet_version }}_${{ matrix.target_platform }}_test_results.html + path: ~/test_results/results.html + + - name: Validate All Tests Passed + if: steps.run_unity_tests.outcome == 'failure' + run: exit 1 + + - name: Generate GH Summary Comment + uses: sierpinskid/nunit-github-comment@v1 + if: github.event_name == 'pull_request' + with: + inputXmlPath: ~/test_results/results.xml + outputFilePath: ~/test_results/gh_comment.txt + + - name: Set GH Comment as variable + if: github.event_name == 'pull_request' + id: generate_gh_comment + run: echo "::set-output name=gh_comment::$(cat ~/test_results/gh_comment.txt)" + + - name: Build Sample App + shell: bash + run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -projectPath "$GITHUB_WORKSPACE" -executeMethod "StreamChat.EditorTools.StreamEditorTools.BuildSampleApp" -streamBase64TestDataSet ${{ secrets.STREAM_AUTH_TEST_DATA_BASE64 }} -apiCompatibility ${{ matrix.dotnet_version }} -scriptingBackend ${{ matrix.compiler }} -buildTargetPlatform ${{ matrix.target_platform }} -buildTargetPath "~/SampleAppBuild/App" -quit + + - name: LS + shell: bash + run: | + ls + echo '----' + ls ~ + echo '----' + ls "~/SampleAppBuild/" + echo '----' + ls "~/SampleAppBuild/App/" + echo '----' + continue-on-error: true + + - name: Upload Sample App + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.os }}_${{ matrix.unity_version }}_${{ matrix.compiler }}_${{ matrix.dotnet_version }}_${{ matrix.target_platform }}_sample_app + path: ~/SampleAppBuild/App/ + diff --git a/Packages/StreamVideo/Runtime/Core/LowLevelClient/StreamVideoLowLevelClient.cs b/Packages/StreamVideo/Runtime/Core/LowLevelClient/StreamVideoLowLevelClient.cs index 83633840..66dddfeb 100644 --- a/Packages/StreamVideo/Runtime/Core/LowLevelClient/StreamVideoLowLevelClient.cs +++ b/Packages/StreamVideo/Runtime/Core/LowLevelClient/StreamVideoLowLevelClient.cs @@ -26,16 +26,19 @@ using StreamVideo.Libs.Utils; using StreamVideo.Libs.Websockets; -#if STREAM_TESTS_ENABLED -[assembly: InternalsVisibleTo("StreamVideo.Tests")] //StreamTodo: verify which Unity version introduced this +#if UNITY_EDITOR || STREAM_TESTS_ENABLED +using System.Runtime.CompilerServices; #endif #if UNITY_EDITOR -using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("StreamVideo.EditorTools")] [assembly: InternalsVisibleTo("StreamVideo.Tests")] #endif +#if STREAM_TESTS_ENABLED +[assembly: InternalsVisibleTo("StreamVideo.Tests")] +#endif + namespace StreamVideo.Core.LowLevelClient { /// diff --git a/Packages/StreamVideo/Tests/Editor/StreamVideo.Tests.asmdef b/Packages/StreamVideo/Tests/Editor/StreamVideo.Tests.asmdef index 28490c6c..6500b95c 100644 --- a/Packages/StreamVideo/Tests/Editor/StreamVideo.Tests.asmdef +++ b/Packages/StreamVideo/Tests/Editor/StreamVideo.Tests.asmdef @@ -2,7 +2,7 @@ "name": "StreamVideo.Tests", "rootNamespace": "", "references": [ - "Stream.Core" + "StreamVideo.Core" ], "includePlatforms": [ "Editor" From bbdba8cb31b711393fc8a36387fd32f4c3a048aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sierpi=C5=84ski?= <33436839+sierpinskid@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:53:29 +0100 Subject: [PATCH 2/4] [CI/CD] Change Unity versions + remove Mono testing (webRTC requires IL2CPP) + temp remove building sample app --- .github/workflows/ci.yml | 49 ++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c020b476..9fa46a0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,9 +21,9 @@ jobs: fail-fast: false matrix: os: [macos-latest] - unity_version: [2021.3.0] + unity_version: [2021.3.27, 2022.3.4] dotnet_version: [NET_4_x, STANDARD_2_x] - compiler: [mono, il2cpp] + compiler: [il2cpp] target_platform: [standalone, mobile] name: Run tests + Build Sample APp runs-on: ${{ matrix.os }} @@ -61,18 +61,31 @@ jobs: if: ${{ matrix.os }} == 'macos-latest' shell: bash run: | - if [[ ${{ matrix.unity_version }} == '2021.3.0' ]] + if [[ ${{ matrix.unity_version }} == '2021.3.27' ]] then - curl -L -o ~/Unity.pkg https://download.unity3d.com/download_unity/6eacc8284459/MacEditorInstaller/Unity.pkg + curl -L -o ~/Unity.pkg https://download.unity3d.com/download_unity/ca3ffb99bcc6/MacEditorInstaller/Unity.pkg if [[ ${{ matrix.compiler }} == 'il2cpp' ]] then - curl -L -o ~/UnityIL2CPPModule.pkg https://download.unity3d.com/download_unity/6eacc8284459/MacEditorTargetInstaller/UnitySetup-Mac-IL2CPP-Support-for-Editor-2021.3.0f1.pkg + curl -L -o ~/UnityIL2CPPModule.pkg https://download.unity3d.com/download_unity/ca3ffb99bcc6/MacEditorTargetInstaller/UnitySetup-Mac-IL2CPP-Support-for-Editor-2021.3.27f1.pkg fi if [[ ${{ matrix.target_platform }} == 'mobile' ]] then - curl -L -o ~/UnityIosModule.pkg https://download.unity3d.com/download_unity/6eacc8284459/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-2021.3.0f1.pkg + curl -L -o ~/UnityIosModule.pkg https://download.unity3d.com/download_unity/ca3ffb99bcc6/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-2021.3.27f1.pkg + fi + elif [[ ${{ matrix.unity_version }} == '2022.3.4' ]] + then + curl -L -o ~/Unity.pkg https://download.unity3d.com/download_unity/1fb1bf06830e/MacEditorInstaller/Unity.pkg + + if [[ ${{ matrix.compiler }} == 'il2cpp' ]] + then + curl -L -o ~/UnityIL2CPPModule.pkg https://download.unity3d.com/download_unity/1fb1bf06830e/MacEditorTargetInstaller/UnitySetup-Mac-IL2CPP-Support-for-Editor-2020.3.30f1.pkg + fi + + if [[ ${{ matrix.target_platform }} == 'mobile' ]] + then + curl -L -o ~/UnityIosModule.pkg https://download.unity3d.com/download_unity/1fb1bf06830e/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-2020.3.30f1.pkg fi fi @@ -260,27 +273,5 @@ jobs: if: github.event_name == 'pull_request' id: generate_gh_comment run: echo "::set-output name=gh_comment::$(cat ~/test_results/gh_comment.txt)" - - - name: Build Sample App - shell: bash - run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -projectPath "$GITHUB_WORKSPACE" -executeMethod "StreamChat.EditorTools.StreamEditorTools.BuildSampleApp" -streamBase64TestDataSet ${{ secrets.STREAM_AUTH_TEST_DATA_BASE64 }} -apiCompatibility ${{ matrix.dotnet_version }} -scriptingBackend ${{ matrix.compiler }} -buildTargetPlatform ${{ matrix.target_platform }} -buildTargetPath "~/SampleAppBuild/App" -quit - - - name: LS - shell: bash - run: | - ls - echo '----' - ls ~ - echo '----' - ls "~/SampleAppBuild/" - echo '----' - ls "~/SampleAppBuild/App/" - echo '----' - continue-on-error: true - - - name: Upload Sample App - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.os }}_${{ matrix.unity_version }}_${{ matrix.compiler }}_${{ matrix.dotnet_version }}_${{ matrix.target_platform }}_sample_app - path: ~/SampleAppBuild/App/ + From 84c0963f20caf93373a58b08cfff66af9b58c6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sierpi=C5=84ski?= <33436839+sierpinskid@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:36:13 +0100 Subject: [PATCH 3/4] Update download urls + fix executeMethod namespace --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fa46a0d..d3770b4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,16 +76,16 @@ jobs: fi elif [[ ${{ matrix.unity_version }} == '2022.3.4' ]] then - curl -L -o ~/Unity.pkg https://download.unity3d.com/download_unity/1fb1bf06830e/MacEditorInstaller/Unity.pkg + curl -L -o ~/Unity.pkg https://download.unity3d.com/download_unity/35713cd46cd7/MacEditorInstaller/Unity.pkg if [[ ${{ matrix.compiler }} == 'il2cpp' ]] then - curl -L -o ~/UnityIL2CPPModule.pkg https://download.unity3d.com/download_unity/1fb1bf06830e/MacEditorTargetInstaller/UnitySetup-Mac-IL2CPP-Support-for-Editor-2020.3.30f1.pkg + curl -L -o ~/UnityIL2CPPModule.pkg https://download.unity3d.com/download_unity/35713cd46cd7/MacEditorTargetInstaller/UnitySetup-Mac-IL2CPP-Support-for-Editor-2022.3.4f1.pkg fi if [[ ${{ matrix.target_platform }} == 'mobile' ]] then - curl -L -o ~/UnityIosModule.pkg https://download.unity3d.com/download_unity/1fb1bf06830e/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-2020.3.30f1.pkg + curl -L -o ~/UnityIosModule.pkg https://download.unity3d.com/download_unity/35713cd46cd7/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-2022.3.4f1.pkg fi fi @@ -212,7 +212,7 @@ jobs: - name: Enable Stream Tests in Unity shell: bash - run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -projectPath "$GITHUB_WORKSPACE" -executeMethod StreamChat.EditorTools.StreamEditorTools.EnableStreamTestsEnabledCompilerFlag -quit + run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -projectPath "$GITHUB_WORKSPACE" -executeMethod StreamVideo.EditorTools.StreamEditorTools.EnableStreamTestsEnabledCompilerFlag -quit #skip -quit due to not working with async tests - name: Run Unity Tests From 6843028dbc98cf859569f81252b173b59bbcae5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sierpi=C5=84ski?= <33436839+sierpinskid@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:30:03 +0100 Subject: [PATCH 4/4] [CI/CD] Add sample app building step --- .github/workflows/ci.yml | 25 ++- Packages/StreamVideo/Editor/Builders.meta | 8 + .../Editor/Builders/ApiCompatibility.cs | 8 + .../Editor/Builders/ApiCompatibility.cs.meta | 3 + .../Editor/Builders/BuildSettings.cs | 25 +++ .../Editor/Builders/BuildSettings.cs.meta | 3 + .../Editor/Builders/BuildTargetPlatform.cs | 8 + .../Builders/BuildTargetPlatform.cs.meta | 3 + .../Editor/Builders/ScriptingBackend.cs | 7 + .../Editor/Builders/ScriptingBackend.cs.meta | 3 + .../Editor/Builders/StreamAppBuilder.cs | 68 +++++++++ .../Editor/Builders/StreamAppBuilder.cs.meta | 3 + .../StreamVideo/Editor/CommandLineParser.cs | 144 ++++++++++++++++++ .../Editor/CommandLineParser.cs.meta | 11 ++ .../DefineSymbols/IUnityDefineSymbols.cs | 2 +- .../DefineSymbols/Unity2020DefineSymbols.cs | 2 +- .../DefineSymbols/Unity2021DefineSymbols.cs | 2 +- .../UnityDefineSymbolsFactory.cs | 2 +- .../StreamVideo/Editor/StreamEditorTools.cs | 13 +- .../StreamVideo/Editor/TestAuthDataSet.cs | 2 +- 20 files changed, 335 insertions(+), 7 deletions(-) create mode 100644 Packages/StreamVideo/Editor/Builders.meta create mode 100644 Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs create mode 100644 Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs.meta create mode 100644 Packages/StreamVideo/Editor/Builders/BuildSettings.cs create mode 100644 Packages/StreamVideo/Editor/Builders/BuildSettings.cs.meta create mode 100644 Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs create mode 100644 Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs.meta create mode 100644 Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs create mode 100644 Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs.meta create mode 100644 Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs create mode 100644 Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs.meta create mode 100644 Packages/StreamVideo/Editor/CommandLineParser.cs create mode 100644 Packages/StreamVideo/Editor/CommandLineParser.cs.meta diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3770b4e..e1d520cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -272,6 +272,29 @@ jobs: - name: Set GH Comment as variable if: github.event_name == 'pull_request' id: generate_gh_comment - run: echo "::set-output name=gh_comment::$(cat ~/test_results/gh_comment.txt)" + run: echo "::set-output name=gh_comment::$(cat ~/test_results/gh_comment.txt)" + + - name: Build Sample App + shell: bash + run: sudo /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -nographics -projectPath "$GITHUB_WORKSPACE" -executeMethod "StreamVideo.EditorTools.StreamEditorTools.BuildSampleApp" -streamBase64TestDataSet ${{ secrets.STREAM_AUTH_TEST_DATA_BASE64 }} -apiCompatibility ${{ matrix.dotnet_version }} -scriptingBackend ${{ matrix.compiler }} -buildTargetPlatform ${{ matrix.target_platform }} -buildTargetPath "~/SampleAppBuild/App" -quit + + - name: LS + shell: bash + run: | + ls + echo '----' + ls ~ + echo '----' + ls "~/SampleAppBuild/" + echo '----' + ls "~/SampleAppBuild/App/" + echo '----' + continue-on-error: true + + - name: Upload Sample App + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.os }}_${{ matrix.unity_version }}_${{ matrix.compiler }}_${{ matrix.dotnet_version }}_${{ matrix.target_platform }}_sample_app + path: ~/SampleAppBuild/App/ diff --git a/Packages/StreamVideo/Editor/Builders.meta b/Packages/StreamVideo/Editor/Builders.meta new file mode 100644 index 00000000..847ffaa1 --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ccea428704014554fa78ad79451331eb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs b/Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs new file mode 100644 index 00000000..9b9349c2 --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs @@ -0,0 +1,8 @@ +namespace StreamVideo.EditorTools.Builders +{ + public enum ApiCompatibility + { + NET_4_x, + STANDARD_2_x + } +} \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs.meta b/Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs.meta new file mode 100644 index 00000000..6b44535b --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/ApiCompatibility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 351c8cbd983a486ab8b579c5b9376765 +timeCreated: 1655821999 \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/BuildSettings.cs b/Packages/StreamVideo/Editor/Builders/BuildSettings.cs new file mode 100644 index 00000000..374fd94f --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/BuildSettings.cs @@ -0,0 +1,25 @@ +using UnityEditor; + +namespace StreamVideo.EditorTools.Builders +{ + public readonly struct BuildSettings + { + public BuildTargetGroup BuildTargetGroup { get; } + public ApiCompatibilityLevel ApiCompatibilityLevel { get; } + public ScriptingImplementation ScriptingImplementation { get; } + public string TargetPath { get; } + + public BuildSettings(BuildTargetGroup buildTargetGroup, ApiCompatibilityLevel apiCompatibilityLevel, + ScriptingImplementation scriptingImplementation, string targetPath) + { + BuildTargetGroup = buildTargetGroup; + ApiCompatibilityLevel = apiCompatibilityLevel; + ScriptingImplementation = scriptingImplementation; + TargetPath = targetPath; + } + + public override string ToString() => + $"{nameof(BuildSettings)} - {nameof(BuildTargetGroup)}: {BuildTargetGroup}, {nameof(ApiCompatibilityLevel)}: {ApiCompatibilityLevel}, " + + $"{nameof(ScriptingImplementation)}: {ScriptingImplementation}, {nameof(TargetPath)}: {TargetPath}"; + } +} \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/BuildSettings.cs.meta b/Packages/StreamVideo/Editor/Builders/BuildSettings.cs.meta new file mode 100644 index 00000000..17cb7057 --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/BuildSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6ba46c1c6986496c801f86952f89109c +timeCreated: 1655821335 \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs b/Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs new file mode 100644 index 00000000..4514bb51 --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs @@ -0,0 +1,8 @@ +namespace StreamVideo.EditorTools.Builders +{ + public enum BuildTargetPlatform + { + Standalone, + Mobile + } +} \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs.meta b/Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs.meta new file mode 100644 index 00000000..da26cc40 --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/BuildTargetPlatform.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9f5f0943f0394daca2b043d47df44190 +timeCreated: 1655821999 \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs b/Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs new file mode 100644 index 00000000..72d7435e --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs @@ -0,0 +1,7 @@ +namespace StreamVideo.EditorTools.Builders +{ + public enum ScriptingBackend + { + IL2CPP + } +} \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs.meta b/Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs.meta new file mode 100644 index 00000000..df3a2a4e --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/ScriptingBackend.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 61abcfc8c7a34b27a42ff73d9588586f +timeCreated: 1655821999 \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs b/Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs new file mode 100644 index 00000000..7dabc5bc --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace StreamVideo.EditorTools.Builders +{ + public class StreamAppBuilder + { + public void BuildSampleApp(BuildSettings settings) + { + var buildTarget = GetBuildTargetFromGroup(settings.BuildTargetGroup); + + PlayerSettings.SetApiCompatibilityLevel(settings.BuildTargetGroup, settings.ApiCompatibilityLevel); + PlayerSettings.SetScriptingBackend(settings.BuildTargetGroup, settings.ScriptingImplementation); + EditorUserBuildSettings.SwitchActiveBuildTarget(settings.BuildTargetGroup, buildTarget); + EditorUserBuildSettings.SetBuildLocation(buildTarget, settings.TargetPath); + + var sceneAssetPath = AssetDatabase.GUIDToAssetPath(SampleAppSceneGuid); + if (!File.Exists(sceneAssetPath)) + { + throw new ArgumentException($"Failed to find scene with guid: `{SampleAppSceneGuid}` and path: `{sceneAssetPath}`"); + } + + var options = new BuildPlayerOptions + { + scenes = new string[] + { + sceneAssetPath + }, + locationPathName = settings.TargetPath, + targetGroup = settings.BuildTargetGroup, + target = buildTarget, + }; + + Debug.Log("Building sample app with settings: " + settings); + + BuildPipeline.BuildPlayer(options); + } + + private const string SampleAppSceneGuid = "2e20276ba7f7641ae944f77c47a6d9da"; + + private static BuildTarget GetBuildTargetFromGroup(BuildTargetGroup buildTargetGroup) + { + if (buildTargetGroup == BuildTargetGroup.Android) + { + return BuildTarget.Android; + } + if (buildTargetGroup == BuildTargetGroup.iOS) + { + return BuildTarget.iOS; + } + if (buildTargetGroup == BuildTargetGroup.Standalone) + { +#if UNITY_EDITOR_WIN + return BuildTarget.StandaloneWindows64; +#elif UNITY_EDITOR_OSX + return BuildTarget.StandaloneOSX; + +#elif UNITY_EDITOR_LINUX + return BuildTarget.StandaloneLinux64; +#endif + } + + throw new NotImplementedException(buildTargetGroup.ToString()); + } + } +} \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs.meta b/Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs.meta new file mode 100644 index 00000000..0a01f807 --- /dev/null +++ b/Packages/StreamVideo/Editor/Builders/StreamAppBuilder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ec318ca59f7248f1a3a4520e72b3bd8c +timeCreated: 1655807886 \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/CommandLineParser.cs b/Packages/StreamVideo/Editor/CommandLineParser.cs new file mode 100644 index 00000000..7e385fa8 --- /dev/null +++ b/Packages/StreamVideo/Editor/CommandLineParser.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using StreamVideo.EditorTools.Builders; +using UnityEditor; + +namespace StreamVideo.EditorTools +{ + public class CommandLineParser + { + public const string ApiCompatibilityArgKey = "-apiCompatibility"; + public const string ScriptingBackendArgKey = "-scriptingBackend"; + public const string BuildTargetPlatformArgKey = "-buildTargetPlatform"; + public const string BuildTargetPathArgKey = "-buildTargetPath"; + + public BuildSettings GetParsedBuildArgs() + { + var args = GetParsedCommandLineArguments(); + + if (IsAnyRequiredArgMissing(args, out var missingArgsInfo, BuildTargetPlatformArgKey, + ApiCompatibilityArgKey, ScriptingBackendArgKey, BuildTargetPathArgKey)) + { + throw new ArgumentException($"Missing argument: `{missingArgsInfo}`"); + } + + if (!Enum.TryParse(args[BuildTargetPlatformArgKey], ignoreCase: true, + out var targetPlatform)) + { + throw new ArgumentException( + $"Failed to parse argument: `{args[BuildTargetPlatformArgKey]}` to enum: {typeof(BuildTargetPlatform)}"); + } + + if (!Enum.TryParse(args[ApiCompatibilityArgKey], ignoreCase: true, + out var apiCompatibility)) + { + throw new ArgumentException( + $"Failed to parse argument: `{args[ApiCompatibilityArgKey]}` to enum: {typeof(ApiCompatibility)}"); + } + + if (!Enum.TryParse(args[ScriptingBackendArgKey], ignoreCase: true, + out var scriptingBackend)) + { + throw new ArgumentException( + $"Failed to parse argument: `{args[ScriptingBackendArgKey]}` to enum: {typeof(ScriptingBackend)}"); + } + + var buildTargetGroup = GetBuildTargetGroup(targetPlatform); + var apiCompatibilityLevel = GetApiCompatibilityLevel(apiCompatibility); + var scriptingImplementation = GetScriptingImplementation(scriptingBackend); + var targetPath = args[BuildTargetPathArgKey]; + + return new BuildSettings(buildTargetGroup, apiCompatibilityLevel, scriptingImplementation, targetPath); + } + + public IDictionary GetParsedCommandLineArguments() + { + var result = new Dictionary(); + ParseCommandLineArguments(Environment.GetCommandLineArgs(), result); + + return result; + } + + public void ParseCommandLineArguments(string[] args, IDictionary result) + => ParseCommandLineArguments(args, _ => result.Add(_.Key, _.Value)); + + public void ParseCommandLineArguments(string[] args, Action<(string Key, string Value)> onArgumentParsed) + { + for (int i = 0; i < args.Length; i++) + { + if (args[i].StartsWith("-")) + { + var key = args[i]; + var value = i < args.Length - 1 ? args[i + 1] : ""; + + onArgumentParsed?.Invoke((key, value)); + } + } + } + + private static bool IsAnyRequiredArgMissing(IDictionary args, out string missingArgsInfo, + params string[] argKeys) + { + var missingKeys = new List(); + + foreach (var key in argKeys) + { + if (!args.ContainsKey(key)) + { + missingKeys.Add(key); + } + } + + missingArgsInfo = missingKeys.Count == 0 ? string.Empty : string.Join(", ", missingKeys); + return missingKeys.Count != 0; + } + + private BuildTargetGroup GetBuildTargetGroup(BuildTargetPlatform targetPlatform) + { + if (targetPlatform == BuildTargetPlatform.Standalone) + { + return BuildTargetGroup.Standalone; + } + +#if UNITY_STANDALONE_OSX + return BuildTargetGroup.iOS; +#else + return BuildTargetGroup.Android; +#endif + } + + private ApiCompatibilityLevel GetApiCompatibilityLevel(ApiCompatibility apiCompatibility) + { +#if UNITY_2021 + + switch (apiCompatibility) + { + case ApiCompatibility.NET_4_x: return ApiCompatibilityLevel.NET_Unity_4_8; + case ApiCompatibility.STANDARD_2_x: return ApiCompatibilityLevel.NET_Standard_2_0; + default: + throw new ArgumentOutOfRangeException(nameof(apiCompatibility), apiCompatibility, null); + } + +#else + switch (apiCompatibility) + { + case ApiCompatibility.NET_4_x: return ApiCompatibilityLevel.NET_4_6; + case ApiCompatibility.STANDARD_2_x: return ApiCompatibilityLevel.NET_Standard_2_0; + default: + throw new ArgumentOutOfRangeException(nameof(apiCompatibility), apiCompatibility, null); + } + +#endif + } + + private ScriptingImplementation GetScriptingImplementation(ScriptingBackend scriptingBackend) + { + switch (scriptingBackend) + { + case ScriptingBackend.IL2CPP: return ScriptingImplementation.IL2CPP; + default: + throw new ArgumentOutOfRangeException(nameof(scriptingBackend), scriptingBackend, null); + } + } + } +} \ No newline at end of file diff --git a/Packages/StreamVideo/Editor/CommandLineParser.cs.meta b/Packages/StreamVideo/Editor/CommandLineParser.cs.meta new file mode 100644 index 00000000..764e6c40 --- /dev/null +++ b/Packages/StreamVideo/Editor/CommandLineParser.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6a4e7043ca669fb4ea362c56a9963265 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/StreamVideo/Editor/DefineSymbols/IUnityDefineSymbols.cs b/Packages/StreamVideo/Editor/DefineSymbols/IUnityDefineSymbols.cs index 9255ec57..9759e3e4 100644 --- a/Packages/StreamVideo/Editor/DefineSymbols/IUnityDefineSymbols.cs +++ b/Packages/StreamVideo/Editor/DefineSymbols/IUnityDefineSymbols.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEditor; -namespace StreamChat.EditorTools.DefineSymbols +namespace StreamVideo.EditorTools.DefineSymbols { public interface IUnityDefineSymbols { diff --git a/Packages/StreamVideo/Editor/DefineSymbols/Unity2020DefineSymbols.cs b/Packages/StreamVideo/Editor/DefineSymbols/Unity2020DefineSymbols.cs index a01b1fb3..e65b4ea9 100644 --- a/Packages/StreamVideo/Editor/DefineSymbols/Unity2020DefineSymbols.cs +++ b/Packages/StreamVideo/Editor/DefineSymbols/Unity2020DefineSymbols.cs @@ -3,7 +3,7 @@ using System.Linq; using UnityEditor; -namespace StreamChat.EditorTools.DefineSymbols +namespace StreamVideo.EditorTools.DefineSymbols { public class Unity2020DefineSymbols : IUnityDefineSymbols { diff --git a/Packages/StreamVideo/Editor/DefineSymbols/Unity2021DefineSymbols.cs b/Packages/StreamVideo/Editor/DefineSymbols/Unity2021DefineSymbols.cs index 9454e2b7..d421a5bd 100644 --- a/Packages/StreamVideo/Editor/DefineSymbols/Unity2021DefineSymbols.cs +++ b/Packages/StreamVideo/Editor/DefineSymbols/Unity2021DefineSymbols.cs @@ -3,7 +3,7 @@ using UnityEditor; using UnityEditor.Build; -namespace StreamChat.EditorTools.DefineSymbols +namespace StreamVideo.EditorTools.DefineSymbols { public class Unity2021DefineSymbols : IUnityDefineSymbols { diff --git a/Packages/StreamVideo/Editor/DefineSymbols/UnityDefineSymbolsFactory.cs b/Packages/StreamVideo/Editor/DefineSymbols/UnityDefineSymbolsFactory.cs index 347520ad..176e1078 100644 --- a/Packages/StreamVideo/Editor/DefineSymbols/UnityDefineSymbolsFactory.cs +++ b/Packages/StreamVideo/Editor/DefineSymbols/UnityDefineSymbolsFactory.cs @@ -1,4 +1,4 @@ -namespace StreamChat.EditorTools.DefineSymbols +namespace StreamVideo.EditorTools.DefineSymbols { public class UnityDefineSymbolsFactory { diff --git a/Packages/StreamVideo/Editor/StreamEditorTools.cs b/Packages/StreamVideo/Editor/StreamEditorTools.cs index 91042398..cd536589 100644 --- a/Packages/StreamVideo/Editor/StreamEditorTools.cs +++ b/Packages/StreamVideo/Editor/StreamEditorTools.cs @@ -1,7 +1,8 @@ using System; using System.Linq; using StreamVideo.Core.LowLevelClient; -using StreamChat.EditorTools.DefineSymbols; +using StreamVideo.EditorTools.Builders; +using StreamVideo.EditorTools.DefineSymbols; using UnityEditor; using UnityEngine; @@ -20,6 +21,16 @@ public static void ToggleStreamDebugModeCompilerFlag() public static void ToggleStreamLocalSfuCompilerFlag() => ToggleCompilerFlag(StreamLocalSfuModeEnabledCompilerFlag); + public static void BuildSampleApp() + { + var parser = new CommandLineParser(); + var builder = new StreamAppBuilder(); + + var buildSettings = parser.GetParsedBuildArgs(); + + builder.BuildSampleApp(buildSettings); + } + public static void EnableStreamTestsEnabledCompilerFlag() => SetStreamTestsEnabledCompilerFlag(StreamTestsEnabledCompilerFlag, true); diff --git a/Packages/StreamVideo/Editor/TestAuthDataSet.cs b/Packages/StreamVideo/Editor/TestAuthDataSet.cs index 32aaf198..c84ea1b6 100644 --- a/Packages/StreamVideo/Editor/TestAuthDataSet.cs +++ b/Packages/StreamVideo/Editor/TestAuthDataSet.cs @@ -4,7 +4,7 @@ using StreamVideo.Libs.Auth; using Random = UnityEngine.Random; -namespace StreamChat.EditorTools +namespace StreamVideo.EditorTools { public struct TestAuthDataSet {