Skip to content

Simplify build & tests of Reqnroll #126

Simplify build & tests of Reqnroll

Simplify build & tests of Reqnroll #126

Workflow file for this run

name: CI
on:
push:
branches:
- 'main'
paths-ignore:
- 'docs/**'
- README.md
- CHANGELOG.md
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
configuration:
description: 'Build Configuration'
required: true
default: 'Debug'
type: choice
options:
- Debug
- Release
production_release:
description: 'If the build produces a production package'
type: boolean
default: false
required: true
version_suffix:
description: 'Suffix for the NuGet packages (without leading -). Build ID will be appended. Use "-" to force empty.'
required: false
specs_filter:
description: 'Filter for Specs execution (e.g. Category=basicExecution)'
required: false
permissions:
checks: write
env:
SPECS_FILTER: "" # use for testing CI: "&Category=basicExecution"
jobs:
build:
runs-on: ubuntu-latest
outputs:
product_version_suffix: ${{ steps.versions.outputs.product_version_suffix }}
product_configuration: ${{ steps.versions.outputs.product_configuration }}
build_params: ${{ steps.versions.outputs.build_params }}
test_params: ${{ steps.versions.outputs.test_params }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- id: versions
name: Calculate versions
shell: pwsh
env:
APPINSIGHTS_KEY: ${{ secrets.APPINSIGHTS_KEY }}
run: |
$productionReleaseSetting = "${{ inputs.production_release }}"
$productionRelease = $false
if ($productionReleaseSetting -eq 'true') {
$productionRelease = $true
}
Write-Output "Production release: $productionRelease"
$versionSuffix = "${{ inputs.version_suffix }}"
if ($versionSuffix -eq "") {
$date = [datetime]::Today
$dateString = $date.ToString('yyyyMMdd')
$versionSuffix = "ci$dateString-${env:GITHUB_RUN_NUMBER}"
}
elseif ($versionSuffix -eq "-") {
$versionSuffix = ""
}
else {
$versionSuffix = "$versionSuffix-${env:GITHUB_RUN_NUMBER}"
}
Write-Output "product_version_suffix=$versionSuffix" >> $env:GITHUB_OUTPUT
Write-Output "Product Suffix: $versionSuffix"
$productConfig = "${{ inputs.configuration }}"
if ($productConfig -eq "") {
$productConfig = "Debug"
}
Write-Output "product_configuration=$productConfig" >> $env:GITHUB_OUTPUT
Write-Output "Product Configuration: $productConfig"
$specsFilter = "${{ inputs.specs_filter }}"
if ($specsFilter -ne "") {
$specsFilter = "&$specsFilter"
}
else {
$specsFilter = $envSPECS_FILTER
}
Write-Output "specs_filter=$specsFilter" >> $env:GITHUB_OUTPUT
Write-Output "Specs Filter: $specsFilter"
$buildParams = "-p:VersionSuffix=$versionSuffix -c $productConfig"
Write-Output "build_params=$buildParams" >> $env:GITHUB_OUTPUT
Write-Output "Build Params: $buildParams"
$mainBuildParams = $buildParams
if ($productionRelease) {
$mainBuildParams = "$mainBuildParams -p:AppInsightsInstrumentationKey=$env:APPINSIGHTS_KEY"
Write-Output "Main Build Params Updated for Production"
}
Write-Output "main_build_params=$mainBuildParams" >> $env:GITHUB_OUTPUT
$testParams = "--no-build --verbosity normal -c $productConfig"
Write-Output "test_params=$testParams" >> $env:GITHUB_OUTPUT
Write-Output "Test Params: $testParams"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore ${{ steps.versions.outputs.main_build_params }}
- name: Runtime Tests
run: dotnet test ./Tests/Reqnroll.RuntimeTests/Reqnroll.RuntimeTests.csproj ${{ steps.versions.outputs.test_params }} -f net6.0
- name: Plugin Tests
run: dotnet test ./Tests/Reqnroll.PluginTests/Reqnroll.PluginTests.csproj ${{ steps.versions.outputs.test_params }} -f net6.0
- name: Generator Tests
run: dotnet test ./Tests/Reqnroll.GeneratorTests/Reqnroll.GeneratorTests.csproj ${{ steps.versions.outputs.test_params }} -f net6.0
- name: ExternalData Plugin Tests
run: dotnet test ./Plugins/Reqnroll.ExternalData/Reqnroll.ExternalData.ReqnrollPlugin.UnitTests/Reqnroll.ExternalData.ReqnrollPlugin.UnitTests.csproj ${{ steps.versions.outputs.test_params }} -f net6.0
- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: packages
path: "GeneratedNuGetPackages/**/*.nupkg"
- name: Upload TRX files
uses: actions/upload-artifact@v4
if: always()
with:
name: build-trx
path: "**/*.trx"
specs-xunit:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore ${{ needs.build.outputs.build_params }}
- name: Set .NET 6 SDK
run: dotnet new globaljson --sdk-version 6.0.418
- name: xUnit Specs
shell: pwsh
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj ${{ needs.build.outputs.test_params }} -f net6.0 --filter "Category=xUnit&Category=Net60&Category!=requiresMsBuild${{ needs.build.outputs.specs_filter }}" --logger "trx;LogFileName=specs-xunit-results.trx"
- name: Publish xUnit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: xUnit Specs
files: "**/specs-xunit-results.trx"
comment_mode: off
- name: Upload TRX files
uses: actions/upload-artifact@v4
if: always()
with:
name: specs-xunit-trx
path: "**/specs-xunit-results.trx"
specs-nunit:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore ${{ needs.build.outputs.build_params }}
- name: Set .NET 6 SDK
run: dotnet new globaljson --sdk-version 6.0.418
- name: NUnit Specs
shell: pwsh
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj ${{ needs.build.outputs.test_params }} -f net6.0 --filter "Category=NUnit3&Category=Net60&Category!=requiresMsBuild${{ needs.build.outputs.specs_filter }}" --logger "trx;LogFileName=specs-nunit-results.trx"
- name: Publish NUnit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: NUnit Specs
files: "**/specs-nunit-results.trx"
comment_mode: off
- name: Upload TRX files
uses: actions/upload-artifact@v4
if: always()
with:
name: specs-nunit-trx
path: "**/specs-nunit-results.trx"
specs-mstest:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore ${{ needs.build.outputs.build_params }}
- name: Set .NET 6 SDK
run: dotnet new globaljson --sdk-version 6.0.418
- name: MsTest Specs
shell: pwsh
run: dotnet test ./Tests/Reqnroll.Specs/Reqnroll.Specs.csproj ${{ needs.build.outputs.test_params }} -f net6.0 --filter "Category=MsTest&Category=Net60&Category!=requiresMsBuild${{ needs.build.outputs.specs_filter }}" --logger "trx;LogFileName=specs-mstest-results.trx"
- name: Publish MSTest Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: MSTest Specs
files: "**/specs-mstest-results.trx"
comment_mode: off
- name: Upload TRX files
uses: actions/upload-artifact@v4
if: always()
with:
name: specs-mstest-trx
path: "**/specs-mstest-results.trx"
system-tests:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore ${{ needs.build.outputs.build_params }}
- name: Set .NET 6 SDK
run: dotnet new globaljson --sdk-version 6.0.418
- name: System Tests
shell: pwsh
run: dotnet test ./Tests/Reqnroll.SystemTests/Reqnroll.SystemTests.csproj ${{ needs.build.outputs.test_params }} --logger "trx;LogFileName=system-tests-results.trx"
- name: Publish System Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
check_name: System Tests
files: "**/system-tests-results.trx"
comment_mode: off
- name: Upload TRX files
uses: actions/upload-artifact@v4
if: always()
with:
name: system-tests-trx
path: "**/system-tests-results.trx"