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
16 changes: 16 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name-template: 'v$NEXT_PATCH_VERSION'
tag-template: 'v$NEXT_PATCH_VERSION'
template: |
# What's Changed

$CHANGES
categories:
- title: '🚀 Features'
label: 'Feature'
- title: '🐛 Bug Fixes'
label: 'Bug'
- title: '🧰 Maintenance'
label: 'Maintenance'
- title: '📖 Documentation'
label: 'Docs'
change-template: '- (#$NUMBER) $TITLE - Thanks to @$AUTHOR '
91 changes: 63 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,87 @@
name: Build and Test
name: Main workflow

on:
push:
branches: [ master ]
pull_request:
push:
branches: [ master ]
release:
types: [ published ]

env:
DOTNET_SDK_VERSION: 5.0.x
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
GITHUB_FEED: https://nuget.pkg.github.com/ch1seL/
GITHUB_USER: ch1seL
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NUGET_FEED: https://api.nuget.org/v3/index.json
NUGET_KEY: ${{ secrets.NUGET_API_KEY }}

jobs:
build:
name: Build and test
if: github.event_name != 'release'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup .NET Core
- name: Setup dotnet SDK 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup dotnet SDK ${{ env.DOTNET_SDK_VERSION }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Setup Redis Server
uses: supercharge/redis-github-action@1.1.0
- name: Run redis
run: |
docker run -d -p 6379:6379 redis
wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
chmod +x wait-for-it.sh
./wait-for-it.sh -s -t 120 localhost:6379

- name: Test
run: dotnet test --configuration Release --no-restore --no-build --verbosity normal

- name: Publish NuGet ch1seL.DistributedLock.Abstraction
uses: brandedoutcast/publish-nuget@v2.5.5
with:
PROJECT_FILE_PATH: src/ch1seL.DistributedLock.Abstraction/ch1seL.DistributedLock.Abstraction.csproj
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
VERSION_REGEX: ^\s*<PackageVersion>(.*)<\/PackageVersion>\s*$

- name: Publish NuGet ch1seL.DistributedLock.RedisLock
uses: brandedoutcast/publish-nuget@v2.5.5
with:
PROJECT_FILE_PATH: src/ch1seL.DistributedLock.RedisLock/ch1seL.DistributedLock.RedisLock.csproj
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
VERSION_REGEX: ^\s*<PackageVersion>(.*)<\/PackageVersion>\s*$

- name: Publish NuGet ch1seL.DistributedLock.MemoryLock
uses: brandedoutcast/publish-nuget@v2.5.5
with:
PROJECT_FILE_PATH: src/ch1seL.DistributedLock.MemoryLock/ch1seL.DistributedLock.MemoryLock.csproj
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
VERSION_REGEX: ^\s*<PackageVersion>(.*)<\/PackageVersion>\s*$

publish:
name: Publish NuGet
needs: build
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
- name: Create Release NuGet package
run: |
arrTag=(${GITHUB_REF//\// })
VERSION="${arrTag[2]}"
echo Version: $VERSION
VERSION="${VERSION//v}"
echo Clean Version: $VERSION
dotnet pack -v normal -c Release --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg
- name: Push to GitHub Feed
working-directory: nupkg
run: |
for f in *.nupkg
do
curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
done
- name: Push to NuGet Feed
working-directory: nupkg
run: |
for f in *.nupkg
do
echo $f
dotnet nuget push $f --source $NUGET_FEED --skip-duplicate --api-key $NUGET_KEY
done
14 changes: 14 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release Drafter

on:
push:
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions RedisLock.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AA3FA77D-B187-41A1-95A9-8BC93CCF79D8}"
ProjectSection(SolutionItems) = preProject
src\Directory.Packages.props = src\Directory.Packages.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ch1seL.DistributedLock.Abstraction", "src\ch1seL.DistributedLock.Abstraction\ch1seL.DistributedLock.Abstraction.csproj", "{503205F0-5FC4-4077-B1BF-C31FE5F73AF4}"
EndProject
Expand Down
2 changes: 0 additions & 2 deletions RedisLock.sln.DotSettings

This file was deleted.

37 changes: 0 additions & 37 deletions RedisLock.sln.DotSettings.user

This file was deleted.

2 changes: 1 addition & 1 deletion samples/WorkerService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WorkerService
{
public class Program
public static class Program
{
public static readonly Guid AppId = Guid.NewGuid();

Expand Down
6 changes: 3 additions & 3 deletions samples/WorkerService/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Worker : BackgroundService
private readonly IDistributedLock _distributedLock;
private readonly Guid _instanceId = Guid.NewGuid();
private readonly ILogger<Worker> _logger;
private readonly Random _random = new Random();
private readonly Random _random = new();

public Worker(ILogger<Worker> logger, IDistributedLock distributedLock)
{
Expand All @@ -27,9 +27,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
using (await _distributedLock.CreateLockAsync("test-lock", waitTime: TimeSpan.FromMinutes(5), retryTime: TimeSpan.FromMilliseconds(10),
cancellationToken: stoppingToken))
{
_logger.LogInformation("App:{appId} | Instance: {instanceId} | Worker running at: {time}", Program.AppId, _instanceId, DateTimeOffset.Now);
_logger.LogInformation("App:{AppId} | Instance: {InstanceId} | Worker running at: {Time}", Program.AppId, _instanceId, DateTimeOffset.Now);
await Task.Delay(TimeSpan.FromSeconds(3), stoppingToken);
_logger.LogInformation("App:{appId} | Instance: {instanceId} | Worker finished at: {time}", Program.AppId, _instanceId, DateTimeOffset.Now);
_logger.LogInformation("App:{AppId} | Instance: {InstanceId} | Worker finished at: {Time}", Program.AppId, _instanceId, DateTimeOffset.Now);
}

// RedLock uses retries and will use mostly only one instance of the worker
Expand Down
6 changes: 3 additions & 3 deletions samples/WorkerService/WorkerService.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>dotnet-WorkerService-56DC58EC-8910-4947-A202-60D027333D3A</UserSecretsId>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 0 additions & 9 deletions samples/WorkerService/appsettings.Development.json

This file was deleted.

20 changes: 20 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project>

<PropertyGroup>
<Authors>Alexander Salamatov</Authors>
<PackageProjectUrl>https://github.com/ch1seL/RedisLock</PackageProjectUrl>

<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<PackageLicenseExpression>MIT</PackageLicenseExpression>

<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/ch1seL/RedisLock</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>

<EmbedUntrackedSources>true</EmbedUntrackedSources>
<LangVersion>latest</LangVersion>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@ public class DistributedLockException : Exception
public DistributedLockException(string resource, string lockId, DistributedLockBadStatus status, Exception innerException = null) : base(
"Lock is not acquired", innerException)
{
Resource = resource;
LockId = lockId;
Status = status;

base.Data.Add("Resource", resource);
base.Data.Add("LockId", lockId);
base.Data.Add("Status", status);
}

public string Resource { get; }
public string LockId { get; }
public DistributedLockBadStatus Status { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageVersion>0.1.2</PackageVersion>
<Authors>ch1seL</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>ch1seL.DistributedLock.Abstraction</PackageId>
<AssemblyName>ch1seL.DistributedLock.Abstraction</AssemblyName>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/ch1seL/RedisLock</PackageProjectUrl>
<AssemblyName>ch1seL.DistributedLock.Abstraction</AssemblyName>
<RootNamespace>Microsoft.Extensions.Caching.Distributed</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>

</Project>
8 changes: 3 additions & 5 deletions src/ch1seL.DistributedLock.MemoryLock/MemoryLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class MemoryLock : IDistributedLock, IDisposable
{
public static readonly string SemaphoreReleaserTypeFullName = typeof(SemaphoreReleaser).FullName;

private readonly ConcurrentDictionary<string, RefCounted<SemaphoreSlim>> _semaphoreSlims =
new ConcurrentDictionary<string, RefCounted<SemaphoreSlim>>();
private readonly ConcurrentDictionary<string, RefCounted<SemaphoreSlim>> _semaphoreSlims = new();

public void Dispose()
{
Expand All @@ -23,9 +22,8 @@ public void Dispose()
}
}

public async Task<IDisposable> CreateLockAsync(string resource, TimeSpan? expiryTime = null,
TimeSpan? waitTime = null,
TimeSpan? retryTime = null, CancellationToken cancellationToken = new CancellationToken())
public async Task<IDisposable> CreateLockAsync(string resource, TimeSpan? expiryTime = null, TimeSpan? waitTime = null, TimeSpan? retryTime = null,
CancellationToken cancellationToken = default)
{
Exception innerException = null;
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Caching;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Distributed;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageVersion>0.1.4</PackageVersion>
<Authors>ch1seL</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>ch1seL.DistributedLock.MemoryLock</PackageId>
<AssemblyName>ch1seL.DistributedLock.MemoryLock</AssemblyName>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/ch1seL/RedisLock</PackageProjectUrl>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Microsoft.Extensions.Caching.Distributed</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ch1seL.DistributedLock.Abstraction" Version="0.1.2"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.9"/>
<PackageReference Include="ch1seL.DistributedLock.Abstraction" Version="0.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
</ItemGroup>

</Project>
Loading