diff --git a/.github/workflows/test-macos.yaml b/.github/workflows/test-macos.yaml new file mode 100644 index 000000000..0796abed1 --- /dev/null +++ b/.github/workflows/test-macos.yaml @@ -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 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 --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-macOS + path: '**/TestResults/*' diff --git a/.github/workflows/test-ubuntu.yaml b/.github/workflows/test-ubuntu.yaml new file mode 100644 index 000000000..a018d5965 --- /dev/null +++ b/.github/workflows/test-ubuntu.yaml @@ -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 --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-Ubuntu + path: '**/TestResults/*' diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml new file mode 100644 index 000000000..70da0a343 --- /dev/null +++ b/.github/workflows/test-windows.yaml @@ -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 --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-Windows + path: '**/TestResults/*' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 000000000..6e96838b7 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,112 @@ +# 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: Run tests and code coverage + +on: + pull_request: + branches: + - main + - 'develop**' + - 'release/**' + push: + branches: + - main + - develop + +jobs: + test-macos: + uses: ./.github/workflows/test_macos.yml + test-ubuntu: + uses: ./.github/workflows/test_ubuntu.yml + test-windows: + uses: ./.github/workflows/test_windows.yml + coverage: + runs-on: ubuntu-latest + needs: [test-macos, test-ubuntu, 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: + reports: "**/*.cobertura.xml" # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported. + targetdir: "${{ github.workspace }}" # REQUIRED # The directory where the generated report should be saved. + reporttypes: "Cobertura" # The output formats and scope (separated by semicolon) Values: Badges, Clover, Cobertura, CsvSummary, Html, Html_Dark, Html_Light, Html_BlueRed, HtmlChart, HtmlInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HtmlInline_AzurePipelines_Light, HtmlSummary, JsonSummary, Latex, LatexSummary, lcov, MarkdownSummary, MarkdownSummaryGithub, MarkdownDeltaSummary, MHtml, PngChart, SonarQube, TeamCitySummary, TextSummary, TextDeltaSummary, Xml, XmlSummary + verbosity: "Warning" # The verbosity level of the log messages. Values: Verbose, Info, Warning, Error, Off + title: "Code Coverage" # Optional title. + tag: "${{ github.run_number }}_${{ github.run_id }}" # Optional tag or build version. + customSettings: "" # Optional custom settings (separated by semicolon). See: https://github.com/danielpalme/ReportGenerator/wiki/Settings. + toolpath: "reportgeneratortool" # Default directory for installing the dotnet tool. + + - name: Code Coverage Summary Report + uses: irongut/CodeCoverageSummary@v1.3.0 + with: + filename: "Cobertura.xml" + badge: true + fail_below_min: true + format: markdown + hide_branch_rate: false + hide_complexity: false + indicators: true + output: both + thresholds: "40 60" + + - name: Upload Code Coverage Report + uses: actions/upload-artifact@v4 + with: + name: CoverageResults + path: code-coverage-results.md + + pr-comment-coverage-results: + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: read + checks: write + needs: coverage + if: github.event_name == 'pull_request' + steps: + - name: Download coverage results + uses: actions/download-artifact@v4 + with: + name: CoverageResults + + - name: run ls recursively + run: ls -R + + - name: Add Coverage PR Comment + uses: marocchino/sticky-pull-request-comment@v2.9.0 + with: + recreate: true + path: code-coverage-results.md + + pr-comment-test-results: + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: read + checks: write + needs: test + if: github.event_name == 'pull_request' + steps: + - uses: actions/download-artifact@v4 + + - name: run ls recursively + run: ls -R + + - name: Add Test Results PR Comment + uses: EnricoMi/publish-unit-test-result-action@v2.16.1 + with: + trx_files: "${{ github.workspace }}/**/*.trx" \ No newline at end of file