diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..81b4179 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,140 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + inputs: + force_nuget_publish: + description: Force NuGet publish for non-master builds + type: boolean + default: false + +env: + SOLUTION: NLog.PerformanceCounter.sln + TEST_PROJECT: tests/NLog.PerformanceCounter.Tests/NLog.PerformanceCounter.Tests.csproj + +jobs: + build: + name: ${{ matrix.name }} + strategy: + matrix: + include: + - os: windows-latest + name: Build & test (Windows) + upload_coverage: true + - os: ubuntu-latest + name: Build & test (Ubuntu) + upload_coverage: false + runs-on: ${{ matrix.os }} + permissions: + contents: read + + steps: + - uses: actions/checkout@v7 + + - name: Restore + run: dotnet restore ${{ env.SOLUTION }} + + - name: Build + if: runner.os == 'Windows' + run: dotnet build ${{ env.SOLUTION }} --configuration Release --no-restore + + - name: Build net8.0 + if: runner.os == 'Linux' + run: dotnet build ${{ env.TEST_PROJECT }} --framework net8.0 --configuration Release --no-restore + + - name: Test net461 + if: runner.os == 'Windows' + run: dotnet test ${{ env.TEST_PROJECT }} --framework net461 --configuration Release --no-restore --no-build --logger GitHubActions + + - name: Test net8.0 with coverage + if: runner.os == 'Windows' + run: dotnet test ${{ env.TEST_PROJECT }} --framework net8.0 --configuration Release --no-restore --no-build --collect:"XPlat Code Coverage" --logger GitHubActions + + - name: Test net8.0 on Linux + if: runner.os == 'Linux' + run: dotnet test ${{ env.TEST_PROJECT }} --framework net8.0 --configuration Release --no-restore --no-build --logger GitHubActions + + - name: Upload coverage to Codecov + if: matrix.upload_coverage + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # https://github.com/codecov/codecov-action/releases/tag/v7.1.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: tests/**/TestResults/**/coverage.cobertura.xml + fail_ci_if_error: true + + pack: + name: Create NuGet package + runs-on: windows-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v7 + + - name: Restore + run: dotnet restore ${{ env.SOLUTION }} + + - name: Determine version suffix + id: version + shell: pwsh + env: + REF: ${{ github.ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + RUN_NUMBER: ${{ github.run_number }} + run: | + if ($env:REF -eq "refs/heads/master") { + echo "suffix=" >> $env:GITHUB_OUTPUT + } elseif ($env:PR_NUMBER) { + echo "suffix=pr.$($env:PR_NUMBER).ci.$($env:RUN_NUMBER)" >> $env:GITHUB_OUTPUT + } else { + echo "suffix=ci.$($env:RUN_NUMBER)" >> $env:GITHUB_OUTPUT + } + + - name: Create NuGet package + shell: pwsh + env: + VERSION_SUFFIX: ${{ steps.version.outputs.suffix }} + run: dotnet pack $env:SOLUTION --no-restore --configuration Release --output artifacts -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -p:EmbedUntrackedSources=true -p:PublishRepositoryUrl=true -p:ContinuousIntegrationBuild=true --version-suffix "$env:VERSION_SUFFIX" + + - name: Upload NuGet package + uses: actions/upload-artifact@v7 + with: + name: NuGetPackages + path: | + artifacts/*.nupkg + artifacts/*.snupkg + if-no-files-found: error + + publish: + name: Publish NuGet package + needs: [build, pack] + if: >- + (github.event_name == 'push' && github.ref == 'refs/heads/master') || + (github.event_name == 'workflow_dispatch' && inputs.force_nuget_publish) + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + steps: + - name: Download NuGet package + uses: actions/download-artifact@v7 + with: + name: NuGetPackages + path: artifacts + + - name: NuGet login + uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2 + id: login + with: + user: ${{ secrets.NUGET_USER }} + + - name: Push to NuGet.org + shell: pwsh + env: + NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} + run: dotnet nuget push "artifacts/*.nupkg" --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate \ No newline at end of file diff --git a/.gitignore b/.gitignore index dfcfd56..fadd366 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ mono_crash.* # Build results +N.png [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ diff --git a/NLog.PerformanceCounter.sln b/NLog.PerformanceCounter.sln index f7520c7..7744951 100644 --- a/NLog.PerformanceCounter.sln +++ b/NLog.PerformanceCounter.sln @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLog.PerformanceCounter.Tes EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B9CD43EE-2A8A-4AB8-B2CA-2A3C9190A08D}" ProjectSection(SolutionItems) = preProject - appveyor.yml = appveyor.yml + .github\workflows\ci.yml = .github\workflows\ci.yml README.md = README.md EndProjectSection EndProject diff --git a/README.md b/README.md index ff3ca34..92d5ddc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ NLog extensions to [Display Windows Performance Counters](https://github.com/NLog/NLog/wiki/PerformanceCounter-Layout-Renderer) and [Update Windows Performance Counters](https://github.com/NLog/NLog/wiki/PerfCounter-target) [![Version](https://badge.fury.io/nu/NLog.PerformanceCounter.svg)](https://www.nuget.org/packages/NLog.PerformanceCounter) -[![AppVeyor](https://img.shields.io/appveyor/ci/nlog/NLog-PerformanceCounter/master.svg)](https://ci.appveyor.com/project/nlog/NLog-PerformanceCounter/branch/master) +[![CI](https://github.com/NLog/NLog.PerformanceCounter/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/NLog/NLog.PerformanceCounter/actions/workflows/ci.yml) ### How to install diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 9bd49ac..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: 5.0.0.{build} -image: Visual Studio 2022 -configuration: Release -platform: Any CPU -skip_tags: true -skip_branch_with_pr: true -nuget: - disable_publish_on_pr: true -build_script: -- ps: msbuild /t:restore,pack /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:ContinuousIntegrationBuild=true /p:EmbedUntrackedSources=true /p:PublishRepositoryUrl=true /verbosity:minimal -test_script: -- ps: dotnet test tests\NLog.PerformanceCounter.Tests\NLog.PerformanceCounter.Tests.csproj -artifacts: - - path: '**\NLog.*.nupkg' - - path: '**\NLog.*.snupkg' -deploy: -- provider: NuGet - api_key: - secure: FStb6Kr5sjHdPq4EzjHeXkW4DQDlS92kM9ZWDhApT68+j4WN7J7cnvvk3fj/hMxi - on: - branch: master diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..0ff4876 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,12 @@ +coverage: + precision: 2 + round: down + range: "60...70" + status: + project: + default: + target: 70% + patch: + default: + target: auto + threshold: 1% \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000..552d14f --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,8 @@ + + + true + all + low + $(WarningsAsErrors);NU1900;NU1901;NU1902;NU1903;NU1904 + + \ No newline at end of file diff --git a/src/NLog.PerformanceCounter/NLog.PerformanceCounter.csproj b/src/NLog.PerformanceCounter/NLog.PerformanceCounter.csproj index 685f108..c3c4338 100644 --- a/src/NLog.PerformanceCounter/NLog.PerformanceCounter.csproj +++ b/src/NLog.PerformanceCounter/NLog.PerformanceCounter.csproj @@ -9,15 +9,12 @@ 5.0.0.0 - $(APPVEYOR_BUILD_NUMBER) - 0 - $(VersionPrefix).$(AppVeyorBuildNumber) + $(VersionPrefix).0 NLog Windows PerformanceCounter NLog NLog.PerformanceCounter provides support for Windows Performance Counters - NLog.PerformanceCounter v$(ProductVersion) - $(ProductVersion) + NLog.PerformanceCounter v$(VersionPrefix) Jarek Kowalski,Kim Christensen,Julian Verdurmen $([System.DateTime]::Now.ToString(yyyy)) Copyright (c) 2004-$(CurrentYear) NLog Project - https://nlog-project.org/ @@ -75,7 +72,6 @@ https://github.com/NLog/NLog/wiki/PerformanceCounter-Layout-Renderer - diff --git a/tests/NLog.PerformanceCounter.Tests/NLog.PerformanceCounter.Tests.csproj b/tests/NLog.PerformanceCounter.Tests/NLog.PerformanceCounter.Tests.csproj index ab5d1eb..27bd318 100644 --- a/tests/NLog.PerformanceCounter.Tests/NLog.PerformanceCounter.Tests.csproj +++ b/tests/NLog.PerformanceCounter.Tests/NLog.PerformanceCounter.Tests.csproj @@ -16,7 +16,10 @@ + + + diff --git a/tests/NLog.PerformanceCounter.Tests/PerformanceCounterLayoutRendererTests.cs b/tests/NLog.PerformanceCounter.Tests/PerformanceCounterLayoutRendererTests.cs index 47d7ecf..ced7a00 100644 --- a/tests/NLog.PerformanceCounter.Tests/PerformanceCounterLayoutRendererTests.cs +++ b/tests/NLog.PerformanceCounter.Tests/PerformanceCounterLayoutRendererTests.cs @@ -35,6 +35,7 @@ namespace NLog.PerformanceCounter.Tests { using Xunit; using NLog.LayoutRenderers; + using System; public class PerformanceCounterLayoutRendererTests { @@ -43,9 +44,11 @@ public PerformanceCounterLayoutRendererTests() LogManager.ThrowExceptions = true; } - [Fact] + [SkippableFact] public void PerformanceCounterLayoutRendererTest() { + Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT, "Performance counters are only supported on Windows."); + var logFactory = new LogFactory().Setup().SetupExtensions(ext => ext.RegisterLayoutRenderer("performancecounter")). LoadConfigurationFromXml(@"