ci: generate coverage report before sonarqube #57
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' | |
# Upload test results | |
- name: Upload test results | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: Test results - ${{ matrix.unity-version }} | |
path: ${{ steps.tests.outputs.artifactsPath }} | |
# Upload coverage results | |
- name: Upload test results | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: Coverage results - ${{ matrix.unity-version }} | |
path: ${{ steps.tests.outputs.coveragePath }} | |
sonarscan: | |
needs: [tests] | |
name: SonarScan | |
runs-on: ubuntu-latest | |
container: unityci/editor:ubuntu-6000.0.32f1-base-3.1.0 | |
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 . | |
# Download the coverage results | |
- name: Download coverage results | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: 'Coverage results - *' | |
path: Coverage | |
- name: Generate report | |
uses: danielpalme/ReportGenerator-GitHub-Action@v5 | |
with: | |
reports: "Coverage/**.xml" | |
targetdir: "CoverageReport" | |
reporttypes: "Html;Badges" | |
- name: Upload report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: CoverageReport | |
- name: Activate Unity | |
continue-on-error: true | |
env: | |
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
run: | | |
echo "$UNITY_LICENSE" | tr -d '\r' > License.ulf | |
unity-editor -nographics -logFile /dev/stdout -manualLicenseFile License.ulf -quit | |
- name: Generate Solution | |
run: | | |
unity-editor -nographics -logFile /dev/stdout -customBuildName scriptable-values -projectPath . -executeMethod Packages.Rider.Editor.RiderScriptEditor.SyncSolution -quit | |
ls | |
# 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 | |
dotnet build scriptable-values.sln | |
./dotnet-sonarscanner end /d:sonar.token=$SONAR_TOKEN |