Skip to content
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
36 changes: 0 additions & 36 deletions .github/workflows/publish.yml

This file was deleted.

133 changes: 133 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Release

# Publishes AsyncMonolith and AsyncMonolith.TestHelpers to nuget.org with trusted publishing: GitHub issues a
# short-lived OIDC token, nuget.org exchanges it for a one-hour API key, and no long-lived key is stored.
#
# - Push a tag such as v11.0.0 to release. The tag must match <VersionPrefix> in Directory.Build.props.
# - Run it manually ("Run workflow") for a dry run: everything except publishing.
#
# The nuget.org account that owns the trusted publishing policy for this workflow file is "aptacode".
on:
push:
tags:
- 'v*'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: release
cancel-in-progress: false

jobs:
test:
name: Full test suite
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Build
run: dotnet build AsyncMonolith.sln -c Release

- name: Fast and integration tests
run: dotnet test --project AsyncMonolith.Tests -c Release --no-build

package:
name: Pack
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Read the version
id: version
run: |
version=$(dotnet msbuild AsyncMonolith/AsyncMonolith.csproj -getProperty:Version)
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Packing $version"
if [[ "$GITHUB_REF_TYPE" == "tag" && "$GITHUB_REF_NAME" != "v$version" ]]; then
echo "::error::Tag $GITHUB_REF_NAME does not match the version in Directory.Build.props ($version)."
exit 1
fi

- name: Check the release notes
run: |
version="${{ steps.version.outputs.version }}"
awk -v v="$version" '/^## /{p=($2==v)} p' docs/releases.md > release-notes.md
if [[ ! -s release-notes.md ]]; then
echo "::error::docs/releases.md has no '## $version' section."
exit 1
fi

- name: Pack
run: |
dotnet pack AsyncMonolith/AsyncMonolith.csproj -c Release --output nupkg
dotnet pack AsyncMonolith.TestHelpers/AsyncMonolith.TestHelpers.csproj -c Release --output nupkg
ls -l nupkg

- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: packages
path: |
nupkg/
release-notes.md

publish:
name: Publish to nuget.org
needs: package
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # trusted publishing
contents: write # GitHub release
steps:
- name: Download packages
uses: actions/download-artifact@v4
with:
name: packages

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x

# The API key lasts an hour, so ask for it right before pushing.
- name: NuGet login (OIDC to temporary API key)
uses: NuGet/login@v1
id: login
with:
user: aptacode # nuget.org profile name that owns the trusted publishing policy

- name: Push packages
run: >-
dotnet nuget push "nupkg/*.nupkg"
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}"
--source https://api.nuget.org/v3/index.json
--skip-duplicate

- name: Create the GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: >-
gh release create "$GITHUB_REF_NAME" nupkg/*.nupkg
--repo "$GITHUB_REPOSITORY"
--title "AsyncMonolith ${{ needs.package.outputs.version }}"
--notes-file release-notes.md
--verify-tag
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:
name: coverage-fast
path: coverage/

- name: Pack (checks package validation and metadata)
run: |
dotnet pack AsyncMonolith/AsyncMonolith.csproj -c Release --output nupkg
dotnet pack AsyncMonolith.TestHelpers/AsyncMonolith.TestHelpers.csproj -c Release --output nupkg

integration:
if: github.event_name == 'workflow_dispatch' && inputs.integration
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion AsyncMonolith.TestHelpers/AsyncMonolith.TestHelpers.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsAsyncMonolithPackage>true</IsAsyncMonolithPackage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>AsyncMonolith.TestHelpers</PackageId>
<Description>Fakes and helpers for testing AsyncMonolith consumers with xunit v3.</Description>
Expand Down
2 changes: 1 addition & 1 deletion AsyncMonolith/AsyncMonolith.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsAsyncMonolithPackage>true</IsAsyncMonolithPackage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>AsyncMonolith</PackageId>
<Description>Transactional outbox, background consumers and scheduled messages for .NET monoliths on EF Core.</Description>
Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<!-- Metadata for the published packages (the projects with GeneratePackageOnBuild). -->
<PropertyGroup Condition="'$(GeneratePackageOnBuild)' == 'true'">
<!-- Metadata for the published packages (the projects with IsAsyncMonolithPackage). -->
<PropertyGroup Condition="'$(IsAsyncMonolithPackage)' == 'true'">
<Authors>Tim Jones</Authors>
<Company>Aptacode</Company>
<Copyright>Copyright (c) Tim Jones</Copyright>
Expand All @@ -24,7 +24,7 @@
<EnablePackageValidation>true</EnablePackageValidation>
</PropertyGroup>

<ItemGroup Condition="'$(GeneratePackageOnBuild)' == 'true'">
<ItemGroup Condition="'$(IsAsyncMonolithPackage)' == 'true'">
<None Include="$(MSBuildThisFileDirectory)AsyncMonolith/logo.png" Pack="true" PackagePath="\" Visible="false" />
<None Include="$(MSBuildThisFileDirectory)PACKAGE.md" Pack="true" PackagePath="README.md" Visible="false" />
</ItemGroup>
Expand Down
53 changes: 53 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Releasing AsyncMonolith

Releases publish two packages, `AsyncMonolith` and `AsyncMonolith.TestHelpers`, at the same version, using
[NuGet trusted publishing](https://learn.microsoft.com/en-us/nuget/nuget-org/trusted-publishing): no API key is
stored anywhere. The [release workflow](.github/workflows/release.yml) does the work.

## One-off setup

- **nuget.org:** a trusted publishing policy for repository `Timmoth/AsyncMonolith`, workflow file `release.yml`,
covering `AsyncMonolith*`. If the policy names an environment, it must be `release`.
- **nuget.org account:** the policy belongs to the `aptacode` profile, which the workflow names in its login step.
- **GitHub environment `release`:** created on first use. Add required reviewers to it if releases should need an
approval before publishing.
- The old `NUGET_API_KEY` secret is no longer used and can be deleted.

## Versioning

AsyncMonolith follows [Semantic Versioning](https://semver.org) from 11.0.0: breaking changes bump the major
version. The version lives in one place, `<VersionPrefix>` in [Directory.Build.props](Directory.Build.props).

## Each release

1. On `main`, set `<VersionPrefix>` to the new version.
2. Add a `## <version>` section to [docs/releases.md](docs/releases.md). It becomes the GitHub release notes, so
say what changed, what breaks, and whether a migration is needed. Add a row to the table at the top.
3. Run the workflow manually ("Run workflow" on the Release workflow) for a dry run: it runs the full test suite,
checks the release notes and packs, but doesn't publish. Download the `packages` artifact to inspect them.
4. Tag and push:

```bash
git tag v11.0.0
```

```bash
git push origin v11.0.0
```

The tag must match `<VersionPrefix>`, or the workflow stops. It then runs the full test suite (including the
integration tests against PostgreSQL, SQL Server, MySQL and MariaDB), packs, exchanges GitHub's OIDC token for
a one-hour nuget.org key, pushes both packages and their symbols, and creates the GitHub release with the
packages attached.
5. After the first release of a new major version, set `PackageValidationBaselineVersion` in
[Directory.Build.targets](Directory.Build.targets) to it, so later releases are checked for accidental breaking
changes.

If a push fails partway, rerun the failed job: pushing uses `--skip-duplicate`, so packages already published are
left alone.

## After 11.0.0

`AsyncMonolith.Ef`, `AsyncMonolith.PostgreSql`, `AsyncMonolith.MsSql`, `AsyncMonolith.MySql` and
`AsyncMonolith.MariaDb` are replaced by `AsyncMonolith`. On nuget.org, mark each as deprecated ("Legacy") with
`AsyncMonolith` as the alternate package, so their users are pointed at the upgrade.
15 changes: 11 additions & 4 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Make sure to check this table before updating the nuget package in your solution

| Version | Description | Migration Required |
|---------|--------------------------------------------|--------------------|
| 11.0.0 | SQLite-safe processing, stored names, modules, backoff, poisoned message service (see below) | Yes |
| 11.0.0 | One package, multi-instance-safe processing, new consumer and options APIs (see below) | Yes |
| 8.0.6 | Added ConsumerAttempts override attribute | No |
| 8.0.5 | Bundle debug symbols with nuget package | No |
| 8.0.4 | Bundle XML docs with nuget package | No |
Expand All @@ -19,6 +19,14 @@ Make sure to check this table before updating the nuget package in your solution

AsyncMonolith is now a single package. From 11.0.0 the major version follows [Semantic Versioning](https://semver.org) (it changes for breaking changes) rather than the .NET version. It is tested against PostgreSQL, SQL Server, MySQL 8.4 (with Oracle's `MySql.EntityFrameworkCore`), MariaDB 11.8 and SQLite.

**Upgrading from 8.x or 10.x**

1. Replace `AsyncMonolith.Ef`, `.PostgreSql`, `.MsSql`, `.MySql` or `.MariaDb` with the `AsyncMonolith` package, and add your EF Core provider if your app doesn't reference it already.
2. Replace `services.Add{Database}AsyncMonolith<TDbContext>(settings => ...)` with `services.AddAsyncMonolith<TDbContext>(options => ...)`, converting times to `TimeSpan`s (see the options changes below).
3. Make consumers implement `IConsumer<TPayload>` and add the `ConsumeContext context` parameter to `Consume`.
4. Call `modelBuilder.ConfigureAsyncMonolith()` in `OnModelCreating`, then add and apply a migration (see below).
5. On PostgreSQL, SQL Server, MySQL or MariaDB, make sure every `Produce` is followed by `SaveChangesAsync`: messages are no longer written without it.

**Migration required.** Add a migration (`dotnet ef migrations add AsyncMonolith_11_0_0`). It adds a nullable `last_error` column to `consumer_messages` and `poisoned_messages`. It also adds indexes for finding due messages (`rail_id, available_after`), due schedules (`available_after`), schedules by tag, and poisoned messages by age, which keep processing fast as the tables grow. If you manage the schema by hand, see the [SQL schemas](https://github.com/Timmoth/AsyncMonolith/tree/main/Schemas). They also now include `rail_id`, and their `trace_id` and `span_id` columns are nullable.

**Changes**
Expand All @@ -27,9 +35,9 @@ AsyncMonolith is now a single package. From 11.0.0 the major version follows [Se
- Cron expressions can have 5 fields (minute precision) as well as 6 (seconds first).
- `AsyncMonolithOptions.SerializerOptions` sets the `JsonSerializerOptions` for payloads. The default is unchanged.
- Tables can live in their own schema or have a prefix: `modelBuilder.ConfigureAsyncMonolith(o => { o.Schema = "jobs"; o.TablePrefix = "jobs_"; })`. The row-locking SQL follows the mapping.
- Every database now produces messages the same way: they are added to your `DbContext` and written on `SaveChanges`, in your transaction. The PostgreSQL, SQL Server, MySQL and MariaDB packages used to write immediately. A repeated insert id skips consumers that already have a pending message with it, on every database.
- Every database now produces messages the same way: they are added to your `DbContext` and written on `SaveChanges`, in your transaction. The PostgreSQL, SQL Server, MySQL and MariaDB packages used to write immediately. A repeated deduplication key skips consumers that already have a pending message with it, on every database.
- Several app instances can safely share the tables with any database. Claims and schedule occurrences use conditional updates, so a message is processed by one processor at a time and a schedule fires once per occurrence.
- Fetch order is deterministic (oldest first, then by id). See [Ordering](guides/consuming-messages.md#ordering) for what is and isn't guaranteed.
- Fetch order is deterministic (oldest first, then by id). See [Ordering](https://timmoth.github.io/AsyncMonolith/guides/consuming-messages/#ordering) for what is and isn't guaranteed.
- Consumers can write to the database on SQLite. Messages are claimed and leased in a short transaction, consumers run outside it, and each message is completed in its own short write. If the app stops mid-message, the message is retried once its consumer timeout plus 30 seconds has passed.
- Retries back off exponentially from `AttemptDelay` up to the new `MaxAttemptDelay` option (default 5 minutes).
- The last error is stored on retried and poisoned messages.
Expand All @@ -56,5 +64,4 @@ AsyncMonolith is now a single package. From 11.0.0 the major version follows [Se
- `AsyncMonolith.TestHelpers` uses xunit v3, and `ConsumerTestBase.InitializeAsync`/`DisposeAsync` return `ValueTask`.
- `IScheduleService` has a new member (`EnsureSchedule`), so custom implementations must add it.
- Errors that were thrown as `System.Exception` are now `InvalidOperationException`.
- `ConsumerRegistry` exposes properties instead of public fields.
- `TestConsumerMessageProcessor.ProcessNext<TDbContext, TConsumer>` now finds the consumer's message. It previously always returned null.
Loading