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 new file mode 100644 index 0000000..a88d71b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,100 @@ +# 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] + paths-ignore: + - '**.md' + - '.github/workflows/**' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: release + cancel-in-progress: false + +env: + RELEASE_SUFFIX: '' + +jobs: + release: + runs-on: windows-latest + environment: nuget + permissions: + contents: write # GitHub release and tag + id-token: write # Trusted Publishing + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v6 + with: + dotnet-version: '10.x' + + - name: Version + id: version + shell: bash + run: | + 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 + + - name: Restore + run: dotnet restore MessageBus.slnx + + - name: Build + run: > + 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 Release --no-build + + - name: Collect packages + shell: bash + run: | + mkdir -p artifacts + find . -path '*/bin/Release/*' -name 'DSoft.*.nupkg' -exec cp {} artifacts/ \; + ls artifacts + + - uses: actions/upload-artifact@v7 + with: + name: drop + path: artifacts/*.nupkg + + - name: NuGet login + id: nuget + uses: NuGet/login@v1 + with: + user: ${{ secrets.NUGET_USER }} + + - 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: + GH_TOKEN: ${{ github.token }} + run: | + 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 9fec097..0c63e09 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -13,11 +13,11 @@ Solution file is `MessageBus.slnx` (new XML solution format — requires recent ```bash dotnet restore MessageBus.slnx dotnet build MessageBus.slnx --configuration Release -dotnet test UnitTest/UnitTest.csproj # tests target net9.0, MSTest +dotnet test UnitTest/UnitTest.csproj # tests target net10.0, MSTest dotnet test UnitTest/UnitTest.csproj --filter "FullyQualifiedName~MessageBusTest.MethodName" # single test ``` -Building the full `DSoft.Messaging` project requires platform workloads (`dotnet workload restore`) because it multi-targets iOS/Android/macOS/tvos/MacCatalyst/Windows. To iterate quickly without workloads, build/test against a single TFM via the UnitTest project (which references the main project but is consumed as `net9.0`). Note `Directory.Build.props` sets `GeneratePackageOnBuild=true` and signs assemblies with `DSoft.snk`. +Building the full `DSoft.Messaging` project requires platform workloads (`dotnet workload restore`) because it multi-targets iOS/Android/macOS/tvos/MacCatalyst/Windows. To iterate quickly without workloads, build/test against a single TFM via the UnitTest project (which references the main project but is consumed as `net10.0`). Note `Directory.Build.props` sets `GeneratePackageOnBuild=true` and signs assemblies with `DSoft.snk`. ## Architecture @@ -41,7 +41,7 @@ Both routes hit the same `MessageBusService` logic. ### Platform-specific compilation `DSoft.Messaging` uses **filename-suffix conventions** instead of one file per TFM — the `.csproj` includes files by suffix via `EnableDefaultCompileItems=false`: - `*.shared.cs` — all targets -- `*.netstandard.cs` — netstandard/net8/net9/net10/net472 +- `*.netstandard.cs` — netstandard/net8/net10/net472 - `*.wpf.cs` (windows7.0), `*.winui.cs` (windows10), `*.android.cs`, `*.ios.cs` (ios+maccatalyst), `*.mac.cs` (macos), `*.tvos.cs` `ThreadControl` is the main example: `ThreadControl.shared.cs` defines the public API and calls `partial` members (`PlatformIsMainThread`, `PlatformBeginInvokeOnMainThread`) implemented per platform. When adding platform-specific code, add a new `*..cs` partial rather than `#if`. (ThreadControl's `MainThread` logic is adapted from Xamarin.Essentials.) @@ -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`). -- Version/release notes live in the `.csproj` PropertyGroups (`Version`, `AssemblyVersion`, `PackageReleaseNotes`); bump there for releases. +- 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/DSoft.Messaging/DSoft.MessageBus.csproj b/DSoft.Messaging/DSoft.MessageBus.csproj index 8df354b..cbb5248 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..40eea56 100644 --- a/MessageBus.slnx +++ b/MessageBus.slnx @@ -9,8 +9,8 @@ - - + + diff --git a/README.md b/README.md index 5943da9..f217c22 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/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: the nuget.org policy trusts workflow `release.yml` in environment `nuget`, and the `NUGET_USER` secret holds the nuget.org profile name. + ### 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/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)] diff --git a/UnitTest/UnitTest.csproj b/UnitTest/UnitTest.csproj index 159e8d9..de536f9 100644 --- a/UnitTest/UnitTest.csproj +++ b/UnitTest/UnitTest.csproj @@ -1,7 +1,7 @@ - net9.0 + net10.0 enable enable False @@ -11,14 +11,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/WPFSample/WPFSample.csproj b/WPFSample/WPFSample.csproj index b8529b7..7993a8b 100644 --- a/WPFSample/WPFSample.csproj +++ b/WPFSample/WPFSample.csproj @@ -2,7 +2,7 @@ WinExe - net9.0-windows + net10.0-windows true False False 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 bea3fa8..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.4.$(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'