From 5b02a7180cf3b12db087374125a9151cfb6e753b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Oct 2026 20:29:26 +0000 Subject: [PATCH 1/4] Update to .NET 10 and latest packages; move CI/CD to GitHub Actions - Target netstandard2.1, net472, net8.0 and net10.0 (incl. iOS, macOS, Mac Catalyst, tvOS, Android, WPF and WinUI); drop .NET 9 targets - Update Microsoft.Extensions.DependencyInjection(.Abstractions) to 10.0.12, WindowsAppSDK to 1.8, Windows SDK BuildTools, MSTest 4, Test SDK, coverlet and DSoft.System.Mvvm - Move UnitTest and WPFSample to .NET 10 - Use the SDK's built-in Source Link, set ContinuousIntegrationBuild on GitHub Actions, add MIT license expression to packages - Replace Azure Pipelines with GitHub Actions build and release workflows; release publishes to nuget.org using the NUGET_API_KEY secret Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TreMhFY8KtDPoVeKPL7NzX --- .github/workflows/build.yml | 50 ++++++++++++ .github/workflows/release.yml | 104 ++++++++++++++++++++++++ DSoft.Messaging/DSoft.MessageBus.csproj | 22 ++--- Directory.Build.props | 10 +-- MessageBus.slnx | 4 +- README.md | 11 ++- UnitTest/UnitTest.csproj | 12 +-- WPFSample/WPFSample.csproj | 4 +- azure-pipelines-mergetest.yml | 51 ------------ azure-pipelines-release.yml | 75 ----------------- 10 files changed, 186 insertions(+), 157 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml delete mode 100644 azure-pipelines-mergetest.yml delete mode 100644 azure-pipelines-release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a0d7bcf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build + +on: + push: + branches-ignore: + - main + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + DOTNET_NOLOGO: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + BUILD_CONFIGURATION: Release + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + + - name: Restore workloads + run: dotnet workload restore DSoft.Messaging/DSoft.MessageBus.csproj + + - name: Restore + run: dotnet restore MessageBus.slnx + + - name: Build + run: dotnet build MessageBus.slnx --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore + + - name: Test + run: dotnet test UnitTest/UnitTest.csproj --configuration ${{ env.BUILD_CONFIGURATION }} --no-build + + - name: Upload packages + uses: actions/upload-artifact@v4 + with: + name: packages + path: '**/bin/${{ env.BUILD_CONFIGURATION }}/DSoft.*.nupkg' + if-no-files-found: error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..63c55cb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,104 @@ +name: Release + +on: + push: + branches: + - main + paths-ignore: + - '.github/**' + workflow_dispatch: + inputs: + version: + description: 'Package version (leave blank to generate one)' + required: false + type: string + publish: + description: 'Publish to nuget.org' + required: false + type: boolean + default: true + +concurrency: + group: release + cancel-in-progress: false + +env: + DOTNET_NOLOGO: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + BUILD_CONFIGURATION: Release + VERSION_PREFIX: '4.4' + +jobs: + release: + runs-on: windows-latest + environment: nuget + + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + + - name: Calculate version + id: version + shell: pwsh + run: | + $version = '${{ inputs.version }}' + if ([string]::IsNullOrWhiteSpace($version)) { + # .., e.g. 4.4.2610.12 + $version = "$env:VERSION_PREFIX.$((Get-Date).ToUniversalTime().ToString('yyMM')).${{ github.run_number }}" + } + # AssemblyVersion/FileVersion must be numeric (strip any prerelease suffix) + $assemblyVersion = ($version -split '-')[0] + "version=$version" >> $env:GITHUB_OUTPUT + "assembly_version=$assemblyVersion" >> $env:GITHUB_OUTPUT + Write-Host "Version: $version" + + - name: Restore workloads + run: dotnet workload restore DSoft.Messaging/DSoft.MessageBus.csproj + + - name: Restore + run: dotnet restore MessageBus.slnx + + - name: Build + run: > + dotnet build MessageBus.slnx --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore + -p:Version=${{ steps.version.outputs.version }} + -p:AssemblyVersion=${{ steps.version.outputs.assembly_version }} + -p:FileVersion=${{ steps.version.outputs.assembly_version }} + + - name: Test + run: dotnet test UnitTest/UnitTest.csproj --configuration ${{ env.BUILD_CONFIGURATION }} --no-build + + - name: Collect packages + shell: pwsh + run: | + New-Item -ItemType Directory -Force -Path artifacts | Out-Null + Get-ChildItem -Recurse -Path . -Include 'DSoft.*.nupkg' | + Where-Object { $_.FullName -match "[\\/]bin[\\/]$env:BUILD_CONFIGURATION[\\/]" } | + Copy-Item -Destination artifacts + Get-ChildItem artifacts + + - name: Upload packages + uses: actions/upload-artifact@v4 + with: + name: packages-${{ steps.version.outputs.version }} + path: artifacts/*.nupkg + if-no-files-found: error + + - name: Publish to nuget.org + if: github.event_name == 'push' || inputs.publish + shell: pwsh + env: + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + run: | + if ([string]::IsNullOrWhiteSpace($env:NUGET_API_KEY)) { + throw 'The NUGET_API_KEY secret is not set.' + } + Get-ChildItem artifacts -Filter *.nupkg | ForEach-Object { + dotnet nuget push $_.FullName --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate + } diff --git a/DSoft.Messaging/DSoft.MessageBus.csproj b/DSoft.Messaging/DSoft.MessageBus.csproj index 9c3198b..6a5e2b2 100644 --- a/DSoft.Messaging/DSoft.MessageBus.csproj +++ b/DSoft.Messaging/DSoft.MessageBus.csproj @@ -1,21 +1,15 @@  - netstandard2.1;net9.0;net9.0-ios;net9.0-macos;net9.0-maccatalyst;net9.0-tvos;net9.0-android;net10.0;net10.0-ios;net10.0-macos;net10.0-maccatalyst;net10.0-tvos;net10.0-android; - $(TargetFrameworks);net8.0; - $(TargetFrameworks);net472;net9.0-windows7.0;net9.0-windows10.0.19041;net10.0-windows7.0;net10.0-windows10.0.19041; - $(TargetFrameworks);net8.0-windows7.0;net8.0-windows10.0.19041; + netstandard2.1;net8.0;net10.0;net10.0-ios;net10.0-macos;net10.0-maccatalyst;net10.0-tvos;net10.0-android; + $(TargetFrameworks);net472;net8.0-windows7.0;net10.0-windows7.0;net10.0-windows10.0.19041; DSoft.MessageBus - 1.3.4 DSoft.MessageBus DSoft Developments $(AssemblyName) ($(TargetFramework)) DSoft.MessageBus MessageBus is a cross platform EventBus system similar to NSNoticationCenter on iOS and otto on Android © DSoft Developments. All rights reserved. - 1.3.5.0 - 1.3.5.0 false - 1.3.4.0 MessageBus false $(DefineConstants); @@ -31,8 +25,8 @@ 15.0 14.0 $(NoWarn);NETSDK1206;CA1416; - Re-Added .NET framework 4.7.2 support - Added generic "Post" method + Updated to .NET 10 and latest dependencies + Removed .NET 9 targets (.NET 8 and .NET 10 LTS remain supported) @@ -65,7 +59,7 @@ - + @@ -76,8 +70,8 @@ - - + + @@ -105,7 +99,7 @@ - + diff --git a/Directory.Build.props b/Directory.Build.props index 8b23830..8c5551d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,6 +2,7 @@ true true + MIT false https://github.com/newky2k/MessageBus https://github.com/newky2k/MessageBus @@ -24,16 +25,13 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - - - - + + true True - $(MSBuildProjectDirectory)\DSoft.snk + $(MSBuildProjectDirectory)/DSoft.snk \ No newline at end of file diff --git a/MessageBus.slnx b/MessageBus.slnx index de09972..abcefaa 100644 --- a/MessageBus.slnx +++ b/MessageBus.slnx @@ -9,8 +9,8 @@ - - + + diff --git a/README.md b/README.md index 5943da9..81a9c6d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ MessageBus is a cross platform EventBus system similar to `NSNoticationCenter` o # Features * Cross-platform - * .NETStandard 2.1, .NET 8+ including iOS, TVOS, Android, UWP, Mac and Windows with support for WPF and WinUI + * .NETStandard 2.1, .NET Framework 4.7.2, .NET 8 and .NET 10 including iOS, tvOS, Android, Mac Catalyst, macOS and Windows with support for WPF and WinUI * Small footprint * Simple API * Create custom events to easily pass additional data @@ -26,6 +26,15 @@ You can then inject `IMessageBusService` into your own services. Please check the Unit tests and sample WPF app for examples of usage +## Building and releasing + +Builds run on GitHub Actions: + +* `.github/workflows/build.yml` builds and tests every pull request and every push to a branch other than `main`, and uploads the packages as a build artifact. +* `.github/workflows/release.yml` runs on every push to `main` (or manually from the Actions tab). It builds, tests, versions the packages as `4.4..` (or the version you enter when running it manually) and pushes them to nuget.org. + +Publishing needs a nuget.org API key stored as the `NUGET_API_KEY` secret (repository secret, or a secret of the `nuget` environment). + ### Attribution `ThreadControl` contains portions of code from [Xamarin.Essentials](https://github.com/xamarin/Essentials/tree/master/Xamarin.Essentials/MainThread), specifically the `MainThread` functionality diff --git a/UnitTest/UnitTest.csproj b/UnitTest/UnitTest.csproj index 0847a30..b4e1614 100644 --- a/UnitTest/UnitTest.csproj +++ b/UnitTest/UnitTest.csproj @@ -1,7 +1,7 @@ - net9.0 + net10.0 enable enable False @@ -11,11 +11,11 @@ - - - - - + + + + + diff --git a/WPFSample/WPFSample.csproj b/WPFSample/WPFSample.csproj index 9a1f577..7993a8b 100644 --- a/WPFSample/WPFSample.csproj +++ b/WPFSample/WPFSample.csproj @@ -2,7 +2,7 @@ WinExe - net9.0-windows + net10.0-windows true False False @@ -10,7 +10,7 @@ - + diff --git a/azure-pipelines-mergetest.yml b/azure-pipelines-mergetest.yml deleted file mode 100644 index ba2589c..0000000 --- a/azure-pipelines-mergetest.yml +++ /dev/null @@ -1,51 +0,0 @@ -# .NET Desktop -# Build and run tests for .NET Desktop or Windows classic desktop solutions. -# Add steps that publish symbols, save build artifacts, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net - -trigger: none - -pool: - vmImage: 'windows-latest' - -variables: - solution: '**/*.slnx' - buildPlatform: 'Any CPU' - buildConfiguration: 'Release' - netVersion: '10.x' - -steps: -- task: NuGetToolInstaller@1 - displayName: Install Latest Nuget - -- task: UseDotNet@2 - displayName: 'Install .NET sdk' - inputs: - packageType: 'sdk' - version: $(netVersion) - -- task: Bash@3 - displayName: Restore Workloads - inputs: - targetType: 'inline' - script: - dotnet workload restore - -# - task: Bash@3 -# displayName: Install MAUI -# inputs: -# targetType: 'inline' -# script: -# dotnet workload install android ios maccatalyst tvos macos maui wasm-tools - -- task: DotNetCoreCLI@2 - displayName: dotnet restore - inputs: - command: 'restore' - projects: '$(solution)' - -- task: DotNetCoreCLI@2 - displayName: dotnet build - inputs: - projects: '$(solution)' - arguments: '--configuration=$(buildConfiguration) /p:Platform="$(buildPlatform)"' diff --git a/azure-pipelines-release.yml b/azure-pipelines-release.yml deleted file mode 100644 index cc1c114..0000000 --- a/azure-pipelines-release.yml +++ /dev/null @@ -1,75 +0,0 @@ -# .NET Desktop -# Build and run tests for .NET Desktop or Windows classic desktop solutions. -# Add steps that publish symbols, save build artifacts, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net - -trigger: - batch: true - branches: - include: - - main - paths: - exclude: - - '*.yml' - -pool: - vmImage: 'windows-latest' - -variables: - solution: '**/*.slnx' - buildPlatform: 'Any CPU' - buildConfiguration: 'Release' - netVersion: '10.x' - releaseSuffix: '' - -name: 4.3.$(date:yyMM).$(date:dd)$(rev:r) -steps: -- task: NuGetToolInstaller@1 - displayName: Install Latest Nuget - -- task: UseDotNet@2 - displayName: 'Install .NET sdk' - inputs: - packageType: 'sdk' - version: $(netVersion) - -- task: Bash@3 - displayName: Restore Workloads - inputs: - targetType: 'inline' - script: - dotnet workload restore - -# - task: Bash@3 -# displayName: Install MAUI -# inputs: -# targetType: 'inline' -# script: -# dotnet workload install android ios maccatalyst tvos macos maui wasm-tools - -- task: DotNetCoreCLI@2 - displayName: dotnet restore - inputs: - command: 'restore' - projects: '$(solution)' - -- task: DotNetCoreCLI@2 - displayName: dotnet build - inputs: - projects: '$(solution)' - arguments: '--configuration=$(buildConfiguration) /p:Platform="$(buildPlatform)" /p:Version=$(Build.BuildNumber)$(releaseSuffix) /p:AssemblyVersion=$(Build.BuildNumber) /p:FileVersion=$(Build.BuildNumber) ' - -- task: CopyFiles@2 - displayName: Copy Files to $(build.artifactstagingdirectory) - inputs: - SourceFolder: '$(system.defaultworkingdirectory)' - Contents: '**/Dsoft.*.nupkg' - TargetFolder: '$(build.artifactstagingdirectory)' - flattenFolders: true - -- task: PublishBuildArtifacts@1 - displayName: Publish Artifacts drop - inputs: - PathtoPublish: '$(Build.ArtifactStagingDirectory)' - ArtifactName: 'drop' - publishLocation: 'Container' From 9494775ec83ac7666aafcad8cc1a322a02258704 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Oct 2026 20:45:38 +0000 Subject: [PATCH 2/4] Use latest GitHub Actions versions and fix MSTest obsolete warning - actions/checkout v7, actions/setup-dotnet v6, actions/upload-artifact v7 (removes the Node.js 20 deprecation warning) - Replace obsolete [DataTestMethod] with [TestMethod] (MSTEST0044) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TreMhFY8KtDPoVeKPL7NzX --- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 6 +++--- UnitTest/ConcurrencyTest.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a0d7bcf..c53b30b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,12 +21,12 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 with: fetch-depth: 0 - name: Setup .NET - uses: actions/setup-dotnet@v5 + uses: actions/setup-dotnet@v6 with: dotnet-version: 10.0.x @@ -43,7 +43,7 @@ jobs: run: dotnet test UnitTest/UnitTest.csproj --configuration ${{ env.BUILD_CONFIGURATION }} --no-build - name: Upload packages - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: packages path: '**/bin/${{ env.BUILD_CONFIGURATION }}/DSoft.*.nupkg' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c08629..8cb8519 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,12 +34,12 @@ jobs: environment: nuget steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 with: fetch-depth: 0 - name: Setup .NET - uses: actions/setup-dotnet@v5 + uses: actions/setup-dotnet@v6 with: dotnet-version: 10.0.x @@ -84,7 +84,7 @@ jobs: Get-ChildItem artifacts - name: Upload packages - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: packages-${{ steps.version.outputs.version }} path: artifacts/*.nupkg diff --git a/UnitTest/ConcurrencyTest.cs b/UnitTest/ConcurrencyTest.cs index c035146..e1ce734 100644 --- a/UnitTest/ConcurrencyTest.cs +++ b/UnitTest/ConcurrencyTest.cs @@ -20,7 +20,7 @@ private static IMessageBusService NewBus() /// underlying Collection<T> and threw "Collection was modified" / /// IndexOutOfRange. Passing means no handler-collection corruption. /// - [DataTestMethod] + [TestMethod] [DataRow(1)] [DataRow(2)] [DataRow(3)] From 5174df13b7286eea8a0fc626b9f9ad7ee419fc6b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Oct 2026 21:00:34 +0000 Subject: [PATCH 3/4] Publish to nuget.org with NuGet trusted publishing Replace the stored NUGET_API_KEY with NuGet/login (OIDC), which exchanges the GitHub Actions token for a short-lived nuget.org API key. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TreMhFY8KtDPoVeKPL7NzX --- .github/workflows/release.yml | 15 +++++++++++---- CLAUDE.md | 2 +- README.md | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8cb8519..a9f7ee7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,6 +32,9 @@ jobs: release: runs-on: windows-latest environment: nuget + permissions: + contents: read + id-token: write # required for NuGet trusted publishing (OIDC) steps: - uses: actions/checkout@v7 @@ -90,15 +93,19 @@ jobs: path: artifacts/*.nupkg if-no-files-found: error + - name: NuGet login (trusted publishing) + id: nuget-login + if: github.event_name == 'push' || inputs.publish + uses: NuGet/login@v1 + with: + user: ${{ secrets.NUGET_USER }} + - name: Publish to nuget.org if: github.event_name == 'push' || inputs.publish shell: pwsh env: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }} run: | - if ([string]::IsNullOrWhiteSpace($env:NUGET_API_KEY)) { - throw 'The NUGET_API_KEY secret is not set.' - } Get-ChildItem artifacts -Filter *.nupkg | ForEach-Object { dotnet nuget push $_.FullName --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate } diff --git a/CLAUDE.md b/CLAUDE.md index a5c2823..351f626 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -49,4 +49,4 @@ Both routes hit the same `MessageBusService` logic. ## Conventions - Keep `IMessageBusService`, the static `MessageBus` facade, and `MessageBusService` in sync — all three expose the same Post/Subscribe/Unsubscribe/Log surface. - New public APIs need XML doc comments (`GenerateDocumentationFile=true`; many nullable/doc warnings are suppressed in `Directory.Build.props`). -- Release notes live in `PackageReleaseNotes` in the `.csproj`. Package/assembly versions are set by CI: `.github/workflows/release.yml` builds `4.5..` (prefix in `VERSION_PREFIX`) on every push to `main` and publishes to nuget.org; `.github/workflows/build.yml` builds and tests PRs and other branches. +- Release notes live in `PackageReleaseNotes` in the `.csproj`. Package/assembly versions are set by CI: `.github/workflows/release.yml` builds `4.5..` (prefix in `VERSION_PREFIX`) on every push to `main` and publishes to nuget.org via NuGet trusted publishing (OIDC, `NUGET_USER` secret); `.github/workflows/build.yml` builds and tests PRs and other branches. diff --git a/README.md b/README.md index cee1bef..eb40871 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Builds run on GitHub Actions: * `.github/workflows/build.yml` builds and tests every pull request and every push to a branch other than `main`, and uploads the packages as a build artifact. * `.github/workflows/release.yml` runs on every push to `main` (or manually from the Actions tab). It builds, tests, versions the packages as `4.5..` (or the version you enter when running it manually) and pushes them to nuget.org. -Publishing needs a nuget.org API key stored as the `NUGET_API_KEY` secret (repository secret, or a secret of the `nuget` environment). +Publishing uses [NuGet trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing), so no API key is stored. On nuget.org add a trusted publishing policy for repository owner `newky2k`, repository `MessageBus`, workflow file `release.yml` (environment `nuget`), and set the `NUGET_USER` secret in GitHub to your nuget.org profile name. ### Attribution From c4a2447100ad8a7c1273ca3e072558319f329b64 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 5 Oct 2026 18:04:58 +0000 Subject: [PATCH 4/4] Split CI and release workflows to match DSoft.DataPrivacy - ci.yml validates pull requests into main (build Release + tests), publishes nothing; replaces build.yml - release.yml follows the DSoft.DataPrivacy release: 4.5.yyMM. with optional RELEASE_SUFFIX, trusted publishing to nuget.org, then tags the commit and creates a GitHub release with the packages attached Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TreMhFY8KtDPoVeKPL7NzX --- .github/workflows/build.yml | 50 --------------- .github/workflows/ci.yml | 36 +++++++++++ .github/workflows/release.yml | 115 +++++++++++++++------------------- CLAUDE.md | 2 +- MessageBus.slnx | 2 +- README.md | 6 +- 6 files changed, 93 insertions(+), 118 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index c53b30b..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Build - -on: - push: - branches-ignore: - - main - pull_request: - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -env: - DOTNET_NOLOGO: true - DOTNET_CLI_TELEMETRY_OPTOUT: true - BUILD_CONFIGURATION: Release - -jobs: - build: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - - name: Setup .NET - uses: actions/setup-dotnet@v6 - with: - dotnet-version: 10.0.x - - - name: Restore workloads - run: dotnet workload restore DSoft.Messaging/DSoft.MessageBus.csproj - - - name: Restore - run: dotnet restore MessageBus.slnx - - - name: Build - run: dotnet build MessageBus.slnx --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore - - - name: Test - run: dotnet test UnitTest/UnitTest.csproj --configuration ${{ env.BUILD_CONFIGURATION }} --no-build - - - name: Upload packages - uses: actions/upload-artifact@v7 - with: - name: packages - path: '**/bin/${{ env.BUILD_CONFIGURATION }}/DSoft.*.nupkg' - if-no-files-found: error diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..42838e2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +# Pull request validation: builds Release and runs the tests. Publishes nothing. +name: CI + +on: + pull_request: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v6 + with: + dotnet-version: '10.x' + + - name: Restore workloads + run: dotnet workload restore DSoft.Messaging/DSoft.MessageBus.csproj + + - name: Restore + run: dotnet restore MessageBus.slnx + + - name: Build + run: dotnet build MessageBus.slnx --configuration Release --no-restore + + - name: Test + run: dotnet test UnitTest/UnitTest.csproj --configuration Release --no-build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a9f7ee7..a88d71b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,65 +1,51 @@ +# Release: on every push to main, builds Release, runs the tests and pushes the +# DSoft.*.nupkg packages to nuget.org as 4.5.yyMM., then tags the +# commit and creates a GitHub release with the packages attached. +# RELEASE_SUFFIX is empty for a stable version; set it to a suffix such as +# '-prerelease' to publish a prerelease. +# Signs in to nuget.org with Trusted Publishing (OIDC), so no API key is stored. name: Release on: push: - branches: - - main + branches: [main] paths-ignore: - - '.github/**' + - '**.md' + - '.github/workflows/**' workflow_dispatch: - inputs: - version: - description: 'Package version (leave blank to generate one)' - required: false - type: string - publish: - description: 'Publish to nuget.org' - required: false - type: boolean - default: true + +permissions: + contents: read concurrency: group: release cancel-in-progress: false env: - DOTNET_NOLOGO: true - DOTNET_CLI_TELEMETRY_OPTOUT: true - BUILD_CONFIGURATION: Release - VERSION_PREFIX: '4.5' + RELEASE_SUFFIX: '' jobs: release: runs-on: windows-latest environment: nuget permissions: - contents: read - id-token: write # required for NuGet trusted publishing (OIDC) - + contents: write # GitHub release and tag + id-token: write # Trusted Publishing steps: - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - name: Setup .NET - uses: actions/setup-dotnet@v6 + - uses: actions/setup-dotnet@v6 with: - dotnet-version: 10.0.x + dotnet-version: '10.x' - - name: Calculate version + - name: Version id: version - shell: pwsh + shell: bash run: | - $version = '${{ inputs.version }}' - if ([string]::IsNullOrWhiteSpace($version)) { - # .., e.g. 4.5.2610.12 - $version = "$env:VERSION_PREFIX.$((Get-Date).ToUniversalTime().ToString('yyMM')).${{ github.run_number }}" - } - # AssemblyVersion/FileVersion must be numeric (strip any prerelease suffix) - $assemblyVersion = ($version -split '-')[0] - "version=$version" >> $env:GITHUB_OUTPUT - "assembly_version=$assemblyVersion" >> $env:GITHUB_OUTPUT - Write-Host "Version: $version" + version="4.5.$(date -u +%y%m).${{ github.run_number }}" + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "package=$version$RELEASE_SUFFIX" >> "$GITHUB_OUTPUT" + echo "Version: $version$RELEASE_SUFFIX" - name: Restore workloads run: dotnet workload restore DSoft.Messaging/DSoft.MessageBus.csproj @@ -69,43 +55,46 @@ jobs: - name: Build run: > - dotnet build MessageBus.slnx --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore - -p:Version=${{ steps.version.outputs.version }} - -p:AssemblyVersion=${{ steps.version.outputs.assembly_version }} - -p:FileVersion=${{ steps.version.outputs.assembly_version }} + dotnet build MessageBus.slnx --configuration Release --no-restore + /p:Version=${{ steps.version.outputs.package }} + /p:AssemblyVersion=${{ steps.version.outputs.version }} + /p:FileVersion=${{ steps.version.outputs.version }} - name: Test - run: dotnet test UnitTest/UnitTest.csproj --configuration ${{ env.BUILD_CONFIGURATION }} --no-build + run: dotnet test UnitTest/UnitTest.csproj --configuration Release --no-build - name: Collect packages - shell: pwsh + shell: bash run: | - New-Item -ItemType Directory -Force -Path artifacts | Out-Null - Get-ChildItem -Recurse -Path . -Include 'DSoft.*.nupkg' | - Where-Object { $_.FullName -match "[\\/]bin[\\/]$env:BUILD_CONFIGURATION[\\/]" } | - Copy-Item -Destination artifacts - Get-ChildItem artifacts - - - name: Upload packages - uses: actions/upload-artifact@v7 + mkdir -p artifacts + find . -path '*/bin/Release/*' -name 'DSoft.*.nupkg' -exec cp {} artifacts/ \; + ls artifacts + + - uses: actions/upload-artifact@v7 with: - name: packages-${{ steps.version.outputs.version }} + name: drop path: artifacts/*.nupkg - if-no-files-found: error - - name: NuGet login (trusted publishing) - id: nuget-login - if: github.event_name == 'push' || inputs.publish + - name: NuGet login + id: nuget uses: NuGet/login@v1 with: user: ${{ secrets.NUGET_USER }} - - name: Publish to nuget.org - if: github.event_name == 'push' || inputs.publish - shell: pwsh + - name: Push to nuget.org + shell: bash + run: | + for package in artifacts/*.nupkg; do + dotnet nuget push "$package" --api-key "${{ steps.nuget.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate + done + + - name: GitHub release + shell: bash env: - NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }} + GH_TOKEN: ${{ github.token }} run: | - Get-ChildItem artifacts -Filter *.nupkg | ForEach-Object { - dotnet nuget push $_.FullName --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate - } + gh release create "v${{ steps.version.outputs.package }}" artifacts/*.nupkg \ + --target "${{ github.sha }}" \ + --title "${{ steps.version.outputs.package }}" \ + --generate-notes \ + ${RELEASE_SUFFIX:+--prerelease} diff --git a/CLAUDE.md b/CLAUDE.md index 351f626..0c63e09 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -49,4 +49,4 @@ Both routes hit the same `MessageBusService` logic. ## Conventions - Keep `IMessageBusService`, the static `MessageBus` facade, and `MessageBusService` in sync — all three expose the same Post/Subscribe/Unsubscribe/Log surface. - New public APIs need XML doc comments (`GenerateDocumentationFile=true`; many nullable/doc warnings are suppressed in `Directory.Build.props`). -- Release notes live in `PackageReleaseNotes` in the `.csproj`. Package/assembly versions are set by CI: `.github/workflows/release.yml` builds `4.5..` (prefix in `VERSION_PREFIX`) on every push to `main` and publishes to nuget.org via NuGet trusted publishing (OIDC, `NUGET_USER` secret); `.github/workflows/build.yml` builds and tests PRs and other branches. +- Release notes live in `PackageReleaseNotes` in the `.csproj`. Package/assembly versions are set by CI: `.github/workflows/release.yml` builds `4.5..` (plus `RELEASE_SUFFIX`) on every push to `main`, publishes to nuget.org via NuGet trusted publishing (OIDC, `NUGET_USER` secret), then tags `v` and creates a GitHub release; `.github/workflows/ci.yml` builds and tests pull requests into `main`. diff --git a/MessageBus.slnx b/MessageBus.slnx index abcefaa..40eea56 100644 --- a/MessageBus.slnx +++ b/MessageBus.slnx @@ -9,7 +9,7 @@ - + diff --git a/README.md b/README.md index eb40871..f217c22 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,10 @@ Please check the Unit tests and sample WPF app for examples of usage Builds run on GitHub Actions: -* `.github/workflows/build.yml` builds and tests every pull request and every push to a branch other than `main`, and uploads the packages as a build artifact. -* `.github/workflows/release.yml` runs on every push to `main` (or manually from the Actions tab). It builds, tests, versions the packages as `4.5..` (or the version you enter when running it manually) and pushes them to nuget.org. +* `.github/workflows/ci.yml` validates every pull request into `main`: it builds Release and runs the tests, and publishes nothing. +* `.github/workflows/release.yml` runs on every push to `main` (or manually from the Actions tab). It builds, tests, pushes the packages to nuget.org as `4.5..`, then tags the commit and creates a GitHub release with the packages attached. Set `RELEASE_SUFFIX` (e.g. `-prerelease`) to publish a prerelease. -Publishing uses [NuGet trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing), so no API key is stored. On nuget.org add a trusted publishing policy for repository owner `newky2k`, repository `MessageBus`, workflow file `release.yml` (environment `nuget`), and set the `NUGET_USER` secret in GitHub to your nuget.org profile name. +Publishing uses [NuGet trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing), so no API key is stored: the nuget.org policy trusts workflow `release.yml` in environment `nuget`, and the `NUGET_USER` secret holds the nuget.org profile name. ### Attribution