ci: fix coverage permissions and paths #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Unity Tests | |
on: | |
push: | |
branches: # Only run jobs if files changed on this branch | |
- master | |
paths: # Only run jobs if files changed at these paths | |
- '.github/workflows/**' | |
- 'Assets/**' | |
- 'Packages/**' | |
- 'ProjectSettings/**' | |
- 'ci/**' | |
env: | |
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
jobs: | |
# Run the Unity tests | |
tests: | |
name: Run ${{ matrix.unity-version }} tests | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
unity-version: | |
- 2021.3.45f1 | |
- 2022.3.55f1 | |
- 2023.2.20f1 | |
- 6000.0.32f1 | |
steps: | |
# Checkout the repo | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
lfs: true | |
fetch-depth: 0 | |
# Cache library folder for faster tests | |
- name: Cache library | |
uses: actions/cache@v4 | |
with: | |
path: Library | |
key: Library-${{ matrix.unity-version }} | |
# Run tests | |
- name: Run tests | |
uses: game-ci/unity-test-runner@v4 | |
id: tests | |
with: | |
unityVersion: ${{ matrix.unity-version }} | |
coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;assemblyFilters:+Hertzole.ScriptableValues' | |
sonarscan: | |
needs: [tests] | |
name: SonarScan | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
lfs: true | |
fetch-depth: 0 | |
- name: Cache library | |
uses: actions/cache@v4 | |
with: | |
path: Library | |
key: Library-Scanner | |
restore-keys: | | |
Library-Scanner | |
- name: Install .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: | | |
8.x | |
- name: Install Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
- name: Install scanner | |
run: dotnet tool install dotnet-sonarscanner --tool-path . --version 6.0.0 | |
- name: Run tests | |
uses: game-ci/unity-test-runner@v4 | |
id: tests | |
with: | |
unityVersion: auto | |
coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;assemblyFilters:+Hertzole.ScriptableValues' | |
# Copy coverage files to a new path so we can fix the paths. | |
- name: Copy coverage files | |
run: cp -r ${{ steps.tests.outputs.coveragePath }} Coverage | |
# The test results have a different path than what SonarQube can read. | |
# We need to remove the github/workspace/ path. | |
- name: Fix paths | |
run: | | |
chmod +x ./ci/fix_paths.sh | |
./ci/fix_paths.sh Coverage | |
- name: SonarQube analysis | |
env: | |
FrameworkPathOverride: /opt/unity/Editor/Data/MonoBleedingEdge/ | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
./dotnet-sonarscanner begin \ | |
/o:"hertzole" \ | |
/k:"scriptable-values" \ | |
/d:sonar.host.url=https://sonarcloud.io \ | |
/d:sonar.verbose=false \ | |
/d:sonar.token=$SONAR_TOKEN \ | |
/d:sonar.cs.nunit.reportsPaths=${{ steps.tests.outputs.artifactsPath }}/**.xml \ | |
/d:sonar.cs.opencover.reportsPaths=Coverage/workspace-opencov/**.xml | |
dotnet build scriptable-values.sln | |
./dotnet-sonarscanner end /d:sonar.token=$SONAR_TOKEN |