Skip to content

Commit

Permalink
Merge pull request #51 from christianhelle/main
Browse files Browse the repository at this point in the history
Introduce Low Priority Readers and Writers using the Preview version of the Cosmos SDK
  • Loading branch information
christianhelle authored Sep 6, 2023
2 parents 113d3a6 + f38561d commit 9e08197
Show file tree
Hide file tree
Showing 34 changed files with 3,419 additions and 96 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/post-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
ATC_EMAIL: 'atcnet.org@gmail.com'
ATC_NAME: 'Atc-Net'
NUGET_REPO_URL: 'https://nuget.pkg.github.com/atc-net/index.json'
VERSION: 1.1.0.${{ github.run_number }}

jobs:
merge-to-stable:
Expand Down Expand Up @@ -43,14 +44,14 @@ jobs:
- name: 🧹 Clean
run: dotnet clean -c Release && dotnet nuget locals all --clear

- name: 🔁 Restore packages
run: dotnet restore
- name: 🛠️ Building library in release mode
run: dotnet pack -c Release -o packages -p:UseSourceLink=true -p:Version=${{ env.VERSION }} -p:PackageVersion=${{ env.VERSION }}

- name: 🛠️ Build
run: dotnet build -c Release --no-restore /p:UseSourceLink=true
- name: 🛠️ Building preview library in release mode
run: dotnet pack -c Release -o packages -p:UseSourceLink=true -p:Version=${{ env.VERSION }} -p:PackageVersion=${{ env.VERSION }}-preview -p:DefineConstants=PREVIEW

- name: 🧪 Run unit tests
run: dotnet test -c Release --no-build
run: dotnet test -c Release -p:DefineConstants=PREVIEW

- name: 🌩️ SonarCloud install scanner
run: dotnet tool install --global dotnet-sonarscanner
Expand All @@ -60,6 +61,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: pwsh
continue-on-error: true
run: |
dotnet sonarscanner begin /k:"atc-cosmos" /o:"atc-net" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build -c Release /p:UseSourceLink=true --no-restore
Expand All @@ -73,8 +75,14 @@ jobs:
git merge --ff-only main
git push origin stable
- name: 🗳️ Creating library package for pre-release
run: dotnet pack -c Release --no-restore -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=$BRANCH_NAME

- name: 📦 Push packages to GitHub Package Registry
run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/'Atc.Cosmos.'${NBGV_NuGetPackageVersion}'.nupkg' -k ${{ secrets.GITHUB_TOKEN }} -s ${{ env.NUGET_REPO_URL }} --skip-duplicate --no-symbols
continue-on-error: true
run: dotnet nuget push **/*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s ${{ env.NUGET_REPO_URL }} --skip-duplicate --no-symbols

- name: 🗳️ Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: Packages
path: |
packages/*.nupkg
README.md
42 changes: 22 additions & 20 deletions .github/workflows/pre-integration.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
name: "Pre-Integration"

on:
pull_request:
types:
- opened
- synchronize
- reopened
push:
workflow_dispatch:

env:
VERSION: 1.1.0.${{ github.run_number }}

jobs:
dotnet5-build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
build:
runs-on: ubuntu-latest
steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v2
Expand All @@ -27,16 +24,24 @@ jobs:
- name: 🧹 Clean
run: dotnet clean -c Release && dotnet nuget locals all --clear

- name: 🔁 Restore packages
run: dotnet restore

- name: 🛠️ Building library in release mode
run: dotnet build -c Release --no-restore
run: dotnet pack -c Release -o packages -p:UseSourceLink=true -p:Version=${{ env.VERSION }} -p:PackageVersion=${{ env.VERSION }}

dotnet-test:
- name: 🛠️ Building preview library in release mode
run: dotnet pack -c Release -o packages -p:UseSourceLink=true -p:Version=${{ env.VERSION }} -p:PackageVersion=${{ env.VERSION }}-preview -p:DefineConstants=PREVIEW

- name: 🗳️ Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: Packages
path: |
packages/*.nupkg
README.md
test:
runs-on: ubuntu-latest
needs:
- dotnet5-build
- build
steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v2
Expand All @@ -51,8 +56,5 @@ jobs:
- name: 🔁 Restore packages
run: dotnet restore

- name: 🛠️ Build
run: dotnet build -c Release --no-restore /p:UseSourceLink=true

- name: 🧪 Run unit tests
run: dotnet test -c Release --no-build
run: dotnet test -c Release -p:DefineConstants=PREVIEW
30 changes: 14 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:
ATC_EMAIL: 'atcnet.org@gmail.com'
ATC_NAME: 'Atc-Net'
NUGET_REPO_URL: 'https://api.nuget.org/v3/index.json'
VERSION: 1.1.${{ github.run_number }}

jobs:
release:
Expand All @@ -19,14 +20,6 @@ jobs:
fetch-depth: 0
token: ${{ secrets.PAT_WORKFLOWS }}

- name: ⚛️ Sets environment variables - branch-name
uses: nelonoel/branch-name@v1.0.1

- name: ⚛️ Sets environment variables - Nerdbank.GitVersioning
uses: dotnet/nbgv@master
with:
setAllVars: true

- name: ⚙️ Setup dotnet 6.0.x
uses: actions/setup-dotnet@v1
with:
Expand All @@ -35,11 +28,19 @@ jobs:
- name: 🧹 Clean
run: dotnet clean -c Release && dotnet nuget locals all --clear

- name: 🔁 Restore packages
run: dotnet restore

- name: 🛠️ Building library in release mode
run: dotnet build -c Release --no-restore /p:UseSourceLink=true
run: dotnet pack -c Release -o packages -p:UseSourceLink=true -p:Version=${{ env.VERSION }} -p:PackageVersion=${{ env.VERSION }}

- name: 🛠️ Building preview library in release mode
run: dotnet pack -c Release -o packages -p:UseSourceLink=true -p:Version=${{ env.VERSION }} -p:PackageVersion=${{ env.VERSION }}-preview -p:DefineConstants=PREVIEW

- name: 🗳️ Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: Packages
path: |
packages/*.nupkg
README.md
- name: ⏩ Merge to release-branch
run: |
Expand All @@ -49,8 +50,5 @@ jobs:
git merge --ff-only stable
git push origin release
- name: 🗳️ Creating library package for release
run: dotnet pack -c Release --no-restore -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=$BRANCH_NAME /p:PublicRelease=true

- name: 📦 Push packages to NuGet
run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/'Atc.Cosmos.'${NBGV_NuGetPackageVersion}'.nupkg' -k ${{ secrets.NUGET_KEY }} -s ${{ env.NUGET_REPO_URL }} --skip-duplicate --no-symbols
run: dotnet nuget push **/*.nupkg -k ${{ secrets.NUGET_KEY }} -s ${{ env.NUGET_REPO_URL }} --skip-duplicate --no-symbols
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "Atc.Cosmos.sln"
}
10 changes: 10 additions & 0 deletions Atc.Cosmos.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug Preview|Any CPU = Debug Preview|Any CPU
Release Preview|Any CPU = Release Preview|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Release|Any CPU.Build.0 = Release|Any CPU
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Debug Preview|Any CPU.ActiveCfg = Debug Preview|Any CPU
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Debug Preview|Any CPU.Build.0 = Debug Preview|Any CPU
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Release Preview|Any CPU.ActiveCfg = Release Preview|Any CPU
{AD8BA566-1E47-4E9E-BEBA-985DCA7A0DB5}.Release Preview|Any CPU.Build.0 = Release Preview|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Release|Any CPU.Build.0 = Release|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Debug Preview|Any CPU.ActiveCfg = Debug Preview|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Debug Preview|Any CPU.Build.0 = Debug Preview|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Release Preview|Any CPU.ActiveCfg = Release Preview|Any CPU
{16FE83BC-DF0D-493D-8EE0-A78006A07EFF}.Release Preview|Any CPU.Build.0 = Release Preview|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
18 changes: 17 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Label="configurations">
<Configurations>Debug;Release;Debug Preview;Release Preview</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug Preview' ">
<DefineConstants>TRACE;PREVIEW;</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release Preview' ">
<DefineConstants>TRACE;PREVIEW;</DefineConstants>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Label="Metadata configuration">
<OrganizationName>atc-net</OrganizationName>
<RepositoryName>atc-cosmos</RepositoryName>
<IsPreview>$(DefineConstants.Contains('PREVIEW'))</IsPreview>
</PropertyGroup>

<!-- Solution wide properties -->
Expand Down
8 changes: 3 additions & 5 deletions src/Atc.Cosmos/Atc.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
<PackageId>Atc.Cosmos</PackageId>
<PackageTags>cosmos;cosmos-sql;netcore;repository</PackageTags>
<Description>Library for configuring containers in Cosmos and providing an easy way to read and write document resources.</Description>
<VersionSuffix Condition="$(IsPreview)">preview</VersionSuffix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.34.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.1-preview" Condition="$(IsPreview)" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.1" Condition="!$(IsPreview)" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
Expand All @@ -22,8 +24,4 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.5.109" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,21 @@ public static IServiceCollection ConfigureCosmos(
services.AddSingleton<ICosmosContainerProvider, CosmosContainerProvider>();
services.AddSingleton(typeof(ICosmosReader<>), typeof(CosmosReader<>));
services.AddSingleton(typeof(ICosmosWriter<>), typeof(CosmosWriter<>));
services.AddSingleton(typeof(ICosmosBulkReader<>), typeof(CosmosBulkReader<>));
services.AddSingleton(typeof(ICosmosBulkWriter<>), typeof(CosmosBulkWriter<>));
services.AddSingleton<ICosmosInitializer, CosmosInitializer>();
services.AddSingleton<IJsonCosmosSerializer, JsonCosmosSerializer>();
services.AddSingleton<ICosmosClientProvider, CosmosClientProvider>();
services.AddSingleton<ICosmosReaderFactory, CosmosReaderFactory>();
services.AddSingleton<ICosmosWriterFactory, CosmosWriterFactory>();
#if PREVIEW
services.AddSingleton(typeof(ILowPriorityCosmosReader<>), typeof(LowPriorityCosmosReader<>));
services.AddSingleton(typeof(ILowPriorityCosmosWriter<>), typeof(LowPriorityCosmosWriter<>));
services.AddSingleton(typeof(ILowPriorityCosmosBulkReader<>), typeof(LowPriorityCosmosBulkReader<>));
services.AddSingleton(typeof(ILowPriorityCosmosBulkWriter<>), typeof(LowPriorityCosmosBulkWriter<>));
services.AddSingleton<ILowPriorityCosmosReaderFactory, LowPriorityCosmosReaderFactory>();
services.AddSingleton<ILowPriorityCosmosWriterFactory, LowPriorityCosmosWriterFactory>();
#endif

builder(new CosmosBuilder(services, registry, null));
return services;
Expand Down
17 changes: 17 additions & 0 deletions src/Atc.Cosmos/ILowPriorityCosmosBulkReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if PREVIEW
namespace Atc.Cosmos
{
/// <summary>
/// Represents a reader that can perform bulk reads on Cosmos resources using the PriorityLevel Low.
/// </summary>
/// <typeparam name="T">
/// The type of <see cref="ICosmosResource"/>
/// to be read by this reader.
/// </typeparam>
public interface ILowPriorityCosmosBulkReader<T>
: ICosmosBulkReader<T>
where T : class, ICosmosResource
{
}
}
#endif
17 changes: 17 additions & 0 deletions src/Atc.Cosmos/ILowPriorityCosmosBulkWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if PREVIEW
namespace Atc.Cosmos
{
/// <summary>
/// Represents a reader that can perform bulk reads on Cosmos resources using the PriorityLevel Low.
/// </summary>
/// <typeparam name="T">
/// The type of <see cref="ICosmosResource"/>
/// to be read by this reader.
/// </typeparam>
public interface ILowPriorityCosmosBulkWriter<in T>
: ICosmosBulkWriter<T>
where T : class, ICosmosResource
{
}
}
#endif
17 changes: 17 additions & 0 deletions src/Atc.Cosmos/ILowPriorityCosmosReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if PREVIEW
namespace Atc.Cosmos
{
/// <summary>
/// Represents a reader that can read Cosmos resources using the PriorityLevel Low.
/// </summary>
/// <typeparam name="T">
/// The type of <see cref="ICosmosResource"/>
/// to be read by this reader.
/// </typeparam>
public interface ILowPriorityCosmosReader<T>
: ICosmosReader<T>
where T : class, ICosmosResource
{
}
}
#endif
26 changes: 26 additions & 0 deletions src/Atc.Cosmos/ILowPriorityCosmosReaderFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if PREVIEW
namespace Atc.Cosmos
{
/// <summary>
/// Represents a factory for creating <see cref="ICosmosReader{T}"/> instances.
/// </summary>
public interface ILowPriorityCosmosReaderFactory
{
/// <summary>
/// Create a <see cref="ICosmosReader{T}"/>.
/// </summary>
/// <typeparam name="TResource">The <see cref="ICosmosResource"/> for the <see cref="ICosmosReader{T}"/>.</typeparam>
/// <returns>A <see cref="ICosmosReader{T}"/>.</returns>
ILowPriorityCosmosReader<TResource> CreateReader<TResource>()
where TResource : class, ICosmosResource;

/// <summary>
/// Create a <see cref="ICosmosBulkReader{T}"/>.
/// </summary>
/// <typeparam name="TResource">The <see cref="ICosmosResource"/> for the <see cref="ICosmosBulkReader{T}"/>.</typeparam>
/// <returns>A <see cref="ICosmosBulkReader{T}"/>.</returns>
ILowPriorityCosmosBulkReader<TResource> CreateBulkReader<TResource>()
where TResource : class, ICosmosResource;
}
}
#endif
17 changes: 17 additions & 0 deletions src/Atc.Cosmos/ILowPriorityCosmosWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if PREVIEW
namespace Atc.Cosmos
{
/// <summary>
/// Represents a writer that can write Cosmos resources using the PriorityLevel Low.
/// </summary>
/// <typeparam name="T">
/// The type of <see cref="ICosmosResource"/>
/// to be read by this reader.
/// </typeparam>
public interface ILowPriorityCosmosWriter<T>
: ICosmosWriter<T>
where T : class, ICosmosResource
{
}
}
#endif
Loading

0 comments on commit 9e08197

Please sign in to comment.