-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for version in bicepconfig.json
- Loading branch information
1 parent
74551a5
commit 37da17f
Showing
18 changed files
with
170 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Bicep.Core.Diagnostics; | ||
using Bicep.Core.UnitTests.Assertions; | ||
using Bicep.Core.UnitTests.Utils; | ||
using Bicep.Core.Utils; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.Core.IntegrationTests; | ||
|
||
[TestClass] | ||
public class BicepConfigTests | ||
{ | ||
[TestMethod] | ||
public async Task Version_mismatch_should_block_compilation() | ||
{ | ||
var result = await CompilationHelper.RestoreAndCompile( | ||
("main.bicep", new(""" | ||
output foo string = '' | ||
""")), ("../bicepconfig.json", new(""" | ||
{ | ||
"bicep": { | ||
"version": "0.0.1" | ||
} | ||
} | ||
"""))); | ||
|
||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics([ | ||
("BCP409", DiagnosticLevel.Error, $"""Bicep version "{BicepVersion.Instance.Value}" was used for compilation, but version "0.0.1" is required in configuration file "/path/bicepconfig.json"."""), | ||
]); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Correct_version_should_permit_compilation() | ||
{ | ||
var result = await CompilationHelper.RestoreAndCompile( | ||
("main.bicep", new(""" | ||
output foo string = '' | ||
""")), ("../bicepconfig.json", new($$""" | ||
{ | ||
"bicep": { | ||
"version": "{{BicepVersion.Instance.Value}}" | ||
} | ||
} | ||
"""))); | ||
|
||
result.Should().NotHaveAnyDiagnostics(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using Bicep.Core.Utils; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.Core.UnitTests.Utils; | ||
|
||
[TestClass] | ||
public class BicepVersionTests | ||
{ | ||
[TestMethod] | ||
public void BicepVersion_should_return_assembly_info() | ||
{ | ||
var result = BicepVersion.Instance; | ||
result.Value.Should().MatchRegex(@"^[0-9]+\.[0-9]+\.[0-9]+"); | ||
if (result.CommitHash is {}) | ||
{ | ||
result.CommitHash.Should().MatchRegex(@"^[0-9a-f]{7,40}$"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.Json; | ||
using Bicep.Core.Extensions; | ||
|
||
namespace Bicep.Core.Configuration; | ||
|
||
public record BicepConfiguration( | ||
string? Version); | ||
|
||
public class BicepConfigurationSection : ConfigurationSection<BicepConfiguration> | ||
{ | ||
public BicepConfigurationSection(BicepConfiguration data) | ||
: base(data) | ||
{ | ||
} | ||
|
||
public static BicepConfigurationSection Bind(JsonElement element) | ||
=> new(element.ToNonNullObject<BicepConfiguration>()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
namespace Bicep.Core.Utils; | ||
|
||
public record BicepVersion( | ||
string Value, | ||
string? CommitHash) | ||
{ | ||
public static readonly BicepVersion Instance = GetVersion(); | ||
|
||
private static BicepVersion GetVersion() | ||
{ | ||
var split = ThisAssembly.AssemblyInformationalVersion.Split('+'); | ||
|
||
return new( | ||
split[0], | ||
split.Length > 1 ? split[1] : null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters