diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml new file mode 100644 index 00000000..9169c50f --- /dev/null +++ b/.github/workflows/test-macos.yml @@ -0,0 +1,49 @@ +# Copyright 2021 Yubico AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Test on macOS + +on: + workflow_call: + +jobs: + test: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + + - name: Add local NuGet repository + run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json" + + - name: Install OpenSSL and link + run: | + brew install openssl + sudo mkdir /usr/local/lib + sudo ln -s $(brew --prefix)/opt/openssl@3/lib/libcrypto.3.dylib /usr/local/lib/libcrypto.3.dylib + sudo ln -s $(brew --prefix)/opt/openssl@3/lib/libssl.3.dylib /usr/local/lib/libssl.3.dylib + + - name: Test Yubico.YubiKey + run: dotnet test --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj --settings coverlet.runsettings.xml + + - name: Test Yubico.Core + run: dotnet test --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.Core/tests/Yubico.Core.UnitTests.csproj --settings coverlet.runsettings.xml + + - name: Upload Test Result Files + uses: actions/upload-artifact@v4 + with: + name: TestResults-macOS + path: '**/TestResults/*' diff --git a/.github/workflows/test-ubuntu.yml b/.github/workflows/test-ubuntu.yml new file mode 100644 index 00000000..b69d2954 --- /dev/null +++ b/.github/workflows/test-ubuntu.yml @@ -0,0 +1,47 @@ +# Copyright 2021 Yubico AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Test on Ubuntu + +on: + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + + - name: Add local NuGet repository + run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json" + + - name: Install PCSC and link libUdev + run: | + sudo apt-get update && sudo apt-get install pcscd -yq + sudo ln -s /usr/lib/x86_64-linux-gnu/libudev.so.1 /usr/lib/libudev.so + + - name: Test Yubico.YubiKey + run: dotnet test --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj --settings coverlet.runsettings.xml + + - name: Test Yubico.Core + run: dotnet test --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.Core/tests/Yubico.Core.UnitTests.csproj --settings coverlet.runsettings.xml + + - name: Upload Test Result Files + uses: actions/upload-artifact@v4 + with: + name: TestResults-Ubuntu + path: '**/TestResults/*' diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml new file mode 100644 index 00000000..42871466 --- /dev/null +++ b/.github/workflows/test-windows.yml @@ -0,0 +1,41 @@ +# Copyright 2021 Yubico AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Test on Windows + +on: + workflow_call: + +jobs: + test: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + - name: Add local NuGet repository + run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json" + + - name: Test Yubico.YubiKey + run: dotnet test --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj --settings coverlet.runsettings.xml + + - name: Test Yubico.Core + run: dotnet test --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.Core/tests/Yubico.Core.UnitTests.csproj --settings coverlet.runsettings.xml + + - name: Upload Test Result Files + uses: actions/upload-artifact@v4 + with: + name: TestResults-Windows + path: '**/TestResults/*' diff --git a/.github/workflows/test-and-cover.yml b/.github/workflows/test.yml similarity index 64% rename from .github/workflows/test-and-cover.yml rename to .github/workflows/test.yml index 4f6338e7..2570270b 100644 --- a/.github/workflows/test-and-cover.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: Tests and code coverage +name: Run tests and code coverage on: pull_request: @@ -26,7 +26,7 @@ on: - '**.cs' - '**.csproj' - '**.sln' - - '.github/workflows/test-and-cover.yml' + - '.github/workflows/test.yml' push: branches: - main @@ -37,61 +37,20 @@ on: - '**.cs' - '**.csproj' - '**.sln' - - '.github/workflows/test-and-cover.yml' - -jobs: - test: - strategy: - fail-fast: false - matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-dotnet@v4 - with: - global-json-file: global.json - - - name: Add local NuGet repository - run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json" - - - name: Install OpenSSL and link for macOS - if: matrix.os == 'macos-latest' - run: | - brew install openssl - sudo mkdir /usr/local/lib - sudo ln -s $(brew --prefix)/opt/openssl@3/lib/libcrypto.3.dylib /usr/local/lib/libcrypto.3.dylib - sudo ln -s $(brew --prefix)/opt/openssl@3/lib/libssl.3.dylib /usr/local/lib/libssl.3.dylib - - - name: Install PCSC and link libUdev for Ubuntu - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update && sudo apt-get install pcscd -yq - sudo ln -s /usr/lib/x86_64-linux-gnu/libudev.so.1 /usr/lib/libudev.so - - - name: Restore dotnet dependencies - run: | - dotnet restore - - - name: Test Yubico.YubiKey - run: dotnet test --no-restore --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj --settings coverlet.runsettings.xml - - - name: Test Yubico.Core - run: dotnet test --no-restore --nologo --logger trx --collect:"XPlat Code Coverage" Yubico.Core/tests/Yubico.Core.UnitTests.csproj --settings coverlet.runsettings.xml - - - name: Upload Test Result Files - uses: actions/upload-artifact@v4 - with: - name: TestResults-${{ matrix.os }} - if-no-files-found: error - path: '**/TestResults/*' + - '.github/workflows/test.yml' +jobs: + test-windows: + uses: ./.github/workflows/test-windows.yml + test-ubuntu: + uses: ./.github/workflows/test-ubuntu.yml + test-macos: + uses: ./.github/workflows/test-macos.yml coverage: runs-on: ubuntu-latest - needs: test + needs: [test-windows] steps: - uses: actions/download-artifact@v4 - - name: Combine Coverage Reports # This is because one report is produced per project, and we want one result for all of them. uses: danielpalme/ReportGenerator-GitHub-Action@5.2.4 with: @@ -152,15 +111,28 @@ jobs: pull-requests: write contents: read checks: write - needs: test + needs: [test-windows, test-ubuntu, test-macOS] if: github.event_name == 'pull_request' steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v4 - name: run ls recursively run: ls -R - - name: Add Test Results PR Comment + - name: Add Test Results PR Comment (Windows) + uses: EnricoMi/publish-unit-test-result-action@v2.16.1 + with: + trx_files: "${{ github.workspace }}/TestResults-Windows/**/*.trx" + check_name: "Test Results: Windows" + + - name: Add Test Results PR Comment (Ubuntu) + uses: EnricoMi/publish-unit-test-result-action@v2.16.1 + with: + trx_files: "${{ github.workspace }}/TestResults-Ubuntu/**/*.trx" + check_name: "Test Results: Ubuntu" + + - name: Add Test Results PR Comment (MacOS) uses: EnricoMi/publish-unit-test-result-action@v2.16.1 with: - trx_files: "${{ github.workspace }}/**/*.trx" \ No newline at end of file + trx_files: "${{ github.workspace }}/TestResults-macOS/**/*.trx" + check_name: "Test Results: MacOS" \ No newline at end of file diff --git a/Yubico.NET.SDK.sln b/Yubico.NET.SDK.sln index 7b6cc52f..8fc6195c 100644 --- a/Yubico.NET.SDK.sln +++ b/Yubico.NET.SDK.sln @@ -31,8 +31,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ .github\workflows\build.yml = .github\workflows\build.yml .github\workflows\check-code-formatting.yml = .github\workflows\check-code-formatting.yml .github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml - .github\workflows\test-and-cover.yml = .github\workflows\test-and-cover.yml .github\workflows\upload-docs.yml = .github\workflows\upload-docs.yml + .github\workflows\test.yml = .github\workflows\test.yml + .github\workflows\test-macos.yml = .github\workflows\test-macos.yml + .github\workflows\test-ubuntu.yml = .github\workflows\test-ubuntu.yml + .github\workflows\test-windows.yml = .github\workflows\test-windows.yml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Yubico.Core", "Yubico.Core", "{45D2A3BE-5111-4890-8898-2D43DB658A40}"