Skip to content

Commit e106b9a

Browse files
Chore: Refactor Options (#48)
* chore: refactor options options are not generally applicable - let's move to provider-specific options model, and remove some redundancies * feat: deploy to a beta source * refactor: stop running build for PRs, run publish-beta for PRs * chore: all PRs, no ignored branches * chore: publish coverage when publishing to beta * chore: always publish to beta on PR required for merge * chore: indicate prerelease * chore: remove redundant parenthesis * use milestone for versioning * need debugging * output PR info * chore: fix regex for posic \d metacharacter not supported * chore: only publish to beta if the milestone is a semantic version * chore: make redis snapshot options generic allowing configuration of different TSnapshots using Configure and ConfigureAll * chore: rename * chore: more standard prerelease versioning? * chore: add doc comments * chore: add a ToString override to make codacy shut up about generic parameter not being used also, if we ever switch to record, it won't allow the connection strings to be exposed accidentally
1 parent f96c986 commit e106b9a

28 files changed

+334
-260
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ on:
1111
- 'EntityDb.sln'
1212
- 'src/**'
1313
- 'test/**'
14-
pull_request:
15-
branches:
16-
- '**'
17-
paths:
18-
- '.github/workflows/build.yml'
19-
- 'global.json'
20-
- 'Directory.Build.props'
21-
- 'EntityDb.sln'
22-
- 'src/**'
23-
- 'test/**'
2414

2515
name: Build
2616

.github/workflows/create-release-draft.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ jobs:
1616
- id: parse
1717
run: |
1818
# This pattern comes from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
19-
# However, Bash uses POSIX regular expressions, and POSIX does not support non-capturing groups: (?:...)
20-
# To make it compatible, the non-capture modifiers have been removed.
21-
22-
semantic_version_pattern='^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
19+
# However, Bash uses POSIX regular expressions, and there are some unsupported features.
20+
# POSIX does not support non-capturing groups: (?:...)
21+
# - To make it compatible, the non-capture modifiers have been removed
22+
# POSIX does not support the digit metacharacter: \d
23+
# - To make it compatible, the digit metacharacters have been replaced with [0-9]
24+
25+
semantic_version_pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
2326
2427
if [[ ${GITHUB_REF/refs\/tags\//} =~ $semantic_version_pattern ]]; then
2528
echo ::set-output name=is_semantic_version::'true'

.github/workflows/publish-beta.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
on: pull_request
2+
3+
name: Publish to Beta
4+
5+
jobs:
6+
milestone:
7+
name: Try Parsing Milestone
8+
runs-on: ubuntu-latest
9+
outputs:
10+
is_semantic_version: ${{ steps.parse.outputs.is_semantic_version }}
11+
steps:
12+
- id: parse
13+
env:
14+
GITHUB_MILESTONE: ${{ github.event.pull_request.milestone.title }}
15+
run: |
16+
# This pattern comes from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
17+
# However, Bash uses POSIX regular expressions, and there are some unsupported features.
18+
# POSIX does not support non-capturing groups: (?:...)
19+
# - To make it compatible, the non-capture modifiers have been removed
20+
# POSIX does not support the digit metacharacter: \d
21+
# - To make it compatible, the digit metacharacters have been replaced with [0-9]
22+
23+
semantic_version_pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
24+
25+
if [[ ${GITHUB_MILESTONE} =~ $semantic_version_pattern ]]; then
26+
echo ::set-output name=is_semantic_version::'true'
27+
else
28+
echo ::set-output name=is_semantic_version::'false'
29+
fi
30+
beta:
31+
needs: milestone
32+
if: ${{ needs.milestone.outputs.is_semantic_version == 'true' }}
33+
name: Publish to Beta
34+
runs-on: ubuntu-latest
35+
environment: beta
36+
steps:
37+
- name: Checkout Repository
38+
uses: actions/checkout@v2
39+
- name: Start Redis
40+
uses: supercharge/[email protected]
41+
with:
42+
redis-version: 6.2.5
43+
- name: Start MongoDB
44+
uses: supercharge/[email protected]
45+
with:
46+
mongodb-version: 5.0.3
47+
mongodb-replica-set: entitydb
48+
- name: Install .NET SDK
49+
uses: actions/setup-dotnet@v1
50+
- name: Restore Dependencies
51+
run: dotnet restore EntityDb.sln --locked-mode
52+
- name: Run Project Tests
53+
run: dotnet test EntityDb.sln --no-restore -c Debug --collect:"XPlat Code Coverage" -r ./TestResults -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
54+
- name: Publish Coverage Results
55+
uses: codacy/codacy-coverage-reporter-action@v1
56+
with:
57+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
58+
coverage-reports: ./TestResults/**/*.xml
59+
- name: Pack Projects into Nuget Packages
60+
run: dotnet pack EntityDb.sln --no-restore -c Release /p:Version='${{ github.event.pull_request.milestone.title }}-beta.${{ github.event.number }}.${{ github.run_number }}.${{ github.run_attempt }}'
61+
- name: Publish to Beta
62+
run: dotnet nuget push */**.nupkg -s ${{ secrets.NUGET_SOURCE }} -k ${{ secrets.NUGET_API_KEY }}

src/EntityDb.Common/Exceptions/CannotWriteInReadOnlyModeException.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using EntityDb.Abstractions.Transactions;
2-
using EntityDb.Common.Transactions;
32
using System;
43

54
namespace EntityDb.Common.Exceptions;
65

76
/// <summary>
87
/// The exception that is thrown when an actor passes a <see cref="ITransaction" /> to an
9-
/// <see cref="ITransactionRepository" /> that was created with
10-
/// <see cref="TransactionSessionOptions.ReadOnly" /> equal to <c>true</c>.
8+
/// <see cref="ITransactionRepository" /> that was created for read-only mode.
119
/// </summary>
1210
public class CannotWriteInReadOnlyModeException : Exception
1311
{

src/EntityDb.Common/Extensions/ServiceCollectionExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ internal static void Add<TService>(this IServiceCollection serviceCollection, Se
5858
serviceCollection.Add(new ServiceDescriptor(typeof(TService), serviceFactory, serviceLifetime));
5959
}
6060

61+
internal static void Add<TService>(this IServiceCollection serviceCollection, ServiceLifetime serviceLifetime)
62+
where TService : class
63+
{
64+
serviceCollection.Add(new ServiceDescriptor(typeof(TService), typeof(TService), serviceLifetime));
65+
}
66+
6167
/// <summary>
6268
/// Adds an internal implementation of <see cref="IPartialTypeResolver" /> which resolves types by using assembly
6369
/// information.

src/EntityDb.Common/Snapshots/SnapshotSessionOptions.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/EntityDb.Common/Transactions/TransactionSessionOptions.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace EntityDb.InMemory.Sessions;
2+
3+
/// <summary>
4+
/// Configures the in-memory snapshot repository.
5+
/// </summary>
6+
public class InMemorySnapshotSessionOptions
7+
{
8+
/// <summary>
9+
/// If <c>true</c>, indicates the agent only intends to execute queries.
10+
/// </summary>
11+
public bool ReadOnly { get; set; }
12+
}

src/EntityDb.InMemory/Snapshots/InMemorySnapshotRepositoryFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ internal class InMemorySnapshotRepositoryFactory<TSnapshot> : DisposableResource
1313
ISnapshotRepositoryFactory<TSnapshot>
1414
{
1515
private readonly IInMemorySession<TSnapshot> _inMemorySession;
16-
private readonly IOptionsFactory<SnapshotSessionOptions> _optionsFactory;
16+
private readonly IOptionsFactory<InMemorySnapshotSessionOptions> _optionsFactory;
1717
private readonly IServiceProvider _serviceProvider;
1818

1919
public InMemorySnapshotRepositoryFactory
2020
(
2121
IServiceProvider serviceProvider,
2222
IInMemorySession<TSnapshot> inMemorySession,
23-
IOptionsFactory<SnapshotSessionOptions> optionsFactory
23+
IOptionsFactory<InMemorySnapshotSessionOptions> optionsFactory
2424
)
2525
{
2626
_serviceProvider = serviceProvider;
@@ -33,9 +33,9 @@ public async Task<ISnapshotRepository<TSnapshot>> CreateRepository(string snapsh
3333
{
3434
await Task.Yield();
3535

36-
var snapshotSessionOptions = _optionsFactory.Create(snapshotSessionOptionsName);
36+
var options = _optionsFactory.Create(snapshotSessionOptionsName);
3737

38-
var inMemorySession = snapshotSessionOptions.ReadOnly
38+
var inMemorySession = options.ReadOnly
3939
? new ReadOnlyInMemorySession<TSnapshot>(_inMemorySession)
4040
: _inMemorySession;
4141

src/EntityDb.MongoDb.Provisioner/Extensions/ServiceCollectionExtensions.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,28 @@
44
using EntityDb.MongoDb.Transactions;
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
7-
using System;
87

98
namespace EntityDb.MongoDb.Provisioner.Extensions;
109

1110
internal static class ServiceCollectionExtensions
1211
{
1312
public static void AddAutoProvisionMongoDbTransactions(
14-
this IServiceCollection serviceCollection, string databaseName,
15-
Func<IConfiguration, string> getConnectionString, bool testMode = false)
13+
this IServiceCollection serviceCollection, bool testMode = false)
1614
{
1715
serviceCollection.AddBsonDocumentEnvelopeService(true);
1816

17+
serviceCollection.Add<MongoDbTransactionRepositoryFactory>
18+
(
19+
testMode ? ServiceLifetime.Singleton : ServiceLifetime.Transient
20+
);
21+
1922
serviceCollection.Add<ITransactionRepositoryFactory>
2023
(
2124
testMode ? ServiceLifetime.Singleton : ServiceLifetime.Transient,
22-
serviceProvider =>
23-
{
24-
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
25-
26-
var connectionString = getConnectionString.Invoke(configuration);
27-
28-
return MongoDbTransactionRepositoryFactory
29-
.Create(serviceProvider, connectionString, databaseName)
30-
.UseTestMode(testMode)
31-
.UseAutoProvisioning(serviceProvider);
32-
}
25+
serviceProvider => serviceProvider
26+
.GetRequiredService<MongoDbTransactionRepositoryFactory>()
27+
.UseTestMode(testMode)
28+
.UseAutoProvisioning(serviceProvider)
3329
);
3430
}
3531
}

0 commit comments

Comments
 (0)