Skip to content

Commit

Permalink
update to .net and use latest bicep
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimdalen committed Dec 14, 2023
1 parent 2ced46a commit cdbe22a
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 71 deletions.
4 changes: 2 additions & 2 deletions src/BicepDocs.Cli/BicepDocs.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RootNamespace>LandingZones.Tools.BicepDocs.Cli</RootNamespace>
<StartupObject>LandingZones.Tools.BicepDocs.Cli.Program</StartupObject>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>Joachim Dalen</Authors>
Expand All @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Bicep.Decompiler" Version="0.14.85" />
<PackageReference Include="Azure.Bicep.Decompiler" Version="0.23.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
Expand Down
4 changes: 2 additions & 2 deletions src/BicepDocs.Core.UnitTests/BicepDocs.Core.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Core.UnitTests</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Core.UnitTests</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Bicep.Core" Version="0.14.85" />
<PackageReference Include="Azure.Bicep.Core" Version="0.23.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
Expand Down
6 changes: 2 additions & 4 deletions src/BicepDocs.Core.UnitTests/ResourceLinkBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Immutable;
using Bicep.Core.Resources;

namespace LandingZones.Tools.BicepDocs.Core.UnitTests;
Expand All @@ -10,14 +9,13 @@ public class ResourceLinkBuilderTests

[TestMethod]
[DataRow(
"Microsoft.Web", "microsoft.web,sites", "2018-11-01",
"Microsoft.Web", "microsoft.web/sites", "2018-11-01",
"microsoft.web/2018-11-01/sites",
DisplayName = "Parses one level resource"
)]
public void TestMethod1(string provider, string resource, string apiVersion, string expected)
{
var resourceParts = resource.Split(",").ToImmutableArray();
var resourceRef = new ResourceTypeReference(resourceParts, apiVersion);
var resourceRef = new ResourceTypeReference(resource, apiVersion);
var generatedLink = ResourceLinkBuilder.GetResourceUrl(resourceRef);
Assert.AreEqual($"{Base}{expected}", generatedLink);
}
Expand Down
4 changes: 2 additions & 2 deletions src/BicepDocs.Core/BicepDocs.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Core</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Core</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Bicep.Decompiler" Version="0.14.85" />
<PackageReference Include="Azure.Bicep.Decompiler" Version="0.23.1" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="20.0.4" />
Expand Down
39 changes: 23 additions & 16 deletions src/BicepDocs.Core/Installer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Immutable;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using Bicep.Core;
Expand All @@ -10,33 +11,39 @@
using Bicep.Core.Registry;
using Bicep.Core.Registry.Auth;
using Bicep.Core.Semantics.Namespaces;
using Bicep.Core.TypeSystem;
using Bicep.Core.TypeSystem.Az;
using Bicep.Core.Utils;
using Bicep.Decompiler;
using LandingZones.Tools.BicepDocs.Core.Abstractions;
using LandingZones.Tools.BicepDocs.Core.Services;
using Microsoft.Extensions.DependencyInjection;
using BicepConfigurationManager = Bicep.Core.Configuration.ConfigurationManager;


namespace LandingZones.Tools.BicepDocs.Core;

public class EmptyModuleRegistryProvider : IArtifactRegistryProvider
{
public ImmutableArray<IArtifactRegistry> Registries(Uri _) => ImmutableArray<IArtifactRegistry>.Empty;
}

public static class Installer
{
public static IServiceCollection AddBicepCore(this IServiceCollection services) => services
.AddScoped<INamespaceProvider, DefaultNamespaceProvider>()
.AddScoped<IAzResourceTypeLoader, AzResourceTypeLoader>()
.AddScoped<IContainerRegistryClientFactory, ContainerRegistryClientFactory>()
.AddScoped<ITemplateSpecRepositoryFactory, TemplateSpecRepositoryFactory>()
.AddScoped<IModuleDispatcher, ModuleDispatcher>()
.AddScoped<IModuleRegistryProvider, DefaultModuleRegistryProvider>()
.AddScoped<ITokenCredentialFactory, TokenCredentialFactory>()
.AddScoped<IFileResolver, FileResolver>()
.AddScoped<IFileSystem, MockFileSystem>()
.AddScoped<IConfigurationManager, BicepConfigurationManager>()
.AddScoped<IApiVersionProviderFactory, ApiVersionProviderFactory>()
.AddScoped<IBicepAnalyzer, LinterAnalyzer>()
.AddScoped<IFeatureProviderFactory, FeatureProviderFactory>()
.AddScoped<ILinterRulesProvider, LinterRulesProvider>()
.AddScoped<BicepCompiler>();
.AddSingleton<IResourceTypeLoader, AzResourceTypeLoader>()
.AddSingleton<IResourceTypeLoaderFactory, AzResourceTypeLoaderFactory>()
.AddSingleton<INamespaceProvider, DefaultNamespaceProvider>()
.AddSingleton<IModuleDispatcher, ModuleDispatcher>()
.AddSingleton<IArtifactRegistryProvider, EmptyModuleRegistryProvider>()
.AddSingleton<ITokenCredentialFactory, TokenCredentialFactory>()
.AddSingleton<IFileResolver, FileResolver>()
.AddSingleton<IEnvironment, Bicep.Core.Utils.Environment>()
.AddSingleton<IFileSystem, MockFileSystem>()
.AddSingleton<IConfigurationManager, ConfigurationManager>()
.AddSingleton<IBicepAnalyzer, LinterAnalyzer>()
.AddSingleton<IFeatureProviderFactory, FeatureProviderFactory>()
.AddSingleton<ILinterRulesProvider, LinterRulesProvider>()
.AddSingleton<BicepCompiler>();

public static IServiceCollection AddBicepDecompiler(this IServiceCollection services) => services
.AddScoped<BicepDecompiler>();
Expand Down
2 changes: 1 addition & 1 deletion src/BicepDocs.Core/Services/BicepFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static string FormatBicepCode(string input)
var parser = new Parser(input);
var programSyntax = parser.Program();
var options = new PrettyPrintOptions(NewlineOption.Auto, IndentKindOption.Space, 2, false);
return PrettyPrinter.PrintProgram(programSyntax, options);
return PrettyPrinter.PrintProgram(programSyntax, options, parser.LexingErrorLookup, parser.ParsingErrorLookup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Destination.FileSystem.UnitTests</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Destination.FileSystem.UnitTests</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Destination.FileSystem</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Destination.FileSystem</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Formatter.Docusaurus.UnitTests</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Formatter.Docusaurus.UnitTests</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Formatter.Docusaurus</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Formatter.Docusaurus</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Formatter.Markdown.UnitTests</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Formatter.Markdown.UnitTests</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ public void BuildResources_Input_BuildsCorrectly()
{
var expected = @"## Resources
- [Microsoft.Web/sites/2022-12-18](https://learn.microsoft.com/en-us/azure/templates/microsoft.web/2022-12-18/sites)".ToPlatformLineEndings() + Environment.NewLine;
- [Microsoft.Web/sites/2022-12-18](https://learn.microsoft.com/en-us/azure/templates/microsoft.web/2022-12-18/sites)"
.ToPlatformLineEndings() + Environment.NewLine;
var resources = new List<ParsedResource>
{
new("Microsoft.Web/sites/2022-12-18", "Microsoft.Web", "sites")
{
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference(new List<string>
{
"microsoft.web",
"sites"
}.ToImmutableArray(), "2022-12-18"))
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference("microsoft.web/sites",
"2022-12-18"))
}
}.ToImmutableList();

Expand All @@ -47,24 +45,19 @@ public void BuildResources_MultipleOfSame_BuildsSingle()
{
var expected = @"## Resources
- [Microsoft.Web/sites/2022-12-18](https://learn.microsoft.com/en-us/azure/templates/microsoft.web/2022-12-18/sites)".ToPlatformLineEndings() + Environment.NewLine;
- [Microsoft.Web/sites/2022-12-18](https://learn.microsoft.com/en-us/azure/templates/microsoft.web/2022-12-18/sites)"
.ToPlatformLineEndings() + Environment.NewLine;
var resources = new List<ParsedResource>
{
new("Microsoft.Web/sites/2022-12-18", "Microsoft.Web", "sites")
{
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference(new List<string>
{
"microsoft.web",
"sites"
}.ToImmutableArray(), "2022-12-18"))
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference("microsoft.web/sites",
"2022-12-18"))
},
new("Microsoft.Web/sites/2022-12-18", "Microsoft.Web", "sites")
{
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference(new List<string>
{
"microsoft.web",
"sites"
}.ToImmutableArray(), "2022-12-18"))
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference("microsoft.web/sites",
"2022-12-18"))
}
}.ToImmutableList();

Expand All @@ -83,7 +76,8 @@ public async Task BuildResources_InputTemplate_BuildsSingle()
{
var expected = @"## Resources
- [Microsoft.Resources/resourceGroups@2021-01-01](https://learn.microsoft.com/en-us/azure/templates/microsoft.resources/2021-01-01/resourcegroups)".ToPlatformLineEndings() + Environment.NewLine;
- [Microsoft.Resources/resourceGroups@2021-01-01](https://learn.microsoft.com/en-us/azure/templates/microsoft.resources/2021-01-01/resourcegroups)"
.ToPlatformLineEndings() + Environment.NewLine;

const string template = @"resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-01-01' = {
name: resourceGroupName
Expand Down Expand Up @@ -160,11 +154,7 @@ public void BuildReferencedResources_Input_BuildsCorrectly()
Name = "siteOne",
Scope = "subscription()",
IsExisting = true,
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference(new List<string>
{
"microsoft.web",
"sites"
}.ToImmutableArray(), "2022-12-18"))
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference("microsoft.web/sites", "2022-12-18"))
}
}.ToImmutableList();

Expand Down Expand Up @@ -194,22 +184,14 @@ public void BuildReferencedResources_MultipleOfSame_BuildsAll()
Name = "siteOne",
Scope = "subscription()",
IsExisting = true,
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference(new List<string>
{
"microsoft.web",
"sites"
}.ToImmutableArray(), "2022-12-18"))
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference("microsoft.web/sites", "2022-12-18"))
},
new("Microsoft.Web/sites/2022-12-18", "Microsoft.Web", "sites")
{
Name = "siteTwo",
Scope = "subscription()",
IsExisting = true,
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference(new List<string>
{
"microsoft.web",
"sites"
}.ToImmutableArray(), "2022-12-18"))
DocUrl = ResourceLinkBuilder.GetResourceUrl(new ResourceTypeReference("microsoft.web/sites", "2022-12-18"))
}
}.ToImmutableList();

Expand All @@ -230,7 +212,8 @@ public async Task BuildReferencedResources_InputTemplate_BuildsSingle()
| Provider | Name | Scope |
| --- | --- | --- |
| Microsoft.Resources/resourceGroups@2021-01-01 | `resourceGroupName` | - |".ToPlatformLineEndings() + Environment.NewLine;
| Microsoft.Resources/resourceGroups@2021-01-01 | `resourceGroupName` | - |".ToPlatformLineEndings() +
Environment.NewLine;

const string template = @"resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-01-01' existing = {
name: resourceGroupName
Expand Down Expand Up @@ -303,4 +286,4 @@ public async Task BuildReferencedResources_NoExistingResources_DoesNotGenerate()
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Formatter.Markdown</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Formatter.Markdown</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="0.33.0" />
<PackageReference Include="Markdig" Version="0.34.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>LandingZones.Tools.BicepDocs.Source.FileSystem.UnitTests</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Source.FileSystem.UnitTests</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>LandingZones.Tools.BicepDocs.Source.FileSystem</AssemblyName>
<RootNamespace>LandingZones.Tools.BicepDocs.Source.FileSystem</RootNamespace>

<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down

0 comments on commit cdbe22a

Please sign in to comment.