diff --git a/.github/workflows/reusable-dotnet-quality.yml b/.github/workflows/reusable-dotnet-quality.yml index 5ff8b77..c3548f5 100644 --- a/.github/workflows/reusable-dotnet-quality.yml +++ b/.github/workflows/reusable-dotnet-quality.yml @@ -8,9 +8,15 @@ on: type: string required: false default: "" + dotnet-test-args: + description: ".NET test arguments (for example \"--report-xunit-trx --coverage --coverage-output-format cobertura\")" + type: string + required: false + default: "" dotnet-version: description: .NET version type: string + required: false default: "10.0" extra-vars: description: "Additional environment variables at the start of the pipeline" @@ -32,11 +38,6 @@ on: type: string required: false default: Quality - mongodb-enabled: - description: "Start MongoDB for integration tests?" - type: boolean - required: false - default: false operating-system: description: Operating system executing the runner type: string @@ -94,12 +95,15 @@ jobs: working-directory: ${{ inputs.working-directory }} steps: - name: Set additional variables + shell: bash run: | - if [[ -z "${{ secrets.extra-vars }}" ]]; then - echo "No extra-vars provided - skipping" - else - echo "${{ secrets.extra-vars }}" >> "$GITHUB_ENV" + if [[ -n "${{ inputs.extra-vars }}" ]]; then + echo "${{ inputs.extra-vars }}" >> "$GITHUB_ENV" fi + - name: Disable git autocrlf + if: ${{ inputs.operating-system == 'windows-latest' }} + run: git config --global core.autocrlf false + shell: bash - name: Clone repository uses: actions/checkout@v6 with: @@ -114,9 +118,6 @@ jobs: uses: ./workflow-parts/actions/dotnet/install-lint-restore with: dotnet-version: ${{ inputs.dotnet-version }} - - name: Start MongoDB - if: ${{ inputs.mongodb-enabled }} - uses: ./workflow-parts/actions/mongodb/start - name: Run optional custom commands if: ${{ inputs.custom-commands != '' }} run: | @@ -124,10 +125,13 @@ jobs: - name: Build & test if: ${{ ! inputs.sonar-enabled }} uses: ./workflow-parts/actions/dotnet/build-test + with: + dotnet-test-args: ${{ inputs.dotnet-test-args }} - name: Build, test & analyze if: ${{ inputs.sonar-enabled }} uses: ./workflow-parts/actions/dotnet/build-test-sonar with: + dotnet-test-args: ${{ inputs.dotnet-test-args }} sonar-organization: ${{ inputs.sonar-organization }} sonar-host-url: ${{ inputs.sonar-host-url }} sonar-project-name: ${{ inputs.sonar-project-name }} diff --git a/.github/workflows/reusable-terraform-deployment.yml b/.github/workflows/reusable-terraform-deployment.yml index 7b6fe40..659fde0 100644 --- a/.github/workflows/reusable-terraform-deployment.yml +++ b/.github/workflows/reusable-terraform-deployment.yml @@ -98,7 +98,6 @@ jobs: ref: ${{ inputs.workflow-parts-version }} path: workflow-parts - name: Add runner ID to MongoDB Atlas - # uses: devpro/github-workflow-parts/actions/mongodb-atlas/add-runner-ip@... cannot be used with an input parameter in it (must be static) so checkout is mandatory uses: ./workflow-parts/actions/mongodb-atlas/add-runner-ip with: atlas-publickey: ${{ secrets.atlas-publickey }} diff --git a/actions/dotnet/build-test-sonar/action.yml b/actions/dotnet/build-test-sonar/action.yml index 3d9331d..5806512 100644 --- a/actions/dotnet/build-test-sonar/action.yml +++ b/actions/dotnet/build-test-sonar/action.yml @@ -2,6 +2,10 @@ name: Build, Test & Analyze description: Builds, runs tests on a .NET codebase and run analysis with Sonar inputs: + dotnet-test-args: + description: .NET test arguments + required: false + default: "" java-version: description: Java version that will be installed (for Sonar CLI) required: false @@ -78,12 +82,12 @@ runs: run: | dotnet test --no-build --verbosity normal --configuration Debug \ --results-directory "${{ inputs.report-folder }}/TestResults" \ - --report-xunit-trx \ - --coverage --coverage-output-format cobertura + ${{ inputs.dotnet-test-args }} shell: bash env: ASPNETCORE_ENVIRONMENT: Development - name: Generate test report + if: ${{ always() && hashFiles(format('{0}/TestResults/*.cobertura.xml', inputs.report-folder)) != '' }} run: | reportgenerator "-reports:${{ inputs.report-folder }}/TestResults/*.cobertura.xml" \ "-targetdir:${{ inputs.report-folder }}" \ diff --git a/actions/dotnet/build-test/action.yml b/actions/dotnet/build-test/action.yml index cc2e2a6..e98e4ea 100644 --- a/actions/dotnet/build-test/action.yml +++ b/actions/dotnet/build-test/action.yml @@ -2,6 +2,10 @@ name: Build & Test description: Builds and runs tests on a .NET codebase inputs: + dotnet-test-args: + description: .NET test arguments + required: false + default: "" report-folder: description: Folder where report files will be generated required: false @@ -13,17 +17,18 @@ runs: - name: Build .NET code run: dotnet build --no-restore --configuration Debug shell: bash - - name: Run .NET tests + - name: Run tests run: | dotnet test --no-build --verbosity normal --configuration Debug \ - --logger:"junit;LogFilePath=..\..\artifacts\{assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose" \ - --collect:"XPlat Code Coverage" + --results-directory "${{ inputs.report-folder }}/TestResults" \ + ${{ inputs.dotnet-test-args }} shell: bash env: ASPNETCORE_ENVIRONMENT: Development - name: Generate test report + if: ${{ always() && hashFiles(format('{0}/TestResults/*.cobertura.xml', inputs.report-folder)) != '' }} run: | - reportgenerator "-reports:./test/*/TestResults/*/coverage.cobertura.xml" \ + reportgenerator "-reports:${{ inputs.report-folder }}/TestResults/*.cobertura.xml" \ "-targetdir:${{ inputs.report-folder }}" \ "-reporttypes:Cobertura;Html;TextSummary" shell: bash