Skip to content

Commit 37459b0

Browse files
committed
Test binary package in CI
Issue redis#195 In the integration workflows, publish the binary package into a local Nuget source and use it as a binary, to make sure it works that way.
1 parent fe18a3b commit 37459b0

File tree

3 files changed

+132
-5
lines changed

3 files changed

+132
-5
lines changed

.github/workflows/reusable.yml

+65-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ on:
2222
dotenv_file:
2323
required: true
2424
type: string
25+
26+
env:
27+
NUPKG_ARTIFACT_NAME: nupkg-${{inputs.dotnet_sdk_version}}-${{inputs.clr_version}}-${{inputs.redis_stack_type}}
28+
2529
jobs:
2630
build_and_test:
2731
name: Test
@@ -55,11 +59,10 @@ jobs:
5559
find . -name '*.csproj' | xargs cat
5660
jq -n --arg version ${{inputs.dotnet_sdk_version}} '{"sdk":{"version":$version,"rollForward":"latestMinor"}}' > global.json
5761
- name: Check .NET version
58-
run: dotnet --version
59-
- name: Check .NET SDKs
60-
run: dotnet --list-sdks
61-
- name: Check .NET runtimes
62-
run: dotnet --list-runtimes
62+
run: |
63+
dotnet --version
64+
dotnet --list-sdks
65+
dotnet --list-runtimes
6366
- name: Restore dependencies
6467
run: dotnet restore
6568
- name: Build
@@ -77,3 +80,60 @@ jobs:
7780
verbose: true
7881
- name: Build
7982
run: dotnet pack -c Release
83+
84+
- name: Upload Nuget package as artifact
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: ${{env.NUPKG_ARTIFACT_NAME}}
88+
path: "**/*.nupkg"
89+
if-no-files-found: error
90+
retention-days: 1
91+
overwrite: true
92+
93+
test_package:
94+
name: Test Package
95+
needs: build_and_test
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@v3
99+
100+
- name: .NET Core 8
101+
uses: actions/setup-dotnet@v3
102+
with:
103+
dotnet-version: 8
104+
105+
- name: Run redis-stack Docker
106+
working-directory: .github
107+
run: docker-compose up -d redis-stack-${{inputs.redis_stack_type}}
108+
109+
- name: Set variables in dotenv
110+
uses: c-py/action-dotenv-to-setenv@v2
111+
with:
112+
env-file: ${{inputs.dotenv_file}}
113+
114+
- name: Prepare local Nuget source
115+
working-directory: dogfooding
116+
run: |
117+
mkdir -p test-source-data
118+
dotnet nuget add source $(readlink -f test-source-data) -n test-source
119+
120+
- name: Download Nuget package artifact
121+
uses: actions/download-artifact@v4
122+
with:
123+
name: ${{env.NUPKG_ARTIFACT_NAME}}
124+
path: dogfooding/test-source-data
125+
126+
- name: Test against Nuget package
127+
working-directory: dogfooding
128+
run: |
129+
# Tweak dotnet version
130+
find . -name '*.csproj' | xargs -I {} sed -E -i 's|<TargetFrameworks(.*)>.*</TargetFrameworks>|<TargetFramework\1>${{inputs.clr_version}}</TargetFramework>|' {}
131+
find . -name '*.csproj' | xargs cat
132+
jq -n --arg version ${{inputs.dotnet_sdk_version}} '{"sdk":{"version":$version,"rollForward":"latestMinor"}}' > global.json
133+
# Verify dotnet version
134+
dotnet --version
135+
dotnet --list-sdks
136+
dotnet --list-runtimes
137+
# Install package and run the code that uses it
138+
dotnet restore -s test-source
139+
dotnet run

dogfooding/PackageTest.cs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using NRedisStack;
2+
using NRedisStack.Core.DataTypes;
3+
using StackExchange.Redis;
4+
5+
public class PackageTest
6+
{
7+
public static void Main()
8+
{
9+
ConfigurationOptions configurationOptions = new ConfigurationOptions();
10+
configurationOptions.SyncTimeout = 20000;
11+
configurationOptions.EndPoints.Add("localhost:6379");
12+
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions);
13+
IDatabase db = redis.GetDatabase();
14+
15+
db.Execute("FLUSHALL");
16+
17+
db.SortedSetAdd("X", "foo", 5.1);
18+
db.SortedSetAdd("X", "bar", 8.4);
19+
db.SortedSetAdd("X", "baz", 6.7);
20+
21+
var result = db.BzmPop(0, new[] { new RedisKey("X") }, MinMaxModifier.Max, count: 2);
22+
Assert(2 == result!.Item2.Count);
23+
Assert("bar" == result.Item2[0].Value);
24+
Assert("baz" == result.Item2[1].Value);
25+
26+
result = db.BzmPop(0, "X", MinMaxModifier.Min);
27+
Assert(1 == result!.Item2.Count);
28+
Assert("foo" == result!.Item2[0].Value);
29+
30+
db.SortedSetAdd("X", "foo", 5.1);
31+
db.SortedSetAdd("X", "bar", 8.4);
32+
db.SortedSetAdd("X", "baz", 6.7);
33+
34+
var singleResult = db.BzPopMin("X", 0);
35+
Assert("foo" == singleResult!.Item2.Value);
36+
37+
singleResult = db.BzPopMax("X", 0);
38+
Assert("bar" == singleResult!.Item2.Value);
39+
40+
Console.WriteLine("All good.");
41+
}
42+
43+
/// <summary>
44+
/// Poor Man's assert, since we don't want to depend on NUnit.
45+
/// </summary>
46+
private static void Assert(bool condition)
47+
{
48+
if (!condition)
49+
{
50+
throw new System.Exception();
51+
}
52+
}
53+
}

dogfooding/dogfooding.csproj

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="NRedisStack" Version="*" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)