Skip to content

Commit

Permalink
asyncapi#197 use 999.* for local nuget package buils to use in tests …
Browse files Browse the repository at this point in the history
…and example project
  • Loading branch information
SennG committed Jul 7, 2024
1 parent 829d5a5 commit 49fb31f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ PublishScripts/
*.nuget.props
*.nuget.targets
local-nuget-source/
dotnet-tools.json

# Microsoft Azure Build Output
csx/
Expand Down
10 changes: 8 additions & 2 deletions examples/StreetlightsAPI/StreetlightsAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>

<!-- Get the latest local build nuget package from source code, from the local nuget packages source as configured in nuget.config -->
<!-- Get the latest local build nuget package from source code, from the local nuget packages source as configured in nuget.config
999.* are the 'special' version number for local builds -->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="AsyncAPI.Saunter.Generator.Build" Version="0.0.999-*">
<PackageReference Include="AsyncAPI.Saunter.Generator.Build" Version="999.*">
<PrivateAssets>all</PrivateAssets>
<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
Expand Up @@ -25,7 +25,8 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Version>0.0.999-debug-$([System.DateTime]::Now.ToString('yyyyMMddHHmm'))</Version>
<!-- 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>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>../../local-nuget-source</PackageOutputPath>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project>

<!-- List all available properties to customize the AsyncAPI.Generator.Build package -->
<PropertyGroup>
<AsyncAPIGenerateDocumentsOnBuild Condition=" '$(AsyncAPIGenerateDocumentsOnBuild)' == '' ">true</AsyncAPIGenerateDocumentsOnBuild>
<AsyncAPIDocumentFormats Condition=" '$(AsyncAPIDocumentFormats)' == '' ">json</AsyncAPIDocumentFormats>
Expand All @@ -8,4 +10,5 @@
<AsyncAPIDocumentNames Condition=" '$(AsyncAPIDocumentNames)' == '' "></AsyncAPIDocumentNames>
<AsyncAPIDocumentEnvVars Condition=" '$(AsyncAPIDocumentEnvVars)' == '' "></AsyncAPIDocumentEnvVars>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,38 @@
<Project>

<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(AsyncAPIGenerateDocumentsOnBuild)' == 'true' ">
<!-- Calculate some paths -->
<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>
<AsyncAPICliToolArgs Condition=" '$(AsyncAPICliToolArgs)' == '' "></AsyncAPICliToolArgs>
<AsyncAPIBuildToolIsInitialized>$([System.IO.File]::Exists($(LocalToolConfigFillFullPath)))</AsyncAPIBuildToolIsInitialized>
</PropertyGroup>

<Message Text="AsyncAPI.Build; AsyncAPIDocumentFormats: $(AsyncAPIDocumentFormats)" />
<Message Text="AsyncAPI.Build; AsyncAPIDocumentOutputPath: $(AsyncAPIDocumentOutputPath)" />
<Message Text="AsyncAPI.Build; AsyncAPIDocumentNames: $(AsyncAPIDocumentNames)" />
<Message Text="AsyncAPI.Build; AsyncAPIDocumentFilename: $(AsyncAPIDocumentFilename)" />
<Message Text="AsyncAPI.Build; AsyncAPIDocumentEnvVars: $(AsyncAPIDocumentEnvVars)" />
<Message Text="AsyncAPI.Build; AsyncAPIBuildToolBuildDir: $(AsyncAPIBuildToolBuildDir)" />
<Message Text="AsyncAPI.Build; AsyncAPIBuildToolRoot: $(AsyncAPIBuildToolRoot)" />
<Message Text="AsyncAPI.Build; MSBuildThisFile: $(MSBuildThisFile)" />
<Message Text="AsyncAPI.Build; MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)" />
<Message Text="AsyncAPI.Build; MSBuildProjectFullPath: $(MSBuildProjectFullPath)" />
<Message Text="AsyncAPI.Build; MSBuildProjectDirectory: $(MSBuildProjectDirectory)" />
<Message Text="AsyncAPI.Build; LocalToolConfigFile: $(LocalToolConfigFile) --> $(LocalToolConfigFillFullPath)" />

<Exec Command="dotnet new tool-manifest"
Condition=" '$([System.IO.File]::Exists($(LocalToolConfigFillFullPath)))' == 'false' "
<!-- 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; AsyncAPIDocumentFormats: $(AsyncAPIDocumentFormats)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIDocumentOutputPath: $(AsyncAPIDocumentOutputPath)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIDocumentNames: $(AsyncAPIDocumentNames)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIDocumentFilename: $(AsyncAPIDocumentFilename)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIDocumentEnvVars: $(AsyncAPIDocumentEnvVars)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIBuildToolBuildDir: $(AsyncAPIBuildToolBuildDir)" />
<Message Text="AsyncAPI.Generator.Build; AsyncAPIBuildToolRoot: $(AsyncAPIBuildToolRoot)" />
<Message Text="AsyncAPI.Generator.Build; MSBuildThisFile: $(MSBuildThisFile)" />
<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 AsyncAPI.Saunter.Generator.Cli"
<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;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Version>0.0.999-debug-$([System.DateTime]::Now.ToString('yyyyMMddHHmm'))</Version>
<!-- 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>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>../../local-nuget-source</PackageOutputPath>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,30 @@ private string Run(string file, string args, string workingDirectory, int expect
[Fact]
public void Pack_Install_Run_Uninstall_Test()
{
var stdOut = this.Run("dotnet", "pack", "../../../../../src/AsyncAPI.Saunter.Generator.Cli");
var workingDirectory = "../../../../../src/AsyncAPI.Saunter.Generator.Cli";
var stdOut = this.Run("dotnet", "pack", workingDirectory);
stdOut.ShouldContain("Successfully created package");

stdOut = this.Run("dotnet", "tool install --global --add-source ./bin/Release AsyncAPI.Saunter.Generator.Cli", "../../../../../src/AsyncAPI.Saunter.Generator.Cli");
// use --force flag to ensure the test starts clean every run
stdOut = this.Run("dotnet", "new tool-manifest --force", workingDirectory);
stdOut.ShouldContain("The template \"Dotnet local tool manifest file\" was created successfully");

stdOut = this.Run("dotnet", "tool install --local --add-source ./bin/Release AsyncAPI.Saunter.Generator.Cli", workingDirectory);
stdOut = stdOut.Replace("Skipping NuGet package signature verification.", "").Trim();
stdOut.ShouldBeOneOf("You can invoke the tool using the following command: dotnet-asyncapi\r\nTool 'asyncapi.saunter.generator.cli' (version '1.0.1') was successfully installed.",
"Tool 'asyncapi.saunter.generator.cli' was reinstalled with the stable version (version '1.0.1').");
stdOut.ShouldContain("You can invoke the tool from this directory using the following commands: 'dotnet tool run dotnet-asyncapi");
stdOut.ShouldContain("was successfully installed.");

stdOut = this.Run("dotnet", "tool list -g asyncapi.saunter.generator.cli", "");
stdOut = this.Run("dotnet", "tool list --local asyncapi.saunter.generator.cli", workingDirectory);
stdOut.ShouldContain("dotnet-asyncapi");

stdOut = this.Run("dotnet", "asyncapi", "", 1);
stdOut = this.Run("dotnet", "tool run dotnet-asyncapi", workingDirectory, 1);
stdOut.ShouldContain("tofile: retrieves AsyncAPI from a startup assembly, and writes to file");

stdOut = this.Run("dotnet", "tool uninstall -g asyncapi.saunter.generator.cli", "");
stdOut.ShouldContain(" was successfully uninstalled.");
stdOut = this.Run("dotnet", "tool uninstall --local asyncapi.saunter.generator.cli", workingDirectory);
stdOut.ShouldContain(" was successfully uninstalled");
stdOut.ShouldContain("removed from manifest file");

stdOut = this.Run("dotnet", "tool list -g asyncapi.saunter.generator.cli", "", 1);
stdOut = this.Run("dotnet", "tool list --local asyncapi.saunter.generator.cli", workingDirectory, 1);
stdOut.ShouldNotContain("dotnet-asyncapi");
}
}

0 comments on commit 49fb31f

Please sign in to comment.