Skip to content

Commit

Permalink
Merge pull request #21 from ScoopInstaller/net-8
Browse files Browse the repository at this point in the history
Update to .Net8, update to latest Nuget packages, update GH workflows + minor improvements
  • Loading branch information
gpailler authored May 5, 2024
2 parents 9c19595 + 1fe1c9a commit 92fe91c
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 113 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
OUTPUT_PATH: ${{ github.workspace }}/output
APP_PATH: ${{ github.workspace }}/src/ScoopSearch.Indexer.Console/
GitHub__Token: ${{ secrets.GITHUB_TOKEN }}
DOTNET_VERSION: '7.0.x'
DOTNET_VERSION: '8.0.x'

jobs:
main:
Expand All @@ -24,10 +24,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup .NET ${{ env.DOTNET_VERSION }}
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

Expand All @@ -47,7 +47,7 @@ jobs:
./ScoopSearch.Indexer.Console
- name: Upload logs
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs
path: ${{ env.OUTPUT_PATH }}/output.txt
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
OUTPUT_PATH: ${{ github.workspace }}/output
TESTS_PATH: ${{ github.workspace }}/src/ScoopSearch.Indexer.Tests/
GitHub__Token: ${{ secrets.GITHUB_TOKEN }}
DOTNET_VERSION: '7.0.x'
DOTNET_VERSION: '8.0.x'
# SONAR_TOKEN: '' # Stored in the Actions secrets

jobs:
Expand All @@ -22,12 +22,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for Sonar blame

- name: Setup .NET ${{ env.DOTNET_VERSION }}
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

Expand All @@ -44,7 +44,7 @@ jobs:
dotnet sonarscanner begin
/o:"scoopinstaller"
/k:"ScoopInstaller_ScoopInstaller.scoopinstaller.github.io-indexer"
/d:sonar.login="${{ secrets.SONAR_TOKEN }}"
/d:sonar.token="${{ secrets.SONAR_TOKEN }}"
/d:sonar.host.url="https://sonarcloud.io"
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This repository contains the Indexer used to build and maintain the Scoop applic
The indexer runs every 2 hours and search for buckets across the whole [GitHub site](https://github.com/ScoopInstaller/scoopinstaller.github.io-indexer/blob/main/src/ScoopSearch.Indexer/appsettings.json#L18-L25) + some additional [inclusions/exclusions](https://github.com/ScoopInstaller/scoopinstaller.github.io-indexer/blob/main/src/ScoopSearch.Indexer/appsettings.json#L28-L40).

### Configuration to build and debug the Indexer
- Install [.NET 7.0 SDK](https://dotnet.microsoft.com/download/dotnet/7.0)
- Install [.NET 8.0 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
- Create an *Azure Search* service
- Retrieve the name (in *Properties*) and use it for `ServiceUrl`
- Retrieve the primary admin key (in *Keys*) and use it for `AdminApiKey`
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<ProjectReference Include="..\ScoopSearch.Indexer\ScoopSearch.Indexer.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Serilog.Enrichers.Sensitive" Version="1.7.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.Sensitive" Version="1.7.3" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void IsCompatible_Succeeds(string input, bool expectedResult)
}

[Fact]
public async void GetBucketAsync_ValidRepo_ReturnsBucket()
public async Task GetBucketAsync_ValidRepo_ReturnsBucket()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -59,7 +59,7 @@ public async void GetBucketAsync_ValidRepo_ReturnsBucket()
}

[Fact]
public async void GetBucketAsync_InvalidRepo_ReturnsNull()
public async Task GetBucketAsync_InvalidRepo_ReturnsNull()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public GitHubBucketsSourceTests(ITestOutputHelper testOutputHelper)
}

[Fact]
public async void GetBucketsAsync_InvalidQueries_ReturnsEmpty()
public async Task GetBucketsAsync_InvalidQueries_ReturnsEmpty()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -42,7 +42,7 @@ public async void GetBucketsAsync_InvalidQueries_ReturnsEmpty()
}

[Fact]
public async void GetBucketsAsync_Succeeds()
public async Task GetBucketsAsync_Succeeds()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ManualBucketsListSourceTests(ITestOutputHelper testOutputHelper)
}

[Fact]
public async void GetBucketsAsync_InvalidUri_ReturnsEmpty()
public async Task GetBucketsAsync_InvalidUri_ReturnsEmpty()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -56,7 +56,7 @@ public async void GetBucketsAsync_InvalidUri_ReturnsEmpty()
[Theory]
[MemberData(nameof(GetBucketsAsyncErrorsTestCases))]
#pragma warning disable xUnit1026
public async void GetBucketsAsync_InvalidStatusCodeSucceeds<TExpectedException>(HttpStatusCode statusCode, string content, TExpectedException _)
public async Task GetBucketsAsync_InvalidStatusCodeSucceeds<TExpectedException>(HttpStatusCode statusCode, string content, TExpectedException _)
#pragma warning restore xUnit1026
where TExpectedException : Exception
{
Expand All @@ -80,16 +80,18 @@ public async void GetBucketsAsync_InvalidStatusCodeSucceeds<TExpectedException>(
await result.Should().ThrowAsync<TExpectedException>();
}

public static IEnumerable<object[]> GetBucketsAsyncErrorsTestCases()
{
yield return new object[] { HttpStatusCode.NotFound, $"url", new HttpRequestException() };
yield return new object[] { HttpStatusCode.OK, "", new ReaderException(null) };
yield return new object[] { HttpStatusCode.OK, $"foo{Environment.NewLine}{Faker.CreateUrl()}", new MissingFieldException(null) };
}
public static TheoryData<HttpStatusCode, string, Exception> GetBucketsAsyncErrorsTestCases() =>
new()
{
{ HttpStatusCode.NotFound, "url", new HttpRequestException() },
{ HttpStatusCode.OK, "", new ReaderException(null) },
{ HttpStatusCode.OK, $"foo{Environment.NewLine}{Faker.CreateUrl()}", new MissingFieldException(null) },
};


[Theory]
[MemberData(nameof(GetBucketsAsyncTestCases))]
public async void GetBucketsAsync_Succeeds(string content, string repositoryUri, bool isCompatible, bool expectedBucket)
public async Task GetBucketsAsync_Succeeds(string content, string repositoryUri, bool isCompatible, bool expectedBucket)
{
// Arrange
_bucketsOptions.ManualBucketsListUrl = Faker.CreateUri();
Expand Down Expand Up @@ -119,12 +121,15 @@ public async void GetBucketsAsync_Succeeds(string content, string repositoryUri,
}
}

public static IEnumerable<object[]> GetBucketsAsyncTestCases()
public static TheoryData<string, string, bool, bool> GetBucketsAsyncTestCases()
{
yield return new object[] { "url", Faker.CreateUrl(), true, false };
var data = new TheoryData<string, string, bool, bool>();
data.Add("url", Faker.CreateUrl(), true, false);
var url = Faker.CreateUrl();
yield return new object[] { $"url{Environment.NewLine}{url}", url, false, false };
yield return new object[] { $"url{Environment.NewLine}{url}", url, true, true };
yield return new object[] { $"url{Environment.NewLine}{url}.git", url, true, true };
data.Add($"url{Environment.NewLine}{url}", url, false, false);
data.Add($"url{Environment.NewLine}{url}", url, true, true);
data.Add($"url{Environment.NewLine}{url}.git", url, true, true);

return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ManualBucketsSourceTests(ITestOutputHelper testOutputHelper)
}

[Fact]
public async void GetBucketsAsync_EmptyManualBuckets_ReturnsEmpty()
public async Task GetBucketsAsync_EmptyManualBuckets_ReturnsEmpty()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -46,7 +46,7 @@ public async void GetBucketsAsync_EmptyManualBuckets_ReturnsEmpty()
}

[Fact]
public async void GetBucketsAsync_ReturnsBuckets()
public async Task GetBucketsAsync_ReturnsBuckets()
{
// Arrange
_bucketsOptions.ManualBuckets = new[] { Faker.CreateUri(), Faker.CreateUri() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public OfficialBucketsSourceTests(ITestOutputHelper testOutputHelper)
}

[Fact]
public async void GetBucketsAsync_InvalidUri_ReturnsEmpty()
public async Task GetBucketsAsync_InvalidUri_ReturnsEmpty()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -56,7 +56,7 @@ public async void GetBucketsAsync_InvalidUri_ReturnsEmpty()
[Theory]
[MemberData(nameof(GetBucketsAsyncErrorsTestCases))]
#pragma warning disable xUnit1026
public async void GetBucketsAsync_InvalidStatusCodeSucceeds<TExpectedException>(HttpStatusCode statusCode, string content, TExpectedException _)
public async Task GetBucketsAsync_InvalidStatusCodeSucceeds<TExpectedException>(HttpStatusCode statusCode, string content, TExpectedException _)
#pragma warning restore xUnit1026
where TExpectedException : Exception
{
Expand All @@ -80,16 +80,17 @@ public async void GetBucketsAsync_InvalidStatusCodeSucceeds<TExpectedException>(
await result.Should().ThrowAsync<TExpectedException>();
}

public static IEnumerable<object[]> GetBucketsAsyncErrorsTestCases()
{
yield return new object[] { HttpStatusCode.NotFound, $"url", new HttpRequestException() };
yield return new object[] { HttpStatusCode.OK, "", new JsonException() };
yield return new object[] { HttpStatusCode.OK, $"foo", new JsonException() };
}
public static TheoryData<HttpStatusCode, string, Exception> GetBucketsAsyncErrorsTestCases() =>
new()
{
{ HttpStatusCode.NotFound, $"url", new HttpRequestException() },
{ HttpStatusCode.OK, "", new JsonException() },
{ HttpStatusCode.OK, $"foo", new JsonException() }
};

[Theory]
[MemberData(nameof(GetBucketsAsyncTestCases))]
public async void GetBucketsAsync_Succeeds(string content, string repositoryUri, bool isCompatible, bool expectedBucket)
public async Task GetBucketsAsync_Succeeds(string content, string repositoryUri, bool isCompatible, bool expectedBucket)
{
// Arrange
_bucketsOptions.OfficialBucketsListUrl = Faker.CreateUri();
Expand Down Expand Up @@ -119,12 +120,15 @@ public async void GetBucketsAsync_Succeeds(string content, string repositoryUri,
}
}

public static IEnumerable<object[]> GetBucketsAsyncTestCases()
public static TheoryData<string, string, bool, bool> GetBucketsAsyncTestCases()
{
var data = new TheoryData<string, string, bool, bool>();
var url = Faker.CreateUrl();
yield return new object[] { $@"{{ }}", url, false, false };
yield return new object[] { $@"{{ }}", url, true, false };
yield return new object[] { $@"{{ ""foo"": ""{url}"" }}", url, false, false };
yield return new object[] { $@"{{ ""foo"": ""{url}"" }}", url, true, true };
data.Add($@"{{ }}", url, false, false);
data.Add($@"{{ }}", url, true, false);
data.Add($@"{{ ""foo"": ""{url}"" }}", url, false, false);
data.Add($@"{{ ""foo"": ""{url}"" }}", url, true, true);

return data;
}
}
8 changes: 4 additions & 4 deletions src/ScoopSearch.Indexer.Tests/Git/GitRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void GetItemsFromIndex_ReturnsEntries()
}

[Fact]
public async void ReadContentAsync_NonExistentEntry_Throws()
public async Task ReadContentAsync_NonExistentEntry_Throws()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -107,7 +107,7 @@ public async void ReadContentAsync_NonExistentEntry_Throws()
}

[Fact]
public async void ReadContentAsync_ExistentEntry_ReturnsContent()
public async Task ReadContentAsync_ExistentEntry_ReturnsContent()
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -123,7 +123,7 @@ public async void ReadContentAsync_ExistentEntry_ReturnsContent()

[Theory]
[MemberData(nameof(GetCommitsCacheTestCases))]
public async void GetCommitsCacheAsync_ReturnsExpectedFilesAndCommits(string repositoryUri, Predicate<string> filter, int expectedFiles, int expectedCommits)
public async Task GetCommitsCacheAsync_ReturnsExpectedFilesAndCommits(string repositoryUri, Predicate<string> filter, int expectedFiles, int expectedCommits)
{
// Arrange
var cancellationToken = new CancellationToken();
Expand All @@ -150,7 +150,7 @@ public static IEnumerable<object[]> GetCommitsCacheTestCases()
[InlineData(Constants.TestRepositoryUri, 1, 5)]
[InlineData("https://github.com/niheaven/scoop-sysinternals", 1, 70)]
[InlineData("https://github.com/ScoopInstaller/Extras", 10, 1_900)]
public async void GetCommitsCacheAsync_BuildCache_Succeeds(string repositoryUri, double maxSeconds, int minimalManifestsCount)
public async Task GetCommitsCacheAsync_BuildCache_Succeeds(string repositoryUri, double maxSeconds, int minimalManifestsCount)
{
// Arrange
var cancellationToken = new CancellationToken();
Expand Down
16 changes: 9 additions & 7 deletions src/ScoopSearch.Indexer.Tests/GitHub/GitHubClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using ScoopSearch.Indexer.GitHub;
Expand All @@ -6,6 +7,7 @@

namespace ScoopSearch.Indexer.Tests.GitHub;

[SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")]
public class GitHubClientTests : IClassFixture<HostFixture>
{
private readonly GitHubClient _sut;
Expand All @@ -20,7 +22,7 @@ public GitHubClientTests(HostFixture hostFixture, ITestOutputHelper testOutputHe

[Theory]
[InlineData("http://example.com/foo/bar")]
public async void GetRepositoryAsync_InvalidRepo_ReturnsNull(string input)
public async Task GetRepositoryAsync_InvalidRepo_ReturnsNull(string input)
{
// Arrange
var uri = new Uri(input);
Expand All @@ -36,7 +38,7 @@ public async void GetRepositoryAsync_InvalidRepo_ReturnsNull(string input)

[Theory]
[InlineData("http://example.invalid/foo/bar")]
public async void GetRepositoryAsync_InvalidDomain_Throws(string input)
public async Task GetRepositoryAsync_InvalidDomain_Throws(string input)
{
// Arrange
var uri = new Uri(input);
Expand All @@ -50,7 +52,7 @@ public async void GetRepositoryAsync_InvalidDomain_Throws(string input)
}

[Fact]
public async void GetRepositoryAsync_NonExistentRepo_ReturnsNull()
public async Task GetRepositoryAsync_NonExistentRepo_ReturnsNull()
{
// Arrange
var uri = new Uri(Constants.NonExistentTestRepositoryUri);
Expand All @@ -64,7 +66,7 @@ public async void GetRepositoryAsync_NonExistentRepo_ReturnsNull()
}

[Fact]
public async void GetRepositoryAsync_RedirectedRepo_ReturnsNull()
public async Task GetRepositoryAsync_RedirectedRepo_ReturnsNull()
{
// Arrange
var uri = new Uri("https://github.com/MCOfficer/scoop-nirsoft");
Expand All @@ -81,7 +83,7 @@ public async void GetRepositoryAsync_RedirectedRepo_ReturnsNull()
[Theory]
[InlineData("https://github.com/ScoopInstaller/Main", 1000)]
[InlineData("https://github.com/ScoopInstaller/Extras", 1500)]
public async void GetRepositoryAsync_ValidRepo_ReturnsGitHubRepo(string input, int expectedMinimumStars)
public async Task GetRepositoryAsync_ValidRepo_ReturnsGitHubRepo(string input, int expectedMinimumStars)
{
// Arrange
var uri = new Uri(input);
Expand All @@ -100,7 +102,7 @@ public async void GetRepositoryAsync_ValidRepo_ReturnsGitHubRepo(string input, i
[InlineData(new object[] { new string[0] })]
[InlineData(new object[] { new[] { "" } })]
[InlineData(new object[] { new[] { "&&==" } })]
public async void SearchRepositoriesAsync_InvalidQueryUrl_Throws(string[] input)
public async Task SearchRepositoriesAsync_InvalidQueryUrl_Throws(string[] input)
{
// Arrange + Act
var cancellationToken = new CancellationToken();
Expand All @@ -122,7 +124,7 @@ public async void SearchRepositoriesAsync_InvalidQueryUrl_Throws(string[] input)
[Theory]
[InlineData(new object[] { new[] { "scoop-bucket", "created:>2023-01-01" } })]
[InlineData(new object[] { new[] { "scoop+bucket", "created:>2023-01-01" } })]
public async void SearchRepositoriesAsync_ValidQuery_ReturnsSearchResults(string[] input)
public async Task SearchRepositoriesAsync_ValidQuery_ReturnsSearchResults(string[] input)
{
// Arrange + Act
var cancellationToken = new CancellationToken();
Expand Down
Loading

0 comments on commit 92fe91c

Please sign in to comment.