SonarCloud: Improve workflow (#23080)
* SonarCloud: allow unit test failures without failing the analysis Test failures should not block SonarCloud analysis - coverage data is still collected by dotnet-coverage regardless of test outcome. The regular CI pipeline is the correct gate for test pass/fail. * SonarCloud: install Java 21 explicitly and skip JRE provisioning - Add actions/setup-java@v5 (temurin-21) so JAVA_HOME always points to Java 21 - Pass sonar.scanner.skipJreProvisioning=true in the begin command since Java 21 is installed explicitly, removing the need for the scanner to download a JRE at runtime * SonarCloud: clear SONARQUBE_SCANNER_PARAMS after begin Prevents the End analysis step from re-applying sonar params that begin already wrote to the analysis config, eliminating the "Ignoring property from env variable" warning. * SonarCloud: always cancel in-progress runs on new push * TEMP: add failing test to verify pipeline resilience — revert before merge * Revert "TEMP: add failing test to verify pipeline resilience — revert before merge" This reverts commit828a7510cb. * Revert "SonarCloud: clear SONARQUBE_SCANNER_PARAMS after begin" This reverts commit1911b65db1. * Make SonarCloud workflow resilient to build and test failures * Fix inaccurate warning message when unit tests fail * Revert build step resilience, keep test failure warning * Improve test failure warning with coverage file check * Temporary: add failing test to verify SonarCloud workflow resilience * Revert "Temporary: add failing test to verify SonarCloud workflow resilience" This reverts commit71ecd61034.
This commit is contained in:
@@ -23,7 +23,7 @@ env:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
@@ -38,6 +38,12 @@ jobs:
|
||||
- name: Setup .NET from global.json
|
||||
uses: actions/setup-dotnet@v5
|
||||
|
||||
- name: Setup Java 21
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: "21"
|
||||
|
||||
- name: Cache SonarQube packages
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
@@ -60,7 +66,8 @@ jobs:
|
||||
dotnet-sonarscanner begin \
|
||||
/k:"$SONAR_PROJECT_KEY" \
|
||||
/o:"$SONAR_ORGANIZATION" \
|
||||
/d:sonar.token="$SONAR_TOKEN"
|
||||
/d:sonar.token="$SONAR_TOKEN" \
|
||||
/d:sonar.scanner.skipJreProvisioning=true
|
||||
|
||||
- name: Restore
|
||||
run: dotnet restore umbraco.sln
|
||||
@@ -69,12 +76,23 @@ jobs:
|
||||
run: GITHUB_ENV=/dev/null dotnet build umbraco.sln --no-restore -clp:ErrorsOnly # prevent sonar MSBuild integration from writing malformed values to $GITHUB_ENV
|
||||
|
||||
- name: Run unit tests with coverage
|
||||
id: tests
|
||||
continue-on-error: true
|
||||
run: |
|
||||
dotnet-coverage collect \
|
||||
"dotnet test tests/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj --no-build" \
|
||||
--output TestResults/coverage.xml \
|
||||
--output-format xml
|
||||
|
||||
- name: Warn on test failure
|
||||
if: steps.tests.outcome == 'failure'
|
||||
run: |
|
||||
if [ -f TestResults/coverage.xml ]; then
|
||||
echo "::warning::Unit tests failed - SonarCloud analysis will proceed with the collected coverage data"
|
||||
else
|
||||
echo "::warning::Unit tests failed and no coverage data was collected"
|
||||
fi
|
||||
|
||||
- name: End analysis
|
||||
env:
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
|
||||
Reference in New Issue
Block a user