From a9749ddcff6f47262f2203b4607507eea10300b1 Mon Sep 17 00:00:00 2001 From: Jake Aitchison Date: Mon, 4 Apr 2022 14:55:15 +0100 Subject: [PATCH] Update Github Actions to use OS matrix --- .github/workflows/build-status.yml | 55 +++++++++------------ .github/workflows/receive-pr.yml | 76 +++++++++++++----------------- 2 files changed, 57 insertions(+), 74 deletions(-) diff --git a/.github/workflows/build-status.yml b/.github/workflows/build-status.yml index 46d13dd42..80903647c 100644 --- a/.github/workflows/build-status.yml +++ b/.github/workflows/build-status.yml @@ -3,64 +3,55 @@ on: push: branches: - master - +env: + DOTNET_VERSION: '6.0.x' jobs: - build-and-test-windows: - name: Build And Test - runs-on: windows-2019 - + build-and-test: + name: Build And Test ${{matrix.os}} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] steps: - uses: actions/checkout@v2 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.101 + dotnet-version: ${{ env.DOTNET_VERSION }} - - name: Restore nHapi + - name: Restore nHapi (Windows) + if: matrix.os == 'windows-latest' run: | dotnet restore nHapi.sln --configfile build\.nuget\NuGet.config + - name: Restore nHapi (Non-Windows) + if: matrix.os != 'windows-latest' + run: | + dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config + - name: Build nHapi run: | dotnet build nHapi.sln -c Release --no-restore - - name: Run tests for all target frameworks + - name: Run tests for all target frameworks (Windows) + if: matrix.os == 'windows-latest' run: | dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj -r TestResults -c Release -f net461 --no-restore --no-build - dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj -r TestResults -c Release -f net6.0--no-restore --no-build + dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj -r TestResults -c Release -f net6.0 --no-restore --no-build dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj -r TestResults -c Release -f net6.0 --no-restore --no-build dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj -r TestResults -c Release -f net461 --no-restore --no-build dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj -r TestResults -c Release -f net6.0 --no-restore --no-build - build-and-test-linux: - name: Build And Test Linux - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.101 - - - name: Restore nHapi - run: | - dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config - - - name: Build nHapi - run: | - dotnet build nHapi.sln -c Release --no-restore - - - name: Run tests for all target frameworks + - name: Run tests for all target frameworks (Non-Windows) + if: matrix.os != 'windows-latest' run: | dotnet test tests/NHapi.Base.NUnit/NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build dotnet test tests/NHapi.NUnit.SourceGeneration/NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build dotnet test tests/NHapi.NUnit/NHapi.NUnit.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build - name: Upload Code Coverage Report - if: always() + if: always() && matrix.os == 'ubuntu-latest' uses: actions/upload-artifact@v2 with: name: coverage-reports @@ -68,7 +59,7 @@ jobs: TestResults/ publish-coverage-results: - needs: build-and-test-linux + needs: build-and-test name: Publish Code Coverage Results runs-on: ubuntu-latest # the build-and-test job might be skipped, we don't need to run this job then diff --git a/.github/workflows/receive-pr.yml b/.github/workflows/receive-pr.yml index 790af6875..236c0a9da 100644 --- a/.github/workflows/receive-pr.yml +++ b/.github/workflows/receive-pr.yml @@ -1,76 +1,68 @@ name: Receive Pull Request on: [pull_request] - +env: + DOTNET_VERSION: '6.0.x' jobs: - build-and-test-windows: - name: Build And Test - runs-on: windows-2019 - + build-and-test: + name: Build And Test ${{matrix.os}} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] steps: - uses: actions/checkout@v2 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.101 - - name: Restore nHapi + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Restore nHapi (Windows) + if: matrix.os == 'windows-latest' run: | dotnet restore nHapi.sln --configfile build\.nuget\NuGet.config + - name: Restore nHapi (Non-Windows) + if: matrix.os != 'windows-latest' + run: | + dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config + - name: Build nHapi run: | dotnet build nHapi.sln -c Release --no-restore - - name: Run tests for all target frameworks + - name: Run tests for all target frameworks (Windows) + if: matrix.os == 'windows-latest' + run: | + dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net461 --no-restore --no-build + dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net6.0 --no-restore --no-build + dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net6.0 --no-restore --no-build + dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net461 --no-restore --no-build + dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net6.0 --no-restore --no-build + + - name: Run tests for all target frameworks (Non-Windows) + if: matrix.os != 'windows-latest' run: | - dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net461 --no-restore --no-build - dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net6.0 --no-restore --no-build - dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net6.0 --no-restore --no-build - dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net461 --no-restore --no-build - dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net6.0 --no-restore --no-build + dotnet test tests/NHapi.Base.NUnit/NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build + dotnet test tests/NHapi.NUnit.SourceGeneration/NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build + dotnet test tests/NHapi.NUnit/NHapi.NUnit.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build - name: Convert trx to junit - if: ${{ success() || failure() }} + if: (success() || failure()) && matrix.os == 'windows-latest' run: | dotnet tool install -g trx2junit trx2junit TestResults/*.trx - name: Upload Unit Test Results - if: always() + if: always() && matrix.os == 'windows-latest' uses: actions/upload-artifact@v2 with: name: unit-test-results path: TestResults\TestResults*.xml - build-and-test-linux: - name: Build And Test Linux - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.101 - - - name: Restore nHapi - run: | - dotnet restore nHapi.sln --configfile build/.nuget/NuGet.config - - - name: Build nHapi - run: | - dotnet build nHapi.sln -c Release --no-restore - - - name: Run tests for all target frameworks - run: | - dotnet test tests/NHapi.Base.NUnit/NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build - dotnet test tests/NHapi.NUnit.SourceGeneration/NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build - dotnet test tests/NHapi.NUnit/NHapi.NUnit.csproj --collect:"XPlat Code Coverage" -r TestResults -c Release -f net6.0 --no-restore --no-build - - name: Upload Code Coverage Report - if: always() + if: always() && matrix.os == 'ubuntu-latest' uses: actions/upload-artifact@v2 with: name: coverage-reports