Skip to content

Running unit tests on all platforms in CI #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions .github/workflows/build-pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,39 @@

name: Build pull request

# Triggers build on pull requests and pushes to the main and develop branches.
on:
pull_request:
branches:
- main
- 'develop**'
- 'release/**'
- 'release**'
paths:
- '**.h'
- '**.c'
- '**.cs'
- '**.csproj'
- '**.sln'
- '.github/workflows/build-pull-requests.yml'


permissions:
pull-requests: write
checks: write
contents: read
packages: read

jobs:
build:
# Give this job a friendly name to show in GitHub UI.
name: Build and test
run-tests:
name: Run tests
uses: ./.github/workflows/test.yml
with:
build-coverage-report: true

build-artifacts:
name: Build artifacts
runs-on: windows-latest
# Build both Debug and ReleaseWithDocs configurations. Most people are probably building 'Debug' the most often. We
# should be sure that Release also builds, and that our documentation also compiles successfully.
strategy:
matrix:
configuration: [Debug, ReleaseWithDocs]

needs: run-tests

steps:
# Checkout the local repository
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
Expand All @@ -50,32 +55,23 @@ jobs:
- 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"

# Build the project
- name: Build Yubico.NET.SDK.sln
run: dotnet build --configuration ${{matrix.configuration}} --nologo --verbosity normal Yubico.NET.SDK.sln

# Save the built NuGet packages, just in case we need to inspect the build output.
run: dotnet build --configuration ReleaseWithDocs --nologo --verbosity normal Yubico.NET.SDK.sln

- name: Save build artifacts
uses: actions/upload-artifact@v4
with:
name: Nuget Packages ${{matrix.configuration}}
name: Nuget Packages ReleaseWithDocs
path: |
Yubico.DotNetPolyfills/src/bin/${{matrix.configuration}}/*.nupkg
Yubico.Core/src/bin/${{matrix.configuration}}/*.nupkg
Yubico.YubiKey/src/bin/${{matrix.configuration}}/*.nupkg
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.nupkg
Yubico.Core/src/bin/ReleaseWithDocs/*.nupkg
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.nupkg

- name: Save build artifacts
uses: actions/upload-artifact@v4
with:
name: Assemblies ${{matrix.configuration}}
name: Assemblies ReleaseWithDocs
path: |
Yubico.DotNetPolyfills/src/bin/${{matrix.configuration}}/**/*.dll
Yubico.Core/src/bin/${{matrix.configuration}}/**/*.dll
Yubico.YubiKey/src/bin/${{matrix.configuration}}/**/*.dll

# Test the project
- name: Test Yubico.YubiKey
run: dotnet test --configuration ${{matrix.configuration}} --verbosity normal --no-build --nologo Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj

- name: Test Yubico.Core
run: dotnet test --configuration ${{matrix.configuration}} --verbosity normal --no-build --nologo Yubico.Core/tests/Yubico.Core.UnitTests.csproj
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/**/*.dll
Yubico.Core/src/bin/ReleaseWithDocs/**/*.dll
Yubico.YubiKey/src/bin/ReleaseWithDocs/**/*.dll
29 changes: 16 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,25 @@ on:
type: string

permissions:
contents: read
id-token: write
packages: write

jobs:
build:
name: Build, test, save artefacts
runs-on: windows-2019
run-tests:
name: Run tests
permissions:
pull-requests: write
checks: write
packages: read
uses: ./.github/workflows/test.yml
with:
build-coverage-report: false

build-artifacts:
name: Build artefacts
runs-on: windows-2019
needs: run-tests

steps:
# Checkout the local repository
- uses: actions/checkout@v4
Expand All @@ -75,13 +85,6 @@ jobs:
- name: Build Yubico.NET.SDK.sln
run: dotnet build --configuration ReleaseWithDocs --nologo --verbosity normal Yubico.NET.SDK.sln

# Run tests
- name: Test Yubico.YubiKey
run: dotnet test --configuration ReleaseWithDocs --verbosity normal --no-build --nologo Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj

- name: Test Yubico.Core
run: dotnet test --configuration ReleaseWithDocs --verbosity normal --no-build --nologo Yubico.Core/tests/Yubico.Core.UnitTests.csproj

# Upload artifacts
- name: Save documentation artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -137,12 +140,12 @@ jobs:
upload-docs:
name: Upload docs
uses: ./.github/workflows/upload-docs.yml
needs: build
needs: build-artifacts

publish-internal:
name: Publish to internal NuGet
runs-on: windows-2019
needs: build
needs: build-artifacts
if: ${{ github.event.inputs.push-to-dev }}
steps:
- uses: actions/download-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
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: Build Yubico.NET.SDK.sln
run: dotnet build --configuration Release --nologo --verbosity normal Yubico.NET.SDK.sln
run: dotnet build --nologo --verbosity normal Yubico.NET.SDK.sln

- name: Check for correct formatting
run: dotnet format --verify-no-changes --no-restore -v d
54 changes: 54 additions & 0 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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:
name: MacOS
runs-on: macos-latest
permissions:
contents: read
packages: read

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 Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj --logger trx --settings coverlet.runsettings.xml --collect:"XPlat Code Coverage"

- name: Test Yubico.Core
run: dotnet test Yubico.Core/tests/Yubico.Core.UnitTests.csproj --logger trx --settings coverlet.runsettings.xml --collect:"XPlat Code Coverage"

- name: Upload Test Result Files
uses: actions/upload-artifact@v4
with:
name: TestResults-macOS
path: '**/TestResults/*'
52 changes: 52 additions & 0 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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:
name: Ubuntu
runs-on: ubuntu-latest
permissions:
contents: read
packages: read

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 Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj --logger trx --settings coverlet.runsettings.xml --collect:"XPlat Code Coverage"

- name: Test Yubico.Core
run: dotnet test Yubico.Core/tests/Yubico.Core.UnitTests.csproj --logger trx --settings coverlet.runsettings.xml --collect:"XPlat Code Coverage"

- name: Upload Test Result Files
uses: actions/upload-artifact@v4
with:
name: TestResults-Ubuntu
path: '**/TestResults/*'
46 changes: 46 additions & 0 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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:
name: Windows
runs-on: windows-latest
permissions:
packages: read
contents: read

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 Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj --logger trx --settings coverlet.runsettings.xml --collect:"XPlat Code Coverage"

- name: Test Yubico.Core
run: dotnet test Yubico.Core/tests/Yubico.Core.UnitTests.csproj --logger trx --settings coverlet.runsettings.xml --collect:"XPlat Code Coverage"

- name: Upload Test Result Files
uses: actions/upload-artifact@v4
with:
name: TestResults-Windows
path: '**/TestResults/*'
Loading