From accc4dae10806277747bc2d8244573165b3dbe5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Zaj=C4=85c?= Date: Thu, 19 Oct 2023 01:10:57 +0200 Subject: [PATCH] Introduce a composite action to run module tests (#72) * Introduce a composite action to run module tests * Treat Core as yet another module except creating NuGet package --- .github/actions/test-module/action.yml | 47 +++++++++++++++++++ .github/workflows/cicd.yml | 40 ++++------------ ...vity.AutoFixture.XUnit2.AutoFakeItEasy.sln | 4 +- ...bjectivity.AutoFixture.XUnit2.AutoMock.sln | 4 +- ...Objectivity.AutoFixture.XUnit2.AutoMoq.sln | 4 +- ...ity.AutoFixture.XUnit2.AutoNSubstitute.sln | 4 +- src/Objectivity.AutoFixture.XUnit2.Core.sln | 31 ++++++++++++ 7 files changed, 94 insertions(+), 40 deletions(-) create mode 100644 .github/actions/test-module/action.yml create mode 100644 src/Objectivity.AutoFixture.XUnit2.Core.sln diff --git a/.github/actions/test-module/action.yml b/.github/actions/test-module/action.yml new file mode 100644 index 00000000..80080ae0 --- /dev/null +++ b/.github/actions/test-module/action.yml @@ -0,0 +1,47 @@ +name: Test module +description: Run tests against specified module +inputs: + module-name: + description: Name of the module + required: true + module-namespace: + description: Name of the module namespace + required: true + codecov-token: + description: Value of Codecov token used to upload code coverage results + required: true + coverage-directory: + description: Path to code coverage directory where results are being stored + required: false + default: ${{ github.workspace }}\src\opencover +outputs: + file-path: + description: Signing key file path + value: ${{ steps.signing-key.outputs.PATH }} +runs: + using: composite + steps: + - name: 🧪 test ${{ matrix.package_module }} in net7.0 & collect coverage + id: module-code-coverage + run: | + $path = [IO.Path]::Combine("$env:CoverageDirectory","$env:ModuleFullName.xml") + dotnet test ./src/$env:ModuleFullName.Tests/ --no-build -f $env:TargetFramework -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$path + "FILE=$env:ModuleFullName.$env:TargetFramework.xml" >> $env:GITHUB_OUTPUT + shell: pwsh + env: + CoverageDirectory: ${{ inputs.coverage-directory }} + ModuleFullName: ${{ inputs.module-namespace }}.${{ inputs.module-name }} + TargetFramework: net7.0 + - name: 🧪 test ${{ matrix.package_module }} in net472 + run: dotnet test ./src/${{ inputs.module-namespace }}.${{ inputs.module-name }}.Tests/ --no-build -f net472 + shell: pwsh + - name: 🧪 test ${{ matrix.package_module }} in net48 + run: dotnet test ./src/${{ inputs.module-namespace }}.${{ inputs.module-name }}.Tests/ --no-build -f net48 + shell: pwsh + - name: 📤 upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ inputs.codecov-token }} + files: ${{ steps.module-code-coverage.outputs.FILE }} + directory: ${{ inputs.coverage-directory }} + flags: unittests diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 566a3993..0011cbe8 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -68,6 +68,7 @@ jobs: $matrix = @{ package_module = @(Foreach ($module in ($allModules.GetEnumerator() | Where-Object { $_.Value })) {$module.Name}) } + if ($matrix.package_module.count -gt 0) { $matrix.package_module = @("Core") + $matrix.package_module } "MATRIX=$($matrix | ConvertTo-JSON -Compress)" >> $env:GITHUB_OUTPUT - name: 📥 checkout uses: actions/checkout@v3 @@ -106,46 +107,21 @@ jobs: CI: true StrongNameKey: ${{ secrets.SIGNING_KEY }} StrongNameKeyPath: ${{ steps.signing-key.outputs.file-path }} - - name: 🧪 test Core in net7.0 & collect coverage - id: core-code-coverage - run: | - $path = [IO.Path]::Combine("$env:CoverageDirectory","$env:CoverageFileName.xml") - dotnet test ./src/${{ env.Namespace }}.Core.Tests/ --no-build -f $env:TargetFramework -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$path - "FILE=$env:CoverageFileName.$env:TargetFramework.xml" >> $env:GITHUB_OUTPUT - env: - CoverageFileName: ${{ env.Namespace }}.Core - TargetFramework: net7.0 - - name: 🧪 test Core in net472 - run: dotnet test ./src/${{ env.Namespace }}.Core.Tests/ --no-build -f net472 - - name: 🧪 test Core in net48 - run: dotnet test ./src/${{ env.Namespace }}.Core.Tests/ --no-build -f net48 - - name: 🧪 test ${{ matrix.package_module }} in net7.0 & collect coverage - id: module-code-coverage - run: | - $path = [IO.Path]::Combine("$env:CoverageDirectory","$env:CoverageFileName.xml") - dotnet test ./src/${{ env.Namespace }}.${{ matrix.package_module }}.Tests/ --no-build -f $env:TargetFramework -e:CollectCoverage=true -e:CoverletOutputFormat=opencover -e:Exclude="[xunit*]*" -e:CoverletOutput=$path - "FILE=$env:CoverageFileName.$env:TargetFramework.xml" >> $env:GITHUB_OUTPUT - env: - CoverageFileName: ${{ env.Namespace }}.${{ matrix.package_module }} - TargetFramework: net7.0 - - name: 🧪 test ${{ matrix.package_module }} in net472 - run: dotnet test ./src/${{ env.Namespace }}.${{ matrix.package_module }}.Tests/ --no-build -f net472 - - name: 🧪 test ${{ matrix.package_module }} in net48 - run: dotnet test ./src/${{ env.Namespace }}.${{ matrix.package_module }}.Tests/ --no-build -f net48 - - name: 📤 upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + - name: 🧪 test + uses: ./.github/actions/test-module with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ${{ steps.core-code-coverage.outputs.FILE }},${{ steps.module-code-coverage.outputs.FILE }} - directory: ${{ env.CoverageDirectory }} - flags: unittests + module-name: ${{ matrix.package_module }} + module-namespace: ${{ env.Namespace }} + codecov-token: ${{ secrets.CODECOV_TOKEN }} - name: 📦 pack + if: ${{ startsWith(matrix.package_module, 'Auto' ) }} run: dotnet pack ./src/${{ env.Namespace }}.${{ matrix.package_module }} --no-restore env: CI: true StrongNameKey: ${{ secrets.SIGNING_KEY }} StrongNameKeyPath: ${{ steps.signing-key.outputs.file-path }} - name: 🔼 upload packages + if: ${{ startsWith(matrix.package_module, 'Auto' ) }} uses: actions/upload-artifact@v3 with: name: packages diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.sln b/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.sln index db8d9c7c..c99f91c5 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.sln +++ b/src/Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29409.12 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34202.233 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Objectivity.AutoFixture.XUnit2.Core", "Objectivity.AutoFixture.XUnit2.Core\Objectivity.AutoFixture.XUnit2.Core.csproj", "{B889895A-FC17-470A-B28E-61AAA8DBC1A4}" EndProject diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoMock.sln b/src/Objectivity.AutoFixture.XUnit2.AutoMock.sln index 29857f56..4726453d 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoMock.sln +++ b/src/Objectivity.AutoFixture.XUnit2.AutoMock.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29409.12 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34202.233 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Objectivity.AutoFixture.XUnit2.Core", "Objectivity.AutoFixture.XUnit2.Core\Objectivity.AutoFixture.XUnit2.Core.csproj", "{7FF963AD-E151-4E45-9093-7B9E6441BFA0}" EndProject diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoMoq.sln b/src/Objectivity.AutoFixture.XUnit2.AutoMoq.sln index c79e78ab..c5495182 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoMoq.sln +++ b/src/Objectivity.AutoFixture.XUnit2.AutoMoq.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29409.12 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34202.233 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Objectivity.AutoFixture.XUnit2.AutoMoq", "Objectivity.AutoFixture.XUnit2.AutoMoq\Objectivity.AutoFixture.XUnit2.AutoMoq.csproj", "{B7ADCA12-249E-4A13-90A3-16AD9E3EDFD0}" EndProject diff --git a/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.sln b/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.sln index cb4fcccf..6a7e9f99 100644 --- a/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.sln +++ b/src/Objectivity.AutoFixture.XUnit2.AutoNSubstitute.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29409.12 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34202.233 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Objectivity.AutoFixture.XUnit2.AutoNSubstitute", "Objectivity.AutoFixture.XUnit2.AutoNSubstitute\Objectivity.AutoFixture.XUnit2.AutoNSubstitute.csproj", "{D3E477EA-F0A1-4287-A22D-C8D982231849}" EndProject diff --git a/src/Objectivity.AutoFixture.XUnit2.Core.sln b/src/Objectivity.AutoFixture.XUnit2.Core.sln new file mode 100644 index 00000000..18d0ef51 --- /dev/null +++ b/src/Objectivity.AutoFixture.XUnit2.Core.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34202.233 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Objectivity.AutoFixture.XUnit2.Core", "Objectivity.AutoFixture.XUnit2.Core\Objectivity.AutoFixture.XUnit2.Core.csproj", "{A639D1F4-C3D5-499F-944B-DEE361C20082}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Objectivity.AutoFixture.XUnit2.Core.Tests", "Objectivity.AutoFixture.XUnit2.Core.Tests\Objectivity.AutoFixture.XUnit2.Core.Tests.csproj", "{D9095A71-49FC-47FE-8C49-1677EBE42B53}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A639D1F4-C3D5-499F-944B-DEE361C20082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A639D1F4-C3D5-499F-944B-DEE361C20082}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A639D1F4-C3D5-499F-944B-DEE361C20082}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A639D1F4-C3D5-499F-944B-DEE361C20082}.Release|Any CPU.Build.0 = Release|Any CPU + {D9095A71-49FC-47FE-8C49-1677EBE42B53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D9095A71-49FC-47FE-8C49-1677EBE42B53}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D9095A71-49FC-47FE-8C49-1677EBE42B53}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D9095A71-49FC-47FE-8C49-1677EBE42B53}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D092E697-BEB8-4A00-B37E-4109FD2B17E7} + EndGlobalSection +EndGlobal