Skip to content

Commit 2476133

Browse files
Add -WithSource to bicep publish (#23317)
* Add -WithSource to Publish-AzBicepModule * Revert unintended changes * Add back missing tests and fix merge error * Fix test * Remove quotes around version * Update src/Resources/Resources/ChangeLog.md --------- Co-authored-by: Stephen Weatherford <Stephen.Weatherford.com> Co-authored-by: Beisi Zhou <[email protected]>
1 parent 3db0703 commit 2476133

File tree

7 files changed

+76
-7
lines changed

7 files changed

+76
-7
lines changed

src/Resources/ResourceManager/Implementation/Bicep/PublishAzureBicepModuleCmdlet.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class PublishAzureBicepModuleCmdlet : AzureRMCmdlet
3434
[Parameter(Mandatory = false, HelpMessage = "Documentation uri of the Bicep module.")]
3535
public string DocumentationUri { get; set; }
3636

37+
[Parameter(Mandatory = false, HelpMessage="[Experimental] Publish source code with the module.")]
38+
public SwitchParameter WithSource { get; set; }
39+
3740
[Parameter(Mandatory = false, HelpMessage="Overwrite existing published module.")]
3841
public SwitchParameter Force { get; set; }
3942

@@ -42,7 +45,7 @@ public class PublishAzureBicepModuleCmdlet : AzureRMCmdlet
4245

4346
public override void ExecuteCmdlet()
4447
{
45-
BicepUtility.Create().PublishFile(this.TryResolvePath(this.FilePath), this.Target, this.DocumentationUri, this.Force.IsPresent, this.WriteVerbose, this.WriteWarning);
48+
BicepUtility.Create().PublishFile(this.TryResolvePath(this.FilePath), this.Target, this.DocumentationUri, this.WithSource.IsPresent, this.Force.IsPresent, this.WriteVerbose, this.WriteWarning);
4649

4750
if (this.PassThru.IsPresent)
4851
{

src/Resources/ResourceManager/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/ResourceManager/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ You can help us improve the accuracy of the result by opening an issue here: htt
510510
<value>Invalid Bicep file path.</value>
511511
</data>
512512
<data name="BicepVersionRequirement" xml:space="preserve">
513-
<value>Please use bicep '{0}' or higher verison.</value>
513+
<value>Please use bicep {0} or higher.</value>
514514
</data>
515515
<data name="BuildBicepFileToJsonFailed" xml:space="preserve">
516516
<value>Build bicep file '{0}' to json failed.</value>

src/Resources/ResourceManager/Utilities/BicepUtility.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public static BicepUtility Create()
5555

5656
private const string MinimalVersionRequirementForBicepPublishWithOptionalForceParameter = "0.17.1";
5757

58+
private const string MinimalVersionRequirementForBicepPublishWithOptionalWithSourceParameter = "0.23.1";
59+
5860
private const string MinimalVersionRequirementForBicepparamFileBuild = "0.16.1";
5961

6062
private const string MinimalVersionRequirementForBicepparamFileBuildWithInlineOverrides = "0.22.6";
@@ -136,7 +138,7 @@ public BicepBuildParamsStdout BuildParams(string bicepParamFilePath, IReadOnlyDi
136138
return JsonConvert.DeserializeObject<BicepBuildParamsStdout>(stdout);
137139
}
138140

139-
public void PublishFile(string bicepFilePath, string target, string documentationUri = null, bool force = false, OutputCallback writeVerbose = null, OutputCallback writeWarning = null)
141+
public void PublishFile(string bicepFilePath, string target, string documentationUri = null, bool withSource = false, bool force = false, OutputCallback writeVerbose = null, OutputCallback writeWarning = null)
140142
{
141143
if (!dataStore.FileExists(bicepFilePath))
142144
{
@@ -150,6 +152,12 @@ public void PublishFile(string bicepFilePath, string target, string documentatio
150152
bicepPublishCommand += $" --documentationUri {GetQuotedFilePath(documentationUri)}";
151153
}
152154

155+
if (withSource)
156+
{
157+
CheckMinimalVersionRequirement(MinimalVersionRequirementForBicepPublishWithOptionalWithSourceParameter);
158+
bicepPublishCommand += $" --with-source";
159+
}
160+
153161
if (force)
154162
{
155163
CheckMinimalVersionRequirement(MinimalVersionRequirementForBicepPublishWithOptionalForceParameter);

src/Resources/Resources.Test/UnitTests/Utilities/BicepUtilityTests.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void BuildParams_fails_for_old_bicep_version()
106106
var bicepUtility = new BicepUtility(invokerMock.Object, dataStoreMock.Object);
107107

108108
FluentActions.Invoking(() => bicepUtility.BuildParams("foo.bicepparam", new Dictionary<string, object>()))
109-
.Should().Throw<AzPSApplicationException>().WithMessage("Please use bicep '0.16.1' or higher verison.");
109+
.Should().Throw<AzPSApplicationException>().WithMessage("Please use bicep 0.16.1 or higher.");
110110
}
111111

112112
[Fact]
@@ -141,5 +141,47 @@ public void BuildParams_fails_for_missing_param_file()
141141
FluentActions.Invoking(() => bicepUtility.BuildParams("foo.bicepparam", new Dictionary<string, object>()))
142142
.Should().Throw<AzPSArgumentException>().WithMessage("Invalid Bicepparam file path.");
143143
}
144+
145+
[Fact]
146+
[Trait(Category.AcceptanceType, Category.CheckIn)]
147+
public void WithSource_adds_with_source_to_CLI()
148+
{
149+
var invokerMock = new Mock<IProcessInvoker>(MockBehavior.Strict);
150+
invokerMock.Setup(x => x.Invoke(It.Is<ProcessInput>(p => p.Arguments == "-v")))
151+
.Returns(new ProcessOutput { ExitCode = 0, Stderr = "", Stdout = "Bicep CLI version 0.23.1 (b02de2da48)" });
152+
invokerMock.Setup(x => x.Invoke(It.Is<ProcessInput>(p => p.Arguments == "publish \"foo.bicep\" --target \"br:example.azurecr.io/hello/world:v1\" --with-source")))
153+
.Returns(new ProcessOutput { ExitCode = 0, Stderr = "", Stdout = "" });
154+
155+
invokerMock.Setup(x => x.CheckExecutableExists("bicep"))
156+
.Returns(true);
157+
158+
var dataStoreMock = new Mock<IDataStore>();
159+
dataStoreMock.Setup(x => x.FileExists("foo.bicep"))
160+
.Returns(true);
161+
162+
var bicepUtility = new BicepUtility(invokerMock.Object, dataStoreMock.Object);
163+
164+
bicepUtility.PublishFile("foo.bicep", "br:example.azurecr.io/hello/world:v1", null, withSource: true);
165+
}
166+
167+
[Fact]
168+
[Trait(Category.AcceptanceType, Category.CheckIn)]
169+
public void WithSource_fails_for_old_bicep_version()
170+
{
171+
var invokerMock = new Mock<IProcessInvoker>(MockBehavior.Strict);
172+
invokerMock.Setup(x => x.Invoke(It.Is<ProcessInput>(p => p.Arguments == "-v")))
173+
.Returns(new ProcessOutput { ExitCode = 0, Stderr = "", Stdout = "Bicep CLI version 0.15.1 (d62b94db31)" });
174+
invokerMock.Setup(x => x.CheckExecutableExists("bicep"))
175+
.Returns(true);
176+
177+
var dataStoreMock = new Mock<IDataStore>();
178+
dataStoreMock.Setup(x => x.FileExists("foo.bicep"))
179+
.Returns(true);
180+
181+
var bicepUtility = new BicepUtility(invokerMock.Object, dataStoreMock.Object);
182+
183+
FluentActions.Invoking(() => bicepUtility.PublishFile("foo.bicep", "br:example.azurecr.io/hello/world:v1", null, withSource: true))
184+
.Should().Throw<AzPSApplicationException>().WithMessage("Please use bicep 0.23.1 or higher.");
185+
}
144186
}
145187
}

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added `-WithSource` parameter to `Publish-AzBicepModule` for publishing source with a module (currently experimental)
2223
* Supported nullable Bicep parameters in Deployment cmdlets
2324

2425
## Version 6.12.1

src/Resources/Resources/help/Publish-AzBicepModule.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Publishes a Bicep file to a registry.
1313
## SYNTAX
1414

1515
```
16-
Publish-AzBicepModule -FilePath <String> -Target <String> [-DocumentationUri <String>] [-Force] [-PassThru]
17-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
16+
Publish-AzBicepModule -FilePath <String> -Target <String> [-DocumentationUri <String>] [-WithSource] [-Force]
17+
[-PassThru] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -128,6 +128,21 @@ Accept pipeline input: True (ByPropertyName)
128128
Accept wildcard characters: False
129129
```
130130
131+
### -WithSource
132+
[Experimental] Publish source code with the module.
133+
134+
```yaml
135+
Type: System.Management.Automation.SwitchParameter
136+
Parameter Sets: (All)
137+
Aliases:
138+
139+
Required: False
140+
Position: Named
141+
Default value: None
142+
Accept pipeline input: False
143+
Accept wildcard characters: False
144+
```
145+
131146
### -Confirm
132147
Prompts you for confirmation before running the cmdlet.
133148

0 commit comments

Comments
 (0)