From c7d01461eddf3fc288c77a43aca2b69187991287 Mon Sep 17 00:00:00 2001 From: Joni Savolainen Date: Wed, 5 Jul 2023 18:09:20 +0300 Subject: [PATCH] ci: add Github pipeline for tests and builds * ci: add Github pipeline for tests and builds * fix(core): catch exceptions from Repository.IsValid * chore(project): add SampleScene to build settings --- .github/workflows/ci.yml | 78 +++++++++++++++++++ .../Core/Services/RepositoryService.cs | 9 ++- ProjectSettings/EditorBuildSettings.asset | 5 +- 3 files changed, 90 insertions(+), 2 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 0000000..a7dfac3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,78 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: {} + +jobs: + buildAndTestForLinux: + name: Build & Test for ${{ matrix.targetPlatform }} on ${{ matrix.unityVersion }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + unityVersion: + - 2021.3.26f1 + - 2022.3.3f1 + - 2023.1.2f1 + targetPlatform: + - StandaloneLinux64 + - StandaloneWindows64 + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/cache@v3 + with: + path: Library + key: Library-${{ matrix.targetPlatform }}-${{ matrix.unityVersion }}-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} + restore-keys: | + Library-${{ matrix.targetPlatform }}-${{ matrix.unityVersion }}- + Library-${{ matrix.targetPlatform }}- + Library- + + - uses: game-ci/unity-test-runner@v2 + id: testRunner + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + with: + testMode: EditMode + unityVersion: ${{ matrix.unityVersion }} + githubToken: ${{ secrets.GITHUB_TOKEN }} + customParameters: -debugCodeOptimization -enableCodeCoverage -coverageResultsPath ./CodeCoverage -coverageOptions "useProjectSettings;generateAdditionalMetrics" + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: Test results (all modes) + path: ${{ steps.testRunner.outputs.artifactsPath }} + + - name: Upload code coverage to Codecov + uses: codecov/codecov-action@v3 + with: + name: Tests + flags: automated + token: ${{ secrets.CODECOV_TOKEN }} + files: CodeCoverage/**/*.xml + + - name: Commit Unity project changes + run: | + git config --global user.name 'github-bot' + git config --global user.email 'github-bot@users.noreply.github.com' + git add -A + git commit -m "chore(ci): switch to different unity version" || echo skipping commit + + - uses: game-ci/unity-builder@v2 + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} + with: + unityVersion: ${{ matrix.unityVersion }} + targetPlatform: ${{ matrix.targetPlatform }} diff --git a/Packages/io.savolainen.unitygit/Core/Services/RepositoryService.cs b/Packages/io.savolainen.unitygit/Core/Services/RepositoryService.cs index 7675204..0d170b6 100644 --- a/Packages/io.savolainen.unitygit/Core/Services/RepositoryService.cs +++ b/Packages/io.savolainen.unitygit/Core/Services/RepositoryService.cs @@ -33,8 +33,15 @@ public IRepository GetProjectRepository() if (!Directory.Exists(gitRepositoryPath)) return null; - if (!Repository.IsValid(gitRepositoryPath)) + try + { + if (!Repository.IsValid(gitRepositoryPath)) + return null; + } + catch + { return null; + } return new Repository(gitRepositoryPath); } diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 0147887..40917b0 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -4,5 +4,8 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 - m_Scenes: [] + m_Scenes: + - enabled: 1 + path: Assets/Scenes/SampleScene.unity + guid: 9fc0d4010bbf28b4594072e72b8655ab m_configObjects: {}