Skip to content
Closed
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
51 changes: 47 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: ci
name: CI

on:
push:
Expand All @@ -18,8 +18,39 @@ on:
- readme.md

jobs:
build:
test:
runs-on: ubuntu-latest
name: Unit Tests
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7

- name: Install .NET Core
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5
with:
dotnet-version: '10.0.x'
cache: true
cache-dependency-path: |
src/Directory.Packages.props
src/**/packages.lock.json

- name: Test UnityNuGet.Server.Tests (Release)
run: dotnet test src/UnityNuGet.Server.Tests/UnityNuGet.Server.Tests.csproj -c Release --logger "console;verbosity=normal"

- name: Test UnityNuGet.Tests excluding long registry validation (Release)
run: >
dotnet test src/UnityNuGet.Tests/UnityNuGet.Tests.csproj
-c Release
--filter "TestCategory!=RegistryValidation"
--logger "console;verbosity=normal"

registry-validation:
runs-on: ubuntu-latest
name: Registry Validation (${{ matrix.shard-index }})
strategy:
fail-fast: false
matrix:
shard-index: [0, 1, 2, 3, 4, 5]

steps:
- name: Checkout
Expand All @@ -29,6 +60,18 @@ jobs:
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5
with:
dotnet-version: '10.0.x'
cache: true
cache-dependency-path: |
src/Directory.Packages.props
src/**/packages.lock.json

- name: Build & test (Release)
run: dotnet test src -c Release --logger "console;verbosity=normal"
- name: Run registry validation shard
env:
UNITYNUGET_REGISTRY_SHARD_COUNT: 6
UNITYNUGET_REGISTRY_SHARD_INDEX: ${{ matrix.shard-index }}
run: >
dotnet test src/UnityNuGet.Tests/UnityNuGet.Tests.csproj
-c Release
--filter "TestCategory=RegistryValidation"
-- NUnit.NumberOfTestWorkers=8
--logger "console;verbosity=normal"
16 changes: 16 additions & 0 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,10 @@
"listed": true,
"version": "1.2.0"
},
"Pipelines.Sockets.Unofficial": {
"listed": true,
"version": "1.0.0"
},
"PlaceframeApiClient": {
"listed": true,
"version": "0.1.3"
Expand Down Expand Up @@ -1593,6 +1597,10 @@
"listed": true,
"version": "7.0.0"
},
"Redis.OM": {
"listed": true,
"version": "0.1.0"
},
"RestSharp": {
"listed": true,
"version": "106.0.0"
Expand Down Expand Up @@ -1857,6 +1865,10 @@
"listed": true,
"version": "1.3.0"
},
"StackExchange.Redis": {
"listed": true,
"version": "2.0.495"
},
"Stateless": {
"listed": true,
"version": "4.3.0"
Expand Down Expand Up @@ -2166,6 +2178,10 @@
"listed": true,
"version": "1.3.1"
},
"Ulid": {
"listed": true,
"version": "0.1.0"
},
"Validation": {
"listed": true,
"version": "2.5.42"
Expand Down
59 changes: 43 additions & 16 deletions src/UnityNuGet.Tests/RegistryTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -165,14 +166,8 @@ static async Task<TestCaseData[]> AllRegistries()

Registry registry = new(loggerFactory, Options.Create(s_registryOptions));

NuGetConsoleTestLogger logger = new();

await registry.StartAsync(CancellationToken.None);

SourceCacheContext cache = new();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();

RegistryTargetFramework[] nuGetFrameworks = [new() { Framework = CommonFrameworks.NetStandard20 }];

string[] excludedPackages = [
Expand Down Expand Up @@ -240,13 +235,42 @@ static async Task<TestCaseData[]> AllRegistries()

Regex excludedPackagesRegex = new(@$"^{string.Join('|', excludedPackages)}$");

return [.. registry.Where(r => !r.Value.Analyzer && !r.Value.Ignored).OrderBy((pair) => pair.Key).Select((pair) =>
int shardCount = 1;
int shardIndex = 0;

string? shardCountEnv = Environment.GetEnvironmentVariable("UNITYNUGET_REGISTRY_SHARD_COUNT");
string? shardIndexEnv = Environment.GetEnvironmentVariable("UNITYNUGET_REGISTRY_SHARD_INDEX");

if (!string.IsNullOrWhiteSpace(shardCountEnv) && int.TryParse(shardCountEnv, out int parsedShardCount) && parsedShardCount > 0)
{
shardCount = parsedShardCount;
}

if (!string.IsNullOrWhiteSpace(shardIndexEnv) && int.TryParse(shardIndexEnv, out int parsedShardIndex) && parsedShardIndex >= 0)
{
shardIndex = parsedShardIndex;
}

if (shardIndex >= shardCount)
{
throw new InvalidOperationException($"Invalid shard configuration: index {shardIndex} must be less than shard count {shardCount}.");
}

var entries = registry
.Where(r => !r.Value.Analyzer && !r.Value.Ignored)
.OrderBy((pair) => pair.Key)
.Select((pair, index) => (pair, index));

if (shardCount > 1)
{
entries = entries.Where(e => e.index % shardCount == shardIndex);
}

return [.. entries.Select((entry) =>
{
KeyValuePair<string, RegistryEntry> pair = entry.pair;

return new TestCaseData(
resource,
logger,
cache,
repository,
excludedPackagesRegex,
nuGetFrameworks,
pair.Key,
Expand All @@ -258,18 +282,21 @@ static async Task<TestCaseData[]> AllRegistries()

const int MaxAllowedVersions = 100;

[Parallelizable(ParallelScope.All)]
[Category("RegistryValidation")]
[TestCaseSource(nameof(AllRegistries))]
public async Task Ensure_Min_Version_Is_Correct_Ignoring_Analyzers_And_Native_Libs(PackageMetadataResource resource,
NuGetConsoleTestLogger logger,
SourceCacheContext cache,
SourceRepository repository,
Regex excludedPackagesRegex,
public async Task Ensure_Min_Version_Is_Correct_Ignoring_Analyzers_And_Native_Libs(Regex excludedPackagesRegex,
RegistryTargetFramework[] nuGetFrameworks,
string packageId,
bool includePrerelease,
bool includeUnlisted,
VersionRange versionRange)
{
NuGetConsoleTestLogger logger = new();
SourceCacheContext cache = new();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();

IEnumerable<IPackageSearchMetadata> dependencyPackageMetas = await resource.GetMetadataAsync(
packageId,
includePrerelease,
Expand Down
Loading