Skip to content

Commit

Permalink
Merge pull request #661 from webprofusion/core_unit_test_github_actio…
Browse files Browse the repository at this point in the history
…n_dev

GitHub Action Workflows for Test Runs on certify
  • Loading branch information
webprofusion-chrisc authored Dec 14, 2023
2 parents b55a691 + 109f7c8 commit 7e662fb
Show file tree
Hide file tree
Showing 23 changed files with 1,149 additions and 114 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/4_6_2_Core_Unit_Tests_Win.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: build and test .NET 4.6.2 Windows

on:
push:
pull_request:
branches: [ release, development ]
paths:
- '**.cs'
- '**.csproj'

env:
DOTNET_VERSION: '8.0.100' # The .NET SDK version to use

jobs:
build-and-test:
# if: ${{ ! always() }}
name: build-and-test-windows
runs-on: windows-latest
steps:
- name: Clone webprofusion/certify
uses: actions/checkout@master
with:
path: ./certify

- name: Clone webprofusion/anvil
uses: actions/checkout@master
with:
repository: webprofusion/anvil
ref: refs/heads/main
path: ./libs/anvil

- name: Clone webprofusion/certify-plugins (development branch push)
if: ${{ github.event_name == 'push' && contains(github.ref_name, '_dev') }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: refs/heads/development
path: ./certify-plugins

- name: Clone webprofusion/certify-plugins (release branch push)
if: ${{ github.event_name == 'push' && contains(github.ref_name, '_rel') }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: refs/heads/release
path: ./certify-plugins

- name: Clone webprofusion/certify-plugins (pull request)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: ${{ github.base_ref }}
path: ./certify-plugins

- name: Setup .NET Core
uses: actions/setup-dotnet@master
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Setup Step CLI
run: |
Invoke-WebRequest -Method 'GET' -uri 'https://dl.smallstep.com/gh-release/cli/docs-cli-install/v0.24.4/step_windows_0.24.4_amd64.zip' -Outfile 'C:\temp\step_windows_0.24.4_amd64.zip'
tar -oxzf C:\temp\step_windows_0.24.4_amd64.zip -C "C:\Program Files"
echo "C:\Program Files\step_0.24.4\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Pull step-ca Docker Image
run: docker pull jrnelson90/step-ca-win

- name: Cache NuGet Dependencies
uses: actions/cache@v3
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-4.6.2-nuget-${{ hashFiles('./certify/src/Certify.Tests/Certify.Core.Tests.Unit/*.csproj') }}
restore-keys: |
${{ runner.os }}-4.6.2-nuget
- name: Install Dependencies & Build Certify.Core.Tests.Unit
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.0
dotnet add package GitHubActionsTestLogger
dotnet add package coverlet.collector
dotnet build -c Debug -f net462 --property WarningLevel=0 /clp:ErrorsOnly
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit

- name: Run Certify.Core.Tests.Unit Tests
run: |
$env:GITHUB_WORKSPACE="$env:GITHUB_WORKSPACE\certify"
$env:GITHUB_STEP_SUMMARY=".\TestResults-4_6_2-${{ runner.os }}\test-summary.md"
dotnet test --no-build -f net462 -l "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true;annotations.messageFormat=@error\n@trace"
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit

- name: Generated Test Results Report
run: |
echo "# Test Results" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
(Get-Content -Path .\TestResults-4_6_2-${{ runner.os }}\test-summary.md).Replace('<details>', '<details open>') | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit
if: ${{ always() }}

- name: Generated Test Coverage Report
run: |
reportgenerator -reports:./TestResults-4_6_2-${{ runner.os }}/*/*.cobertura.xml -targetdir:./TestResults-4_6_2-${{ runner.os }} -reporttypes:MarkdownSummaryGithub "-title:Test Coverage"
Get-Content -Path ./TestResults-4_6_2-${{ runner.os }}/SummaryGithub.md | Out-File -FilePath $env:GITHUB_STEP_SUMMARY
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit
if: ${{ always() }}

# - name: Upload dotnet test Artifacts
# uses: actions/upload-artifact@master
# with:
# name: dotnet-results-${{ runner.os }}-${{ env.DOTNET_VERSION }}
# path: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit/TestResults-4_6_2-${{ runner.os }}
# # Use always() to always run this step to publish test results when there are test failures
# if: ${{ always() }}
114 changes: 114 additions & 0 deletions .github/workflows/8_0_Core_Unit_Tests_Linux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: build and test .NET Core 8.0 Linux

on:
push:
pull_request:
branches: [ release, development ]
paths:
- '**.cs'
- '**.csproj'

env:
DOTNET_VERSION: '8.0.100' # The .NET SDK version to use

jobs:
build-and-test:

name: build-and-test-linux
runs-on: ubuntu-latest
steps:
- name: Clone webprofusion/certify
uses: actions/checkout@master
with:
path: ./certify

- name: Clone webprofusion/anvil
uses: actions/checkout@master
with:
repository: webprofusion/anvil
ref: refs/heads/main
path: ./libs/anvil

- name: Clone webprofusion/certify-plugins (development branch push)
if: ${{ github.event_name == 'push' && contains(github.ref_name, '_dev') }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: refs/heads/development
path: ./certify-plugins

- name: Clone webprofusion/certify-plugins (release branch push)
if: ${{ github.event_name == 'push' && contains(github.ref_name, '_rel') }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: refs/heads/release
path: ./certify-plugins

- name: Clone webprofusion/certify-plugins (pull request)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: ${{ github.base_ref }}
path: ./certify-plugins

- name: Setup .NET Core
uses: actions/setup-dotnet@master
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Setup Step CLI
run: |
wget https://dl.smallstep.com/gh-release/cli/docs-cli-install/v0.23.0/step-cli_0.23.0_amd64.deb
sudo dpkg -i step-cli_0.23.0_amd64.deb
- name: Pull step-ca Docker Image
run: docker pull smallstep/step-ca

- name: Cache NuGet Dependencies
uses: actions/cache@v3
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-${{ env.DOTNET_VERSION }}-nuget-${{ hashFiles('./certify/src/Certify.Tests/Certify.Core.Tests.Unit/*.csproj') }}
restore-keys: |
${{ runner.os }}-${{ env.DOTNET_VERSION }}-nuget
- name: Install Dependencies & Build Certify.Core.Tests.Unit
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.0
dotnet add package GitHubActionsTestLogger
dotnet add package coverlet.collector
dotnet build -c Debug -f net8.0 --property WarningLevel=0 /clp:ErrorsOnly
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit

- name: Run Certify.Core.Tests.Unit Tests
run: |
export GITHUB_WORKSPACE="$GITHUB_WORKSPACE/certify"
export GITHUB_STEP_SUMMARY="./TestResults-8_0-${{ runner.os }}/test-summary.md"
dotnet test --no-build -f net8.0 -l "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true;annotations.messageFormat=@error\n@trace"
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit

- name: Generate Test Results Report
run: |
echo "# Test Results" > $GITHUB_STEP_SUMMARY
sed -i 's/<details>/<details open>/g' ./TestResults-8_0-${{ runner.os }}/test-summary.md
cat ./TestResults-8_0-${{ runner.os }}/test-summary.md >> $GITHUB_STEP_SUMMARY
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit
if: ${{ always() }}

- name: Generated Test Coverage Report
run: |
reportgenerator -reports:./TestResults-8_0-${{ runner.os }}/*/coverage.cobertura.xml -targetdir:./TestResults-8_0-${{ runner.os }} -reporttypes:MarkdownSummaryGithub "-title:Test Coverage"
cat ./TestResults-8_0-${{ runner.os }}/SummaryGithub.md > $GITHUB_STEP_SUMMARY
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit
if: ${{ always() }}

# - name: Upload dotnet test Artifacts
# uses: actions/upload-artifact@master
# with:
# name: dotnet-results-${{ runner.os }}-${{ env.DOTNET_VERSION }}
# path: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit/TestResults-8_0-${{ runner.os }}
# # Use always() to always run this step to publish test results when there are test failures
# if: ${{ always() }}
114 changes: 114 additions & 0 deletions .github/workflows/8_0_Core_Unit_Tests_Win.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: build and test .NET Core 8.0 Windows

on:
push:
pull_request:
branches: [ release, development ]
paths:
- '**.cs'
- '**.csproj'

env:
DOTNET_VERSION: '8.0.100' # The .NET SDK version to use

jobs:
build-and-test:

name: build-and-test-windows
runs-on: windows-latest
steps:
- name: Clone webprofusion/certify
uses: actions/checkout@master
with:
path: ./certify

- name: Clone webprofusion/anvil
uses: actions/checkout@master
with:
repository: webprofusion/anvil
ref: refs/heads/main
path: ./libs/anvil

- name: Clone webprofusion/certify-plugins (development branch push)
if: ${{ github.event_name == 'push' && contains(github.ref_name, '_dev') }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: refs/heads/development
path: ./certify-plugins

- name: Clone webprofusion/certify-plugins (release branch push)
if: ${{ github.event_name == 'push' && contains(github.ref_name, '_rel') }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: refs/heads/release
path: ./certify-plugins

- name: Clone webprofusion/certify-plugins (pull request)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@master
with:
repository: webprofusion/certify-plugins
ref: ${{ github.base_ref }}
path: ./certify-plugins

- name: Setup .NET Core
uses: actions/setup-dotnet@master
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Setup Step CLI
run: |
Invoke-WebRequest -Method 'GET' -uri 'https://dl.smallstep.com/gh-release/cli/docs-cli-install/v0.24.4/step_windows_0.24.4_amd64.zip' -Outfile 'C:\temp\step_windows_0.24.4_amd64.zip'
tar -oxzf C:\temp\step_windows_0.24.4_amd64.zip -C "C:\Program Files"
echo "C:\Program Files\step_0.24.4\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Pull step-ca Docker Image
run: docker pull jrnelson90/step-ca-win

- name: Cache NuGet Dependencies
uses: actions/cache@v3
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-${{ env.DOTNET_VERSION }}-nuget-${{ hashFiles('./certify/src/Certify.Tests/Certify.Core.Tests.Unit/*.csproj') }}
restore-keys: |
${{ runner.os }}-${{ env.DOTNET_VERSION }}-nuget
- name: Install Dependencies & Build Certify.Core.Tests.Unit
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.2.0
dotnet add package GitHubActionsTestLogger
dotnet add package coverlet.collector
dotnet build -c Debug -f net8.0 --property WarningLevel=0 /clp:ErrorsOnly
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit

- name: Run Certify.Core.Tests.Unit Tests
run: |
$env:GITHUB_WORKSPACE="$env:GITHUB_WORKSPACE\certify"
$env:GITHUB_STEP_SUMMARY=".\TestResults-8_0-${{ runner.os }}\test-summary.md"
dotnet test --no-build -f net8.0 -l "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true;annotations.messageFormat=@error\n@trace"
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit

- name: Generate Test Results Report
run: |
echo "# Test Results" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
(Get-Content -Path .\TestResults-8_0-${{ runner.os }}\test-summary.md).Replace('<details>', '<details open>') | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit
if: ${{ always() }}

- name: Generated Test Coverage Report
run: |
reportgenerator -reports:./TestResults-8_0-${{ runner.os }}/*/coverage.cobertura.xml -targetdir:./TestResults-8_0-${{ runner.os }} -reporttypes:MarkdownSummaryGithub "-title:Test Coverage"
Get-Content -Path ./TestResults-8_0-${{ runner.os }}/SummaryGithub.md | Out-File -FilePath $env:GITHUB_STEP_SUMMARY
working-directory: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit
if: ${{ always() }}

# - name: Upload dotnet test Artifacts
# uses: actions/upload-artifact@master
# with:
# name: dotnet-results-${{ runner.os }}-${{ env.DOTNET_VERSION }}
# path: ./certify/src/Certify.Tests/Certify.Core.Tests.Unit/TestResults-8_0-${{ runner.os }}
# # Use always() to always run this step to publish test results when there are test failures
# if: ${{ always() }}
11 changes: 10 additions & 1 deletion src/Certify.Core/Management/CertifyManager/CertifyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,16 @@ public async Task<bool> PerformRenewalTasks()
return await Task.FromResult(true);
}

public void Dispose() => ManagedCertificateLog.DisposeLoggers();
public void Dispose() => Cleanup();

private void Cleanup()
{
ManagedCertificateLog.DisposeLoggers();
if(_tc != null)
{
_tc.Dispose();
}
}

/// <summary>
/// Perform (or preview) an import of settings from another instance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -81,6 +81,7 @@ public async Task TeardownIIS()
{
await iisManager.DeleteSite(testSiteName);
Assert.IsFalse(await iisManager.SiteExists(testSiteName));
certifyManager.Dispose();
}

[TestMethod, TestCategory("MegaTest")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public async Task TeardownIIS()
{
await _iisManager.DeleteSite(_testSiteName);
Assert.IsFalse(await _iisManager.SiteExists(_testSiteName));
_certifyManager.Dispose();
}

[TestMethod, Description("Happy path test for using CertifyManager.GetPrimaryWebSites() for IIS")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public CertifyManagerTests()
_certifyManager.Init().Wait();
}

[TestCleanup] public void Cleanup()
{
_certifyManager.Dispose();
}

[TestMethod, Description("Happy path test for using CertifyManager.GetACMEProvider()")]
public async Task TestCertifyManagerGetACMEProvider()
{
Expand Down
Loading

0 comments on commit 7e662fb

Please sign in to comment.