Skip to content

Commit

Permalink
Merge pull request #262 from samsmithnz/feature/armtemplates3
Browse files Browse the repository at this point in the history
Added AzureResourceManagerTemplateDeployment@3 task support
  • Loading branch information
samsmithnz authored Feb 21, 2021
2 parents a087355 + 1dd37c7 commit dc4ff40
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public GitHubActions.Step ProcessStep(AzurePipelines.Step step)
gitHubStep = CreateAzurePowershellStep(step);
break;
case "AZURERESOURCEGROUPDEPLOYMENT@2":
case "AZURERESOURCEMANAGERTEMPLATEDEPLOYMENT@3":
gitHubStep = CreateAzureManageResourcesStep(step);
break;
case "AZUREFUNCTIONAPP@1":
Expand Down Expand Up @@ -1005,15 +1006,39 @@ private GitHubActions.Step CreateAzureManageResourcesStep(AzurePipelines.Step st
// csmParametersFile: '$(build.artifactstagingdirectory)/drop/ARMTemplates/azuredeploy.parameters.json'
// overrideParameters: '-environment $(AppSettings.Environment) -locationShort $(ArmTemplateResourceGroupLocation)'


//or:
//- task: AzureResourceManagerTemplateDeployment@3
// inputs:
// deploymentScope: 'Resource Group'
// azureResourceManagerConnection: 'copy-connection'
// subscriptionId: '00000000-0000-0000-0000-000000000000'
// action: 'Create Or Update Resource Group'
// resourceGroupName: 'demogroup'
// location: 'West US'
// templateLocation: 'URL of the file'
// csmFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.json$(AzureFileCopy.StorageContainerSasToken)'
// csmParametersFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.parameters.json$(AzureFileCopy.StorageContainerSasToken)'
// deploymentMode: 'Incremental'
// deploymentName: 'deploy1'

// https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-cli
//- name: Swap web service staging slot to production
// uses: Azure/[email protected]
// with:
// inlineScript: az deployment group create --resource-group <resource-group-name> --template-file <path-to-template>

string resourceGroup = GetStepInput(step, "resourcegroupname");
string armTemplateFile = GetStepInput(step, "csmfile");
string armTemplateParametersFile = GetStepInput(step, "csmparametersfile");
string resourceGroup = GetStepInput(step, "resourceGroupName");
string armTemplateFile = GetStepInput(step, "csmFile");
string armTemplateParametersFile = GetStepInput(step, "csmParametersFile");
if (string.IsNullOrEmpty(armTemplateFile) == true)
{
armTemplateFile = GetStepInput(step, "csmFileLink");
}
if (string.IsNullOrEmpty(armTemplateFile) == true)
{
armTemplateParametersFile = GetStepInput(step, "csmParametersFileLink");
}
string overrideParameters = GetStepInput(step, "overrideParameters");

string script = "az deployment group create --resource-group " + resourceGroup +
Expand Down Expand Up @@ -2551,23 +2576,6 @@ public GitHubActions.Step[] AddSupportingSteps(AzurePipelines.Step[] steps, bool
}
break;

//If we have an Azure step, we will need to add a Azure login step
case "AZURECLI@2":
case "AZUREPOWERSHELL@4":
case "AZUREAPPSERVICEMANAGE@0":
case "AZURERESOURCEGROUPDEPLOYMENT@2":
case "AZUREFUNCTIONAPP@1":
case "AZUREFUNCTIONAPPCONTAINER@1":
case "AZURERMWEBAPPDEPLOYMENT@3":
case "AZURERMWEBAPPDEPLOYMENT@4":
case "AZUREWEBAPPCONTAINER@1":
case "AZUREWEBAPP@1":
if (addAzureLoginStep == false)
{
addAzureLoginStep = true;
stepAdjustment++;
}
break;

case "VSBUILD@1":
if (addMSSetupStep == false)
Expand All @@ -2576,6 +2584,30 @@ public GitHubActions.Step[] AddSupportingSteps(AzurePipelines.Step[] steps, bool
stepAdjustment++;
}
break;

default:
//If we have an Azure step, we will need to add a Azure login step
if (step.task.ToUpper().StartsWith("AZURE") == true)
{
//case "AZURECLI@2":
//case "AZUREPOWERSHELL@4":
//case "AZUREAPPSERVICEMANAGE@0":
//case "AZURERESOURCEGROUPDEPLOYMENT@2":
//case "AZURERESOURCEMANAGERTEMPLATEDEPLOYMENT@3":
//case "AZUREFUNCTIONAPP@1":
//case "AZUREFUNCTIONAPPCONTAINER@1":
//case "AZURERMWEBAPPDEPLOYMENT@3":
//case "AZURERMWEBAPPDEPLOYMENT@4":
//case "AZUREWEBAPPCONTAINER@1":
//case "AZUREWEBAPP@1":
if (addAzureLoginStep == false)
{
addAzureLoginStep = true;
stepAdjustment++;
}
break;
}
break;
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/AzurePipelinesToGitHubActionsConverter.Tests/StepsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,41 @@ public void ArmTemplateDeploymentStepTest()
Assert.AreEqual(expected, gitHubOutput.actionsYaml);
}

[TestMethod]
public void ArmTemplateV3DeploymentStepTest()
{
//Arrange
Conversion conversion = new Conversion();
string yaml = @"
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'copy-connection'
subscriptionId: '00000000-0000-0000-0000-000000000000'
action: 'Create Or Update Resource Group'
resourceGroupName: $(ResourceGroupName)
location: 'West US'
templateLocation: 'URL of the file'
csmFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.json$(AzureFileCopy.StorageContainerSasToken)'
csmParametersFileLink: '$(AzureFileCopy.StorageContainerUri)templates/mainTemplate.parameters.json$(AzureFileCopy.StorageContainerSasToken)'
deploymentMode: 'Incremental'
deploymentName: 'deploy1'
overrideParameters: '-environment $(AppSettings.Environment) -locationShort $(ArmTemplateResourceGroupLocation)'
";

//Act
ConversionResponse gitHubOutput = conversion.ConvertAzurePipelineTaskToGitHubActionTask(yaml);

//Assert
string expected = @"
- uses: Azure/[email protected]
with:
inlineScript: az deployment group create --resource-group ${{ env.ResourceGroupName }} --template-file ${{ env.AzureFileCopy.StorageContainerUri }}templates/mainTemplate.json${{ env.AzureFileCopy.StorageContainerSasToken }} --parameters -environment ${{ env.AppSettings.Environment }} -locationShort ${{ env.ArmTemplateResourceGroupLocation }}
";
expected = UtilityTests.TrimNewLines(expected);
Assert.AreEqual(expected, gitHubOutput.actionsYaml);
}


// [TestMethod]
// public void MSBuildStepTest()
Expand Down

0 comments on commit dc4ff40

Please sign in to comment.