Skip to content

Commit

Permalink
Merge pull request #71 from nowsprinting/chore/fix_test_workflow
Browse files Browse the repository at this point in the history
Mod run tests as embedded package on CI
  • Loading branch information
nowsprinting authored Apr 28, 2024
2 parents eebba86 + d270be7 commit 8f12462
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
29 changes: 16 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Koji Hasegawa.
# Copyright (c) 2023-2024 Koji Hasegawa.
# This software is released under the MIT License.

name: Test
Expand All @@ -18,6 +18,9 @@ on:
- '.github/**'
- '!.github/workflows/test.yml'

env:
PACKAGE_NAME: com.nowsprinting.test-helper

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -42,12 +45,6 @@ jobs:
octocov: true

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: false
lfs: false

- name: Crete project for tests
uses: nowsprinting/create-unity-project-action@v3
with:
Expand All @@ -60,22 +57,26 @@ jobs:
restore-keys: |
Library-
- name: Set package name
run: |
echo "package_name=$(grep -o -E '"name": "(.+)"' ./package.json | cut -d ' ' -f2)" >> "$GITHUB_ENV"
- name: Checkout repository as embedded package
uses: actions/checkout@v4
with:
submodules: false
lfs: false
path: ${{ env.CREATED_PROJECT_PATH }}/Packages/${{ env.PACKAGE_NAME }}
# In Linux editor, there is a problem that assets in local packages cannot be found with `AssetDatabase.FindAssets`.
# As a workaround, I have made it into an embedded package.

- name: Install dependencies
run: |
npm install -g openupm-cli
openupm add -f com.unity.test-framework
openupm add -f com.unity.testtools.codecoverage
openupm add -f com.cysharp.unitask
openupm add -ft "${{ env.package_name }}"@file:../../
working-directory: ${{ env.CREATED_PROJECT_PATH }}

- name: Set coverage assembly filters
run: |
assemblies=$(find . -name "*.asmdef" -maxdepth 3 | sed -e s/.*\\//\+/ | sed -e s/\\.asmdef// | sed -e s/^.*\\.Tests//)
assemblies=$(find ${{ env.CREATED_PROJECT_PATH }}/Packages/${{ env.PACKAGE_NAME }} -name "*.asmdef" | sed -e s/.*\\//\+/ | sed -e s/\\.asmdef// | sed -e s/^.*\\.Tests//)
# shellcheck disable=SC2001,SC2048,SC2086
echo "assembly_filters=$(echo ${assemblies[*]} | sed -e s/\ /,/g),+<assets>,-*.Tests" >> "$GITHUB_ENV"
Expand All @@ -99,7 +100,9 @@ jobs:
id: test

- name: Set coverage path for octocov
run: sed -i -r 's/\.\/Logs/${{ steps.test.outputs.coveragePath }}/' .octocov.yml
run: |
mv ${{ env.CREATED_PROJECT_PATH }}/Packages/${{ env.PACKAGE_NAME }}/.octocov.yml .
sed -i -r 's/UnityProject~\/Logs/${{ steps.test.outputs.coveragePath }}/' .octocov.yml
if: ${{ matrix.octocov }}

- name: Run octocov
Expand Down
16 changes: 9 additions & 7 deletions .octocov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
coverage:
if: true
paths:
- ./Logs/Report/lcov.info # Warning: This path is replace by regex in test.yml
- UnityProject~/Logs/Report/lcov.info # Warning: This path is to be replaced by regex in test.yml

codeToTestRatio:
code:
- 'Editor/**/*.cs'
- 'Runtime/**/*.cs'
- 'Samples~/**/*.cs'
- '!Samples~/**/Tests/**/*.cs'
- '**/*.cs'
- '!**/Tests/**'
- '!UnityProject~/Library/**'
test:
- 'Tests/**/*.cs'
- 'Samples~/**/Tests/**/*.cs'
- '**/Tests/**/*.cs'
- '!UnityProject~/Library/**'

testExecutionTime:
if: true

diff:
datastores:
- artifact://${GITHUB_REPOSITORY}
Expand Down

0 comments on commit 8f12462

Please sign in to comment.