Skip to content

Commit

Permalink
chore: clean-up and prepare NuGet publish
Browse files Browse the repository at this point in the history
Signed-off-by: Thorsten Hans <[email protected]>
  • Loading branch information
ThorstenHans committed May 29, 2024
1 parent 45175d4 commit 930d5e4
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 171 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ on:
push:
branches:
- "main"
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
pull_request:
branches:
- "main"

env:
VERSION: 0.0.1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
Expand All @@ -22,23 +25,39 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Set Version Variable
if: ${{ github.ref_type == 'tag' }}
env:
TAG: ${{ github.ref_name }}
run: echo "VERSION=${TAG#v}" >> $GITHUB_ENV

- name: Build Aspire.Hosting.Spin
run: dotnet build --configuration Release
run: dotnet build --configuration Release /p:Version=$VERSION
working-directory: ./Aspire.Hosting.Spin

- name: Run Tests
run: dotnet test --logger trx --results-directory "test-results"
- name: Upload .NET Test Results

- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: dotnet-test-results
path: test-results
if: ${{ always() }}

- name: Install .NET Aspire Workload
run: dotnet workload install aspire

- name: Build Sample Application
run: dotnet build --configuration Release
working-directory: ./example/host

- name: Publish NuGet Package
if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
run: dotnet nuget push ./Aspire.Hosting.Spin/bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
18 changes: 9 additions & 9 deletions Aspire.Hosting.Spin.Tests/Aspire.Hosting.Spin.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="Moq" Version="4.20.70"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Hosting.Spin\Aspire.Hosting.Spin.csproj" />
<ProjectReference Include="..\Aspire.Hosting.Spin\Aspire.Hosting.Spin.csproj"/>
</ItemGroup>

</Project>
14 changes: 5 additions & 9 deletions Aspire.Hosting.Spin.Tests/CheckForSpinTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Aspire.Hosting.ApplicationModel;
using FluentAssertions;
using Moq;

namespace Aspire.Hosting.Spin.Tests;

public class CheckForSpinTests
{

bool IsSpinInPath()
private bool IsSpinInPath()
{
var paths = Environment.GetEnvironmentVariable("PATH")!.Split(Path.PathSeparator);
return paths.Select(path => Path.Combine(path, "spin"))
Expand All @@ -20,19 +17,18 @@ public async Task ItShouldPassIfSpinIsInstalled()
Skip.IfNot(IsSpinInPath());
var sut = new CheckForSpin();
var act = () => sut.BeforeStartAsync(null!);

await act.Should().NotThrowAsync();
}

[SkippableFact]
public async Task ItShouldFailIfSpinIsNotInstalled()
{
Skip.If(IsSpinInPath());

var sut = new CheckForSpin();
var act = () => sut.BeforeStartAsync(null!);

await act.Should().ThrowAsync<Exception>();
}

}
6 changes: 1 addition & 5 deletions Aspire.Hosting.Spin.Tests/OciReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ namespace Aspire.Hosting.Spin.Tests;

public class OciReferenceTests
{

[Theory]
[InlineData("nginx", "1-alpine", "nginx:1-alpine")]
[InlineData("nginx", "1.0.0", "nginx:1.0.0")]
[InlineData("nginx", "", "nginx:latest")]
[InlineData("thorstenhans/hello", "0.0.1", "thorstenhans/hello:0.0.1")]

public void ItShouldGenerateValidOciReferences(string repository, string tag, string expected)
{
var sut = OciReference.From(repository, tag);
sut.ToString().Should().Be(expected);

}

[Theory]
[InlineData("")]
[InlineData(" ")]
Expand All @@ -38,5 +35,4 @@ public void OciReferenceShouldNotAllowNullOrEmptyForRepository(string repository
var act = () => OciReference.From(repository, "some");
act.Should().Throw<ArgumentException>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public async Task ItShouldProvideAFluentAPI()

mockRedis.Setup(r => r.Resource.GetValueAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync("redis://foo");

var sut = await SpinRuntimeConfigurationBuilder.Create("foo.yaml")
.WithSqliteDatabase("default", "my.sqlite")
.WithRedisKeyValueStore("foo", mockRedis.Object)
Expand All @@ -31,7 +31,7 @@ public async Task ItShouldSetSqliteDatabaseDetails()
sut.SqliteDatabases.Should().HaveCount(1);
sut.SqliteDatabases.Should().Contain("default", new SqliteDatabase("custom.sqlite"));
}

[Fact]
public async Task ItShouldThrowWhenUserTriesToConfigureSqliteDatabaseTwiceWithSameName()
{
Expand All @@ -57,7 +57,7 @@ public async Task ItShouldSetRedisKeyValueStoreDetails()
sut.KeyValueStores.Should().HaveCount(1);
sut.KeyValueStores.Should().Contain("some", new RedisKeyValueStore("redis://some"));
}

[Fact]
public async Task ItShouldThrowWhenUserTriesToConfigureRedisKeyValueStoreTwiceWithSameName()
{
Expand All @@ -72,11 +72,10 @@ await SpinRuntimeConfigurationBuilder.Create("foo.yaml")
};
await action.Should().ThrowAsync<ArgumentException>();
}

[Fact]
public async Task ItShouldThrowWhenUserTriesToConfigureSqliteKeyValueStoreTwiceWithSameName()
{

var action = async () =>
{
await SpinRuntimeConfigurationBuilder.Create("foo.yaml")
Expand All @@ -86,7 +85,7 @@ await SpinRuntimeConfigurationBuilder.Create("foo.yaml")
};
await action.Should().ThrowAsync<ArgumentException>();
}

[Fact]
public async Task ItShouldThrowWhenUserTriesToConfigureKeyValueStoresWithDuplicatedName()
{
Expand All @@ -102,7 +101,7 @@ await SpinRuntimeConfigurationBuilder.Create("foo.yaml")
};
await action.Should().ThrowAsync<ArgumentException>();
}

[Fact]
public async Task ItShouldSetSqliteKeyValueStoreDetails()
{
Expand All @@ -113,7 +112,7 @@ public async Task ItShouldSetSqliteKeyValueStoreDetails()
sut.KeyValueStores.Should().HaveCount(1);
sut.KeyValueStores.Should().Contain("some", new SpinKeyValueStore("kv.sqlite"));
}

[Fact]
public async Task ItShouldSetMultipleKeyValueStoreDetails()
{
Expand Down
34 changes: 21 additions & 13 deletions Aspire.Hosting.Spin/Aspire.Hosting.Spin.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Product>Aspire.Hosting.Spin</Product>
<PackageId>com.fermyon.spin.aspire.hosting</PackageId>
<Authors>Fermyon Technologies</Authors>
<Company>Fermyon Technologies</Company>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.20</Version>
</PropertyGroup>
<PropertyGroup>
<Product>Aspire.Hosting.Spin</Product>
<PackageId>Aspire.Hosting.Spin</PackageId>
<Authors>Fermyon Technologies</Authors>
<Company>Fermyon Technologies</Company>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/fermyon/Aspire.Hosting.Spin</PackageProjectUrl>
<RepositoryUrl>https://github.com/fermyon/Aspire.Hosting.Spin</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Nullable>enable</Nullable>
<Version>0.0.20</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting" Version="8.0.1"/>
</ItemGroup>
<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="/"/>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Aspire.Hosting.Spin/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class Constants
{
public const string SpinBinary = "spin";
public const string SpinVariablePrefix = "SPIN_VARIABLE_";

public static class SpinCommands
{
public const string Up = "up";
Expand All @@ -25,6 +26,5 @@ public static class SpinFlags
public const string Version = "--version";
public const string Listen = "--listen";
public const string Confirm = "--yes";

}
}
3 changes: 2 additions & 1 deletion Aspire.Hosting.Spin/LifecycleHooks/CheckForSpin.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Diagnostics;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;

namespace Aspire.Hosting;

public class CheckForSpin : Lifecycle.IDistributedApplicationLifecycleHook
public class CheckForSpin : IDistributedApplicationLifecycleHook
{
public async Task BeforeStartAsync(DistributedApplicationModel appModel,
CancellationToken cancellationToken = new())
Expand Down
9 changes: 6 additions & 3 deletions Aspire.Hosting.Spin/LifecycleHooks/InstallSpinPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using System.Diagnostics;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;

namespace Aspire.Hosting;

public class InstallSpinPlugin : Lifecycle.IDistributedApplicationLifecycleHook
public class InstallSpinPlugin : IDistributedApplicationLifecycleHook
{
private readonly string _pluginName;

public InstallSpinPlugin(string name)
{
_pluginName = name;
}

public async Task BeforeStartAsync(DistributedApplicationModel appModel,
CancellationToken cancellationToken = new())
{
Expand All @@ -21,7 +23,8 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel,
StartInfo = new ProcessStartInfo
{
FileName = Constants.SpinBinary,
Arguments = $"{Constants.SpinCommands.Plugins} {Constants.SpinCommands.Install} {_pluginName} {Constants.SpinFlags.Confirm}",
Arguments =
$"{Constants.SpinCommands.Plugins} {Constants.SpinCommands.Install} {_pluginName} {Constants.SpinFlags.Confirm}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down
9 changes: 6 additions & 3 deletions Aspire.Hosting.Spin/LifecycleHooks/SpinRegistryLogin.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using System.Diagnostics;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;

namespace Aspire.Hosting;

public class SpinRegistryLogin: Lifecycle.IDistributedApplicationLifecycleHook {
public class SpinRegistryLogin : IDistributedApplicationLifecycleHook
{
private readonly OciRegistryCredentials _creds;

public SpinRegistryLogin(OciRegistryCredentials creds)
{
_creds = creds;
}

public async Task BeforeStartAsync(DistributedApplicationModel appModel,
CancellationToken cancellationToken = new())
{
Expand All @@ -21,7 +23,8 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel,
StartInfo = new ProcessStartInfo
{
FileName = Constants.SpinBinary,
Arguments = $"{Constants.SpinCommands.Registry} {Constants.SpinCommands.Login} {_creds.LoginServer} -u {_creds.User} -p {_creds.Password}",
Arguments =
$"{Constants.SpinCommands.Registry} {Constants.SpinCommands.Login} {_creds.LoginServer} -u {_creds.User} -p {_creds.Password}",
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
Expand Down
6 changes: 3 additions & 3 deletions Aspire.Hosting.Spin/OciReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ public class OciReference(string repository, string tag)
{
public const string Latest = "latest";

public string Repository { get; } = repository;
public string Tag { get; } = tag;

public static OciReference From(string repository, string tag)
{
ArgumentException.ThrowIfNullOrWhiteSpace(repository);
return new OciReference(repository, tag);
}

public String Repository { get; } = repository;
public String Tag { get; } = tag;

public override string ToString()
{
Expand Down
7 changes: 4 additions & 3 deletions Aspire.Hosting.Spin/OciRegistryCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ namespace Aspire.Hosting;

public class OciRegistryCredentials
{
public required string LoginServer { get; init; }
public required string User { get; init; }
public required string Password { get; init; }

public static OciRegistryCredentials Create(string loginServer, string user, string password)
{
ArgumentException.ThrowIfNullOrWhiteSpace(loginServer);
Expand All @@ -14,7 +18,4 @@ public static OciRegistryCredentials Create(string loginServer, string user, str
Password = password
};
}
public required string LoginServer { get; init; }
public required string User { get; init; }
public required string Password { get; init; }
}
Loading

0 comments on commit 930d5e4

Please sign in to comment.