Skip to content

Commit

Permalink
asyncapi#197 .build nuget package
Browse files Browse the repository at this point in the history
  • Loading branch information
Senn Geerts authored and Senn Geerts committed Jul 13, 2024
1 parent 5823431 commit 38ac1eb
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 189 deletions.
5 changes: 0 additions & 5 deletions examples/StreetlightsAPI/StreetlightsAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<!-- Special args for the AsyncAPI.Generator.Cli tool used by local build AsyncAPI.Generator.Build nuget package,
do not use in normal usage scenarios, this is to use a local build version -->
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<AsyncAPICliToolArgs>--version "999.*" --add-source "$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../../local-nuget-source))"</AsyncAPICliToolArgs>
</PropertyGroup>

<!-- For release: use a real published nuget package -->
<ItemGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>12</LangVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
Expand All @@ -15,7 +15,7 @@
<RepositoryUrl>https://github.com/asyncapi/saunter</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
<PackageProjectUrl>https://github.com/asyncapi/saunter</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -24,6 +24,10 @@
<Version>1.0.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<!-- 999.* are local builds numbers, they must be unique each build to bypass all nuget caching -->
<Version>999.$([System.DateTime]::Now.ToString("yy"))$([System.DateTime]::Now.DayOfYear).$([System.DateTime]::Now.ToString("HHmm"))</Version>
Expand All @@ -41,6 +45,11 @@
<None Include="readme.md" Pack="true" PackagePath="/" />
<None Include="../../assets/logo.png" Pack="true" PackagePath="/" />
<None Include="build/*" Pack="true" PackagePath="/build" />
<None Include="bin/$(Configuration)/$(TargetFramework)" Pack="true" PackagePath="/tools" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AsyncAPI.Saunter.Generator.Cli\AsyncAPI.Saunter.Generator.Cli.csproj" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<PropertyGroup>
<AsyncAPIBuildToolBuildDir>$([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory)))</AsyncAPIBuildToolBuildDir>
<AsyncAPIBuildToolRoot>$([System.IO.Path]::GetDirectoryName($(AsyncAPIBuildToolBuildDir)))</AsyncAPIBuildToolRoot>
<LocalToolConfigFile>./.config/dotnet-tools.json</LocalToolConfigFile>
<LocalToolConfigFillFullPath>$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(AsyncAPIBuildToolRoot), $(LocalToolConfigFile)))))</LocalToolConfigFillFullPath>
<!-- Pin the default version of the Generator.Cli tool to use -->
<AsyncAPICliToolArgs Condition=" '$(AsyncAPICliToolArgs)' == '' ">--version [1.0.2-beta]</AsyncAPICliToolArgs>
<AsyncAPIBuildToolIsInitialized>$([System.IO.File]::Exists($(LocalToolConfigFillFullPath)))</AsyncAPIBuildToolIsInitialized>
<AsyncAPICliToolPath>$([System.IO.Path]::Combine($(AsyncAPIBuildToolRoot), tools, net8.0, AsyncAPI.Saunter.Generator.Cli.dll))</AsyncAPICliToolPath>
<AsyncAPICliToolStartupAssembly>$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(OutputPath), $(AssemblyTitle).dll))</AsyncAPICliToolStartupAssembly>
<AsyncAPICliToolOutputPath>$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(AsyncAPIDocumentOutputPath)))</AsyncAPICliToolOutputPath>
</PropertyGroup>

<!-- Debug output: print some paths, set -v flag (verbosity) at least to [n]ormal to show in build output -->
<Message Text="AsyncAPI.Generator.Build; AsyncAPIBuildToolIsInitialized: $(AsyncAPIBuildToolIsInitialized)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPICliToolArgs: $(AsyncAPICliToolArgs)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPICliToolPath: $(AsyncAPICliToolPath)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPICliToolStartupAssembly: $(AsyncAPICliToolStartupAssembly)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPICliToolOutputPath: $(AsyncAPICliToolOutputPath)" />

<Message Text="AsyncAPI.Generator.Build; AsyncAPIDocumentFormats: $(AsyncAPIDocumentFormats)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIDocumentOutputPath: $(AsyncAPIDocumentOutputPath)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIDocumentNames: $(AsyncAPIDocumentNames)" />
Expand All @@ -27,17 +27,8 @@
<Message Text="AsyncAPI.Generator.Build; MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)" />
<Message Text="AsyncAPI.Generator.Build; MSBuildProjectFullPath: $(MSBuildProjectFullPath)" />
<Message Text="AsyncAPI.Generator.Build; MSBuildProjectDirectory: $(MSBuildProjectDirectory)" />
<Message Text="AsyncAPI.Generator.Build; LocalToolConfigFile: $(LocalToolConfigFile); FullPath: $(LocalToolConfigFillFullPath)" />

<!-- dotnet-asyncapi is installed locally in the AsyncAPI.Generator.Build .nuget folder, install is only needed once -->
<Exec Command="dotnet new tool-manifest --force"
Condition=" '$(AsyncAPIBuildToolIsInitialized)' == 'false'"
WorkingDirectory="$(AsyncAPIBuildToolRoot)" />
<Exec Command="dotnet tool install --local $(AsyncAPICliToolArgs) AsyncAPI.Saunter.Generator.Cli"
Condition=" '$(AsyncAPIBuildToolIsInitialized)' == 'false'"
WorkingDirectory="$(AsyncAPIBuildToolRoot)" />

<Exec Command="dotnet tool run dotnet-asyncapi tofile --output &quot;$(MSBuildProjectDirectory)/$(AsyncAPIDocumentOutputPath)&quot; --format &quot;$(AsyncAPIDocumentFormats)&quot; --doc &quot;$(AsyncAPIDocumentNames)&quot; --filename &quot;$(AsyncAPIDocumentFilename)&quot; --env &quot;$(AsyncAPIDocumentEnvVars)&quot; &quot;$(MSBuildProjectDirectory)/$(OutputPath)/$(AssemblyTitle).dll&quot;"
<Exec Command="dotnet &quot;$(AsyncAPICliToolPath)&quot; tofile &quot;$(AsyncAPICliToolStartupAssembly)&quot; --output &quot;$(AsyncAPICliToolOutputPath)&quot; --format &quot;$(AsyncAPIDocumentFormats)&quot; --doc &quot;$(AsyncAPIDocumentNames)&quot; --filename &quot;$(AsyncAPIDocumentFilename)&quot; --env &quot;$(AsyncAPIDocumentEnvVars)&quot;"
WorkingDirectory="$(AsyncAPIBuildToolRoot)" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AsyncAPI.NET.Readers" Version="5.2.1" PrivateAssets="All" />
<PackageReference Include="AsyncAPI.NET.Readers" Version="5.2.1" />
<PackageReference Include="ConsoleAppFramework" Version="5.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -56,7 +56,7 @@
</ItemGroup>

<ItemGroup>
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="/" />
<None Include="../../assets/logo.png" Pack="true" PackagePath="/" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public IServiceProvider BuildServiceProvider(string startupAssembly)
var fullPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), startupAssembly));
logger.LogInformation($"Loading startup assembly: {fullPath}");
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
var nswagCommandsAssembly = Assembly.LoadFrom("NSwag.Commands.dll");
var nswagCommandsAssembly = Assembly.LoadFrom(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(ServiceProviderBuilder).Assembly.Location), "NSwag.Commands.dll")));
var nswagServiceProvider = nswagCommandsAssembly.GetType("NSwag.Commands.ServiceProviderResolver");
var serviceProvider = (IServiceProvider)nswagServiceProvider.InvokeMember("GetServiceProvider", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, null, [assembly]);
return serviceProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public int ToFile([Argument] string startupassembly, string output = "./", strin
}
}

return 1;
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>

Expand Down
161 changes: 2 additions & 159 deletions test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,169 +67,12 @@ public void StreetlightsAPIExportSpecTest()
File.Exists("asyncapi.json").ShouldBeTrue("asyncapi.json");

var yml = File.ReadAllText("asyncapi.yml");
yml.ShouldBe("""
asyncapi: 2.6.0
info:
title: Streetlights API
version: 1.0.0
description: The Smartylighting Streetlights API allows you to remotely manage the city lights.
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0
servers:
mosquitto:
url: test.mosquitto.org
protocol: mqtt
webapi:
url: localhost:5000
protocol: http
defaultContentType: application/json
channels:
publish/light/measured:
servers:
- webapi
publish:
operationId: MeasureLight
summary: Inform about environmental lighting conditions for a particular streetlight.
tags:
- name: Light
message:
$ref: '#/components/messages/lightMeasuredEvent'
subscribe/light/measured:
servers:
- mosquitto
subscribe:
operationId: PublishLightMeasurement
summary: Subscribe to environmental lighting conditions for a particular streetlight.
tags:
- name: Light
message:
payload:
$ref: '#/components/schemas/lightMeasuredEvent'
components:
schemas:
lightMeasuredEvent:
type: object
properties:
id:
type: integer
format: int32
description: Id of the streetlight.
lumens:
type: integer
format: int32
description: Light intensity measured in lumens.
sentAt:
type: string
format: date-time
description: Light intensity measured in lumens.
additionalProperties: false
messages:
lightMeasuredEvent:
payload:
$ref: '#/components/schemas/lightMeasuredEvent'
name: lightMeasuredEvent
""", "yaml");
yml.ShouldBe(ExpectedSpecFiles.Yml_v2_6, "yaml");

var yaml = File.ReadAllText("asyncapi.yaml");
yaml.ShouldBe(yml, "yml");

var json = File.ReadAllText("asyncapi.json");
json.ShouldBe("""
{
"asyncapi": "2.6.0",
"info": {
"title": "Streetlights API",
"version": "1.0.0",
"description": "The Smartylighting Streetlights API allows you to remotely manage the city lights.",
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"servers": {
"mosquitto": {
"url": "test.mosquitto.org",
"protocol": "mqtt"
},
"webapi": {
"url": "localhost:5000",
"protocol": "http"
}
},
"defaultContentType": "application/json",
"channels": {
"publish/light/measured": {
"servers": [
"webapi"
],
"publish": {
"operationId": "MeasureLight",
"summary": "Inform about environmental lighting conditions for a particular streetlight.",
"tags": [
{
"name": "Light"
}
],
"message": {
"$ref": "#/components/messages/lightMeasuredEvent"
}
}
},
"subscribe/light/measured": {
"servers": [
"mosquitto"
],
"subscribe": {
"operationId": "PublishLightMeasurement",
"summary": "Subscribe to environmental lighting conditions for a particular streetlight.",
"tags": [
{
"name": "Light"
}
],
"message": {
"payload": {
"$ref": "#/components/schemas/lightMeasuredEvent"
}
}
}
}
},
"components": {
"schemas": {
"lightMeasuredEvent": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32",
"description": "Id of the streetlight."
},
"lumens": {
"type": "integer",
"format": "int32",
"description": "Light intensity measured in lumens."
},
"sentAt": {
"type": "string",
"format": "date-time",
"description": "Light intensity measured in lumens."
}
},
"additionalProperties": false
}
},
"messages": {
"lightMeasuredEvent": {
"payload": {
"$ref": "#/components/schemas/lightMeasuredEvent"
},
"name": "lightMeasuredEvent"
}
}
}
}
""", "json");
json.ShouldBe(ExpectedSpecFiles.Json_v2_6, "json");
}
}

0 comments on commit 38ac1eb

Please sign in to comment.