From efc989c91797a4988c4ee28fc4c1e56f31602635 Mon Sep 17 00:00:00 2001 From: Farshad DASHTI Date: Fri, 4 Oct 2024 14:41:32 +0100 Subject: [PATCH] Updated cashing and template --- .github/workflows/build-test-caching.yml | 1 + .github/workflows/build-test-template.yml | 28 ++++++++++++++----- .../ServiceCollectionExtensions.cs | 3 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-test-caching.yml b/.github/workflows/build-test-caching.yml index 4ad16be..25c79aa 100644 --- a/.github/workflows/build-test-caching.yml +++ b/.github/workflows/build-test-caching.yml @@ -14,5 +14,6 @@ jobs: project_name: DfE.CoreLibs.Caching project_path: src/DfE.CoreLibs.Caching sonar_project_key: DFE-Digital_corelibs-caching + run_tests: false secrets: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/build-test-template.yml b/.github/workflows/build-test-template.yml index efac82e..043ec6e 100644 --- a/.github/workflows/build-test-template.yml +++ b/.github/workflows/build-test-template.yml @@ -15,6 +15,11 @@ on: required: true type: string description: "SonarCloud project key" + run_tests: + required: true + type: boolean + default: true + description: "Flag to run or skip tests" secrets: SONAR_TOKEN: required: true @@ -70,13 +75,22 @@ jobs: - name: Build, Test and Analyze env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - ConnectionStrings__DefaultConnection: ${{ env.CONNECTION_STRING }} CI: true run: | - dotnet-sonarscanner begin /k:"${{ inputs.sonar_project_key }}" /o:"dfe-digital" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.coverageReportPaths=CoverageReport/SonarQube.xml + if [ ${{ inputs.run_tests }} == "true" ]; then + dotnet-sonarscanner begin /k:"${{ inputs.sonar_project_key }}" /o:"dfe-digital" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.coverageReportPaths=CoverageReport/SonarQube.xml; + else + dotnet-sonarscanner begin /k:"${{ inputs.sonar_project_key }}" /o:"dfe-digital" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"; + fi dotnet build --no-restore -p:CI=${CI} ${{ inputs.project_path }} - dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" ${{ inputs.project_path }} - reportgenerator -reports:./**/coverage.cobertura.xml -targetdir:./CoverageReport -reporttypes:SonarQube - dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" + + - name: Run Tests + if: ${{ inputs.run_tests }} == true + run: dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" ${{ inputs.project_path }} + + - name: Generate Code Coverage Report + if: ${{ inputs.run_tests }} == true + run: reportgenerator -reports:./**/coverage.cobertura.xml -targetdir:./CoverageReport -reporttypes:SonarQube + + - name: Complete Sonar Scan + run: dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file diff --git a/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs b/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs index c5fcda9..c688d21 100644 --- a/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs +++ b/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs @@ -16,5 +16,4 @@ public static IServiceCollection AddServiceCaching( return services; } } -} - +} \ No newline at end of file